Merge pull request #151 from beatz174-bit/codex/fix-all-e2e-test-errors
Fix e2e add product flows
This commit is contained in:
+10
-7
@@ -11,6 +11,7 @@ import {
|
|||||||
secondaryProduct,
|
secondaryProduct,
|
||||||
waitForScreenHeading,
|
waitForScreenHeading,
|
||||||
openSelect,
|
openSelect,
|
||||||
|
openAddProductDialog,
|
||||||
ensureCategoryExists,
|
ensureCategoryExists,
|
||||||
expectProductQuantity,
|
expectProductQuantity,
|
||||||
addProductToPickList,
|
addProductToPickList,
|
||||||
@@ -68,6 +69,8 @@ test.describe('Active pick list', () => {
|
|||||||
await page.getByRole('link', { name: 'Manage Products' }).click();
|
await page.getByRole('link', { name: 'Manage Products' }).click();
|
||||||
await waitForScreenHeading(page, 'Manage Products');
|
await waitForScreenHeading(page, 'Manage Products');
|
||||||
|
|
||||||
|
await openAddProductDialog(page);
|
||||||
|
|
||||||
await page.getByLabel('Name').click();
|
await page.getByLabel('Name').click();
|
||||||
await page.getByLabel('Name').fill('Playwright Cola');
|
await page.getByLabel('Name').fill('Playwright Cola');
|
||||||
|
|
||||||
@@ -84,7 +87,7 @@ test.describe('Active pick list', () => {
|
|||||||
await expect(page.getByText('Playwright Cola')).toBeVisible();
|
await expect(page.getByText('Playwright Cola')).toBeVisible();
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Edit Playwright Cola' }).click();
|
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 expect(editNameField).toBeVisible();
|
||||||
await editNameField.fill('Playwright Cola Zero');
|
await editNameField.fill('Playwright Cola Zero');
|
||||||
|
|
||||||
@@ -105,6 +108,8 @@ test.describe('Active pick list', () => {
|
|||||||
await page.getByRole('link', { name: 'Manage Products' }).click();
|
await page.getByRole('link', { name: 'Manage Products' }).click();
|
||||||
await waitForScreenHeading(page, 'Manage Products');
|
await waitForScreenHeading(page, 'Manage Products');
|
||||||
|
|
||||||
|
await openAddProductDialog(page);
|
||||||
|
|
||||||
await page.getByLabel('Name').click();
|
await page.getByLabel('Name').click();
|
||||||
await page.getByLabel('Name').fill(listProductName);
|
await page.getByLabel('Name').fill(listProductName);
|
||||||
await openSelect(page, 'Add product category', areaName, 'select-add-product-category');
|
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();
|
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 expect(editListNameField).toBeVisible();
|
||||||
await editListNameField.fill(updatedListProductName);
|
await editListNameField.fill(updatedListProductName);
|
||||||
|
|
||||||
@@ -139,9 +144,11 @@ test.describe('Active pick list', () => {
|
|||||||
await expect(page.getByText(updatedListProductName)).toHaveCount(0);
|
await expect(page.getByText(updatedListProductName)).toHaveCount(0);
|
||||||
|
|
||||||
const addProduct = async (name: string) => {
|
const addProduct = async (name: string) => {
|
||||||
|
await openAddProductDialog(page);
|
||||||
await page.getByLabel('Name').fill(name);
|
await page.getByLabel('Name').fill(name);
|
||||||
await openSelect(page, 'Add product category', areaName, 'select-add-product-category');
|
await openSelect(page, 'Add product category', areaName, 'select-add-product-category');
|
||||||
await page.getByRole('button', { name: 'Save Product' }).first().click();
|
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.getByText('Product added.')).toBeVisible();
|
||||||
await expect(page.getByRole('button', { name: `Edit ${name}` })).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 expectProductQuantity(page, additionalProduct, 2);
|
||||||
|
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
await waitForScreenHeading(page, `${areaName} List`);
|
||||||
await expectProductQuantity(page, additionalProduct, 2);
|
await expectProductQuantity(page, additionalProduct, 2);
|
||||||
|
|
||||||
const decrementButton = page.getByRole('button', { name: 'Decrease quantity' });
|
const decrementButton = page.getByRole('button', { name: 'Decrease quantity' });
|
||||||
await decrementButton.click();
|
await decrementButton.click();
|
||||||
await decrementButton.click();
|
|
||||||
await decrementButton.click();
|
|
||||||
|
|
||||||
await expectProductQuantity(page, additionalProduct, 1);
|
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 }) => {
|
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 page.getByRole('button', { name: 'Save and Return' }).click();
|
||||||
await waitForScreenHeading(page, 'Pick Lists');
|
await waitForScreenHeading(page, 'Pick Lists');
|
||||||
|
|
||||||
await page.reload();
|
|
||||||
await page.getByRole('link', { name: areaName }).first().click();
|
await page.getByRole('link', { name: areaName }).first().click();
|
||||||
await waitForScreenHeading(page, `${areaName} List`);
|
await waitForScreenHeading(page, `${areaName} List`);
|
||||||
await expectProductQuantity(page, additionalProduct, 3);
|
await expectProductQuantity(page, additionalProduct, 3);
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ export const waitForScreenHeading = async (page: Page, heading: string, timeout
|
|||||||
await expect(page.getByRole('heading', { name: heading })).toBeVisible({ 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) => {
|
export const openSelect = async (page: Page, label: string, optionName: string, testId?: string) => {
|
||||||
const tryOpen = async (lbl: string) => {
|
const tryOpen = async (lbl: string) => {
|
||||||
// 1) Try testId wrapper if provided
|
// 1) Try testId wrapper if provided
|
||||||
@@ -247,6 +256,8 @@ export const ensureProductsExist = async (page: Page, productNames: string[], ca
|
|||||||
for (const productName of productNames) {
|
for (const productName of productNames) {
|
||||||
if ((await page.getByRole('button', { name: `Edit ${productName}` }).count()) > 0) continue;
|
if ((await page.getByRole('button', { name: `Edit ${productName}` }).count()) > 0) continue;
|
||||||
|
|
||||||
|
await openAddProductDialog(page);
|
||||||
|
|
||||||
const nameField = page.getByLabel('Name');
|
const nameField = page.getByLabel('Name');
|
||||||
await nameField.click();
|
await nameField.click();
|
||||||
await nameField.fill(productName);
|
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.locator('[aria-label="Save product"]').first().click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await page.getByLabel('Add product dialog').first().waitFor({ state: 'hidden', timeout: 5000 });
|
||||||
|
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
page.getByText('Product added.').waitFor({ state: 'visible', timeout: 5000 }).catch(() => {}),
|
page.getByText('Product added.').waitFor({ state: 'visible', timeout: 5000 }).catch(() => {}),
|
||||||
page.getByRole('button', { name: `Edit ${productName}` }).waitFor({ state: 'visible', timeout: 5000 }).catch(() => {}),
|
page.getByRole('button', { name: `Edit ${productName}` }).waitFor({ state: 'visible', timeout: 5000 }).catch(() => {}),
|
||||||
|
|||||||
Reference in New Issue
Block a user