From d4b1de452c7c0d06700c0e2ee383f0f9ca72ee04 Mon Sep 17 00:00:00 2001 From: Nico Date: Mon, 25 May 2026 11:48:12 -0700 Subject: [PATCH] test: tighten Playwright selectors --- frontend/src/components/modals/ConfirmSlideModal.jsx | 2 +- frontend/tests/available-items-catalog.spec.ts | 4 ++-- frontend/tests/classification-details.spec.ts | 8 ++++++-- frontend/tests/household-onboarding.spec.ts | 12 ++++++------ frontend/tests/invite-link-management.spec.ts | 2 +- frontend/tests/toast-notifications.spec.ts | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/modals/ConfirmSlideModal.jsx b/frontend/src/components/modals/ConfirmSlideModal.jsx index ac95100..f924701 100644 --- a/frontend/src/components/modals/ConfirmSlideModal.jsx +++ b/frontend/src/components/modals/ConfirmSlideModal.jsx @@ -170,7 +170,7 @@ export default function ConfirmSlideModal({ onPointerCancel={handlePointerCancel} aria-label="Slide to confirm" > - > + > diff --git a/frontend/tests/available-items-catalog.spec.ts b/frontend/tests/available-items-catalog.spec.ts index 6d26dad..c7bc0ff 100644 --- a/frontend/tests/available-items-catalog.spec.ts +++ b/frontend/tests/available-items-catalog.spec.ts @@ -150,8 +150,8 @@ test("manage stores opens a modal to edit and delete household store items", asy const managerModal = page.locator(".store-items-modal"); await expect(managerModal).toBeVisible(); - await expect(managerModal.getByText("milk")).toBeVisible(); - await expect(managerModal.getByText("apples")).toBeVisible(); + await expect(managerModal.getByText("milk", { exact: true })).toBeVisible(); + await expect(managerModal.getByText("apples", { exact: true })).toBeVisible(); await managerModal.locator(".store-items-table-row").filter({ hasText: "apples" }).getByRole("button", { name: "Edit Settings" }).click(); const editorModal = page.locator(".available-item-editor-modal"); diff --git a/frontend/tests/classification-details.spec.ts b/frontend/tests/classification-details.spec.ts index 8f59c3c..3f49a7c 100644 --- a/frontend/tests/classification-details.spec.ts +++ b/frontend/tests/classification-details.spec.ts @@ -271,7 +271,9 @@ test("add-details modal validates with toasts and persists classification detail const yogurtRow = page.locator(".glist-li").filter({ hasText: "yogurt" }); await expect(yogurtRow).toBeVisible(); - await expect(page.locator(".action-toast.action-toast-success")).toContainText("Added item"); + await expect( + page.locator(".action-toast.action-toast-success").filter({ hasText: "Added item" }) + ).toContainText("Added item"); await openEditModal(yogurtRow, page); @@ -302,7 +304,9 @@ test("edit modal supports zone-only updates and shows API error toasts", async ( await editModal.locator(".edit-modal-select").nth(1).selectOption("Checkout Area"); await editModal.getByRole("button", { name: "Save Changes" }).click(); - await expect(page.locator(".action-toast.action-toast-success")).toContainText("Updated item"); + await expect( + page.locator(".action-toast.action-toast-success").filter({ hasText: "Updated item" }) + ).toContainText("Updated item"); await expect(editModal).toBeHidden(); await openEditModal(yogurtRow, page); diff --git a/frontend/tests/household-onboarding.spec.ts b/frontend/tests/household-onboarding.spec.ts index 6acbefe..8ebeaab 100644 --- a/frontend/tests/household-onboarding.spec.ts +++ b/frontend/tests/household-onboarding.spec.ts @@ -39,14 +39,14 @@ test("new users with no households see create and join actions instead of a load await expect(page.getByRole("button", { name: "Create or Join Household" })).toBeVisible(); await expect(page.getByRole("heading", { name: "No household yet" })).toBeVisible(); - await expect(page.getByRole("button", { name: "Create Household" })).toBeVisible(); - await expect(page.getByRole("button", { name: "Join Household" })).toBeVisible(); + await expect(page.getByRole("button", { name: "Create Household", exact: true })).toBeVisible(); + await expect(page.getByRole("button", { name: "Join Household", exact: true })).toBeVisible(); - await page.getByRole("button", { name: "Join Household" }).click(); + await page.getByRole("button", { name: "Join Household", exact: true }).click(); await expect(page.getByLabel("Invite Code or Link")).toBeVisible(); await page.getByRole("button", { name: "Close household dialog" }).click(); - await page.getByRole("button", { name: "Create Household" }).click(); + await page.getByRole("button", { name: "Create Household", exact: true }).click(); await expect(page.getByLabel("Household Name")).toBeVisible(); await page.getByRole("button", { name: "Close household dialog" }).click(); @@ -54,6 +54,6 @@ test("new users with no households see create and join actions instead of a load await expect(page.getByRole("heading", { name: "Manage" })).toBeVisible(); await expect(page.getByRole("heading", { name: "No household yet" })).toBeVisible(); - await expect(page.getByRole("button", { name: "Create Household" })).toBeVisible(); - await expect(page.getByRole("button", { name: "Join Household" })).toBeVisible(); + await expect(page.getByRole("button", { name: "Create Household", exact: true })).toBeVisible(); + await expect(page.getByRole("button", { name: "Join Household", exact: true })).toBeVisible(); }); diff --git a/frontend/tests/invite-link-management.spec.ts b/frontend/tests/invite-link-management.spec.ts index aea47e8..cc93b8d 100644 --- a/frontend/tests/invite-link-management.spec.ts +++ b/frontend/tests/invite-link-management.spec.ts @@ -71,7 +71,7 @@ test("join household modal accepts invite links but rejects legacy invite codes" }); await page.goto("/manage"); - await page.getByRole("button", { name: "Join Household" }).click(); + await page.getByRole("button", { name: "Join Household", exact: true }).click(); await page.getByLabel("Invite Link").fill("HABC123"); await page.getByRole("button", { name: "Open Invite" }).click(); diff --git a/frontend/tests/toast-notifications.spec.ts b/frontend/tests/toast-notifications.spec.ts index a24763a..ba89553 100644 --- a/frontend/tests/toast-notifications.spec.ts +++ b/frontend/tests/toast-notifications.spec.ts @@ -38,7 +38,7 @@ test("login failure shows inline error and error toast", async ({ page }) => { await page.getByPlaceholder("Password").fill("bad-password"); await page.getByRole("button", { name: "Login" }).click(); - await expect(page.getByText("Invalid credentials")).toBeVisible(); + await expect(page.getByText("Invalid credentials", { exact: true })).toBeVisible(); await expect(page.locator(".action-toast.action-toast-error")).toContainText("Login failed"); await expect(page.locator(".action-toast.action-toast-error")).toContainText("Invalid credentials"); });