test: update buy modal e2e for location lists

This commit is contained in:
Nico 2026-06-04 12:20:04 -07:00
parent d5b38b6711
commit 1874851b37
2 changed files with 45 additions and 12 deletions

View File

@ -64,7 +64,19 @@ async function setupBuyModalRoutes(
});
});
await page.route("**/households/1/stores/10/list/recent", async (route) => {
await page.route("**/households/1/locations/10/zones", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
zones: [
{ id: 501, name: "Produce", sort_order: 10 },
],
}),
});
});
await page.route("**/households/1/locations/10/list/recent", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
@ -72,7 +84,7 @@ async function setupBuyModalRoutes(
});
});
await page.route("**/households/1/stores/10/list/suggestions**", async (route) => {
await page.route("**/households/1/locations/10/list/suggestions**", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
@ -80,7 +92,7 @@ async function setupBuyModalRoutes(
});
});
await page.route("**/households/1/stores/10/list/classification**", async (route) => {
await page.route("**/households/1/locations/10/list/classification**", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
@ -88,7 +100,7 @@ async function setupBuyModalRoutes(
});
});
await page.route("**/households/1/stores/10/list/item**", async (route) => {
await page.route("**/households/1/locations/10/list/item**", async (route) => {
const request = route.request();
if (request.method() === "PATCH") {
@ -156,7 +168,7 @@ async function setupBuyModalRoutes(
});
});
await page.route("**/households/1/stores/10/list", async (route) => {
await page.route("**/households/1/locations/10/list", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
@ -183,12 +195,11 @@ test("buying an item advances to the next one in the current sort order", async
]);
await page.goto("/");
await page.locator(".glist-sort").selectOption("qty-high");
await openBuyModal(page, "bread");
await page.getByRole("button", { name: "Mark as Bought" }).click();
await expect(page.locator(".confirm-buy-item-name")).toHaveText("apples");
await expect(page.locator(".confirm-buy-item-name")).toHaveText("milk");
});
test("buying the last item in the current order wraps to the first remaining item", async ({ page }) => {
@ -201,7 +212,6 @@ test("buying the last item in the current order wraps to the first remaining ite
]);
await page.goto("/");
await page.locator(".glist-sort").selectOption("az");
await openBuyModal(page, "milk");
await page.getByRole("button", { name: "Mark as Bought" }).click();
@ -219,7 +229,6 @@ test("partial buy keeps the item on the list and advances past it", async ({ pag
]);
await page.goto("/");
await page.locator(".glist-sort").selectOption("qty-low");
await openBuyModal(page, "bravo");
await page.locator(".confirm-buy-counter-btn").nth(0).click();

View File

@ -16,8 +16,12 @@ type HouseholdSeed = {
type StoreSeed = {
id?: number;
household_store_id?: number;
household_id?: number;
name?: string;
location?: string;
location_name?: string;
display_name?: string;
is_default?: boolean;
};
@ -57,9 +61,21 @@ export async function mockHouseholdAndStoreShell(
invite_code: "ABCD1234",
...options.household,
};
const stores = options.stores || [
{ id: 10, name: "Costco", location: "Warehouse", is_default: true },
];
const stores = (options.stores || [
{ id: 10, household_store_id: 100, name: "Costco", location_name: "Warehouse", is_default: true },
]).map((store, index) => {
const locationName = store.location_name || store.location || "Default Location";
return {
household_id: household.id,
household_store_id: store.household_store_id ?? store.id ?? index + 1,
id: store.id ?? index + 10,
name: store.name || "Costco",
location_name: locationName,
display_name: store.display_name || `${store.name || "Costco"} - ${locationName}`,
is_default: store.is_default ?? index === 0,
...store,
};
});
await page.route("**/households", async (route) => {
await route.fulfill({
@ -76,6 +92,14 @@ export async function mockHouseholdAndStoreShell(
body: JSON.stringify(stores),
});
});
await page.route(`**/households/${household.id}/stores`, async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(stores),
});
});
}
export async function confirmSlide(page: Page) {