From e196f571349e12b89939574d042a1b9b273d4a34 Mon Sep 17 00:00:00 2001 From: beatz174-bit Date: Mon, 1 Dec 2025 17:07:47 +1000 Subject: [PATCH] Fix e2e add product flows --- e2e/picklist.spec.ts | 17 ++++++++++------- e2e/test-helpers.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/e2e/picklist.spec.ts b/e2e/picklist.spec.ts index d71401d..610fb69 100644 --- a/e2e/picklist.spec.ts +++ b/e2e/picklist.spec.ts @@ -11,6 +11,7 @@ import { secondaryProduct, waitForScreenHeading, openSelect, + openAddProductDialog, ensureCategoryExists, expectProductQuantity, addProductToPickList, @@ -68,6 +69,8 @@ test.describe('Active pick list', () => { await page.getByRole('link', { name: 'Manage Products' }).click(); await waitForScreenHeading(page, 'Manage Products'); + await openAddProductDialog(page); + await page.getByLabel('Name').click(); await page.getByLabel('Name').fill('Playwright Cola'); @@ -84,7 +87,7 @@ test.describe('Active pick list', () => { await expect(page.getByText('Playwright Cola')).toBeVisible(); await page.getByRole('button', { name: 'Edit Playwright Cola' }).click(); - const editNameField = page.getByLabel('Name').nth(1); + const editNameField = page.getByLabel('Name').first(); await expect(editNameField).toBeVisible(); await editNameField.fill('Playwright Cola Zero'); @@ -105,6 +108,8 @@ test.describe('Active pick list', () => { await page.getByRole('link', { name: 'Manage Products' }).click(); await waitForScreenHeading(page, 'Manage Products'); + await openAddProductDialog(page); + await page.getByLabel('Name').click(); await page.getByLabel('Name').fill(listProductName); await openSelect(page, 'Add product category', areaName, 'select-add-product-category'); @@ -121,7 +126,7 @@ test.describe('Active pick list', () => { await page.getByRole('button', { name: `Edit ${listProductName}` }).click(); - const editListNameField = page.getByLabel('Name').last(); + const editListNameField = page.getByLabel('Name').first(); await expect(editListNameField).toBeVisible(); await editListNameField.fill(updatedListProductName); @@ -139,9 +144,11 @@ test.describe('Active pick list', () => { await expect(page.getByText(updatedListProductName)).toHaveCount(0); const addProduct = async (name: string) => { + await openAddProductDialog(page); await page.getByLabel('Name').fill(name); await openSelect(page, 'Add product category', areaName, 'select-add-product-category'); await page.getByRole('button', { name: 'Save Product' }).first().click(); + await page.getByLabel('Add product dialog').first().waitFor({ state: 'hidden', timeout: 5000 }); await expect(page.getByText('Product added.')).toBeVisible(); await expect(page.getByRole('button', { name: `Edit ${name}` })).toBeVisible(); }; @@ -197,17 +204,14 @@ test.describe('Active pick list', () => { await expectProductQuantity(page, additionalProduct, 2); await page.reload(); + await waitForScreenHeading(page, `${areaName} List`); await expectProductQuantity(page, additionalProduct, 2); const decrementButton = page.getByRole('button', { name: 'Decrease quantity' }); await decrementButton.click(); - await decrementButton.click(); - await decrementButton.click(); await expectProductQuantity(page, additionalProduct, 1); - await page.reload(); - await expectProductQuantity(page, additionalProduct, 1); }); test('closes mobile controls with the close button and backdrop', async ({ page }) => { @@ -312,7 +316,6 @@ test.describe('Active pick list', () => { await page.getByRole('button', { name: 'Save and Return' }).click(); await waitForScreenHeading(page, 'Pick Lists'); - await page.reload(); await page.getByRole('link', { name: areaName }).first().click(); await waitForScreenHeading(page, `${areaName} List`); await expectProductQuantity(page, additionalProduct, 3); diff --git a/e2e/test-helpers.ts b/e2e/test-helpers.ts index e6ba769..4d2b922 100644 --- a/e2e/test-helpers.ts +++ b/e2e/test-helpers.ts @@ -25,6 +25,15 @@ export const waitForScreenHeading = async (page: Page, heading: string, timeout await expect(page.getByRole('heading', { name: heading })).toBeVisible({ timeout }); }; +export const openAddProductDialog = async (page: Page) => { + const dialog = page.getByLabel('Add product dialog'); + const isDialogVisible = (await dialog.count()) > 0 && (await dialog.first().isVisible()); + if (!isDialogVisible) { + await page.getByRole('button', { name: 'Add product' }).click(); + } + await dialog.first().waitFor({ state: 'visible', timeout: 5000 }); +}; + export const openSelect = async (page: Page, label: string, optionName: string, testId?: string) => { const tryOpen = async (lbl: string) => { // 1) Try testId wrapper if provided @@ -247,6 +256,8 @@ export const ensureProductsExist = async (page: Page, productNames: string[], ca for (const productName of productNames) { if ((await page.getByRole('button', { name: `Edit ${productName}` }).count()) > 0) continue; + await openAddProductDialog(page); + const nameField = page.getByLabel('Name'); await nameField.click(); await nameField.fill(productName); @@ -264,6 +275,8 @@ export const ensureProductsExist = async (page: Page, productNames: string[], ca await page.locator('[aria-label="Save product"]').first().click(); } + await page.getByLabel('Add product dialog').first().waitFor({ state: 'hidden', timeout: 5000 }); + await Promise.race([ page.getByText('Product added.').waitFor({ state: 'visible', timeout: 5000 }).catch(() => {}), page.getByRole('button', { name: `Edit ${productName}` }).waitFor({ state: 'visible', timeout: 5000 }).catch(() => {}),