Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fast-cycles-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Removed unnecessary await from expect statements and split select link option into two methods to reduce flakiness.
37 changes: 27 additions & 10 deletions playwright/pages/dialogs/addNavigationMenuItemDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,37 @@ export class AddNavigationMenuItemDialog extends BasePage {
super(page);
}

async selectLinkOption(option: string, optionName: string) {
async selectLinkTypeOption(linkType: string) {
await this.menuLinkType.click();
await this.waitForDOMToFullyLoad();
await this.menuLinkOptions.filter({ hasText: "Categories" }).waitFor({ state: "visible" });
await this.menuLinkOptions.filter({ hasText: "Collections" }).waitFor({ state: "visible" });
await this.menuLinkOptions.filter({ hasText: "Pages" }).waitFor({ state: "visible" });
await expect(this.menuLinkOptions.filter({ hasText: option })).toBeEnabled();
await this.menuLinkOptions.filter({ hasText: option }).click({ force: true });
await this.waitForDOMToFullyLoad();

// Ensure the link type option is visible and select it
Copy link
Contributor

@andrzejewsky andrzejewsky Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLM models generate usually tons on comments, explaining what they do - it's useful when composing the final solution, but usually redundant when used in the destined codebase.

const linkTypeOption = this.menuLinkOptions.filter({ hasText: linkType });

await linkTypeOption.waitFor({ state: "visible" });
await expect(linkTypeOption).toBeEnabled();
await linkTypeOption.click({ force: true });

// Verify the correct link type is selected
const selectedLinkType = await this.menuLinkType.inputValue();

if (selectedLinkType !== linkType) {
throw new Error(`Expected link type "${linkType}" but found "${selectedLinkType}"`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an assert, not exception raising, this will break the test execution by unhandled error

}
}

async selectLinkTypeValue(optionName: string) {
await this.menuLinkValue.click();
await this.menuLinkOptions.filter({ hasText: optionName }).waitFor({ state: "visible" });
await expect(this.menuLinkOptions.filter({ hasText: optionName })).toBeEnabled();
await this.menuLinkOptions.filter({ hasText: optionName }).click({ force: true });
await this.waitForDOMToFullyLoad();

// Ensure the option is present and select it
const option = this.menuLinkOptions.filter({ hasText: optionName });

await option.waitFor({ state: "visible" });
await expect(option).toBeEnabled();
await option.click({ force: true });

// Verify the correct option is selected
await expect(this.menuLinkValue).toHaveValue(optionName);
}

Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/attributes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for (const attr of attributeClasses) {
await attributesPage.addValueDialog.typeAndSaveAttributeValue();
await attributesPage.clickSaveButton();
await attributesPage.expectSuccessBanner();
await expect(await attributesPage.attributesRows.count()).toEqual(1);
expect(await attributesPage.attributesRows.count()).toEqual(1);
await attributesPage.valueRequiredCheckbox.waitFor({
state: "visible",
timeout: 10000,
Expand Down
9 changes: 6 additions & 3 deletions playwright/tests/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ test("TC: SALEOR_194 Should create a new menu navigation with menu item @navigat
const menuItemName = faker.random.word();

await addNavigationMenuItemDialog.typeMenuItemName(menuItemName);
await addNavigationMenuItemDialog.selectLinkOption("Categories", "Polo Shirts");
await addNavigationMenuItemDialog.selectLinkTypeOption("Categories");
await addNavigationMenuItemDialog.selectLinkTypeValue("Polo Shirts");
await addNavigationMenuItemDialog.clickSaveButton();
await expect(navigationDetailsPage.addMenuItemDialog).not.toBeVisible();
await navigation.expectSuccessBanner();
Expand All @@ -59,7 +60,8 @@ test("TC: SALEOR_198 Should update existing menu @navigation @e2e", async () =>

await navigationDetailsPage.clickEditMenuItemButton(menuItemToBeUpdated.name);
await addNavigationMenuItemDialog.typeMenuItemName(newItemName);
await addNavigationMenuItemDialog.selectLinkOption("Categories", "Polo Shirts");
await addNavigationMenuItemDialog.selectLinkTypeOption("Categories");
await addNavigationMenuItemDialog.selectLinkTypeValue("Polo Shirts");
await addNavigationMenuItemDialog.clickSaveButton();
await expect(navigationDetailsPage.addMenuItemDialog).not.toBeVisible();
await navigationDetailsPage.clickDeleteMenuItemButton(menuItemToBeDeleted.name);
Expand All @@ -69,7 +71,8 @@ test("TC: SALEOR_198 Should update existing menu @navigation @e2e", async () =>
const menuItemName = faker.random.word();

await addNavigationMenuItemDialog.typeMenuItemName(menuItemName);
await addNavigationMenuItemDialog.selectLinkOption("Categories", "Polo Shirts");
await addNavigationMenuItemDialog.selectLinkTypeOption("Categories");
await addNavigationMenuItemDialog.selectLinkTypeValue("Polo Shirts");
await addNavigationMenuItemDialog.clickSaveButton();
await expect(navigationDetailsPage.menuItemList).toContainText(menuItemName);
await navigationDetailsPage.clickDeleteMenuItemButton(menuItemName);
Expand Down
6 changes: 2 additions & 4 deletions playwright/tests/taxes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ test("TC: SALEOR_117 Add new country and tax rates to it @taxes @e2e", async ()
await taxesPage.addCountriesDialog.checkAndSaveSingleCountry(
COUNTRIES.countryToBeAddedInTaxes.name,
);
expect(await taxesPage.countriesListRow.first()).toHaveText(
COUNTRIES.countryToBeAddedInTaxes.name,
);
expect(taxesPage.countriesListRow.first()).toHaveText(COUNTRIES.countryToBeAddedInTaxes.name);
await taxesPage.typeAllTaxRatesForCountry("23", "0", "16", "7", "21", "19");
await taxesPage.clickSaveButton();
await taxesPage.expectSuccessBanner();
Expand All @@ -57,7 +55,7 @@ test("TC: SALEOR_118 Add new class with metadata and set tax rate for single cou
await taxesPage.gotoChannelsTabUrl();
await taxesPage.clickTaxClassTab();
await taxesPage.clickCreateClassButton();
expect(await taxesPage.taxClassNameInput).toHaveValue("New tax class");
expect(taxesPage.taxClassNameInput).toHaveValue("New tax class");
await taxesPage.typeTaxClassName("Automation test tax class");
await taxesPage.typeSearchedTaxCountryName("United States of America");
await taxesPage.typeTaxRateInSearchedCountryRow("United States of America", "20");
Expand Down
22 changes: 9 additions & 13 deletions playwright/tests/vouchers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test("TC: SALEOR_40 Create voucher with auto-generated codes and fixed amount di

const generatedCodesRows = await vouchersPage.getNumberOfGridRowsWithText(codesPrefix);

await expect(
expect(
generatedCodesRows,
`Auto-generated number of codes: ${codesQuantity} should be visible on grid`,
).toEqual(codesQuantity);
Expand All @@ -38,7 +38,7 @@ test("TC: SALEOR_40 Create voucher with auto-generated codes and fixed amount di

const activeCodesRows = await vouchersPage.getNumberOfGridRowsWithText("Active");

await expect(
expect(
activeCodesRows,
`Given codes quantity: ${codesQuantity} should have status Active displayed on grid`,
).toEqual(codesQuantity);
Expand All @@ -56,9 +56,7 @@ test("TC: SALEOR_85 Create voucher with manual code and percentage discount @vou

const manualCodesRows = await vouchersPage.getNumberOfGridRowsWithText(code);

await expect(manualCodesRows, `Manually added code: ${code} should be visible on grid`).toEqual(
1,
);
expect(manualCodesRows, `Manually added code: ${code} should be visible on grid`).toEqual(1);
await vouchersPage.clickPercentDiscountTypeButton();
await vouchersPage.rightSideDetailsPage.selectOneChannelAsAvailableWhenMoreSelected(
"Channel-PLN",
Expand All @@ -70,7 +68,7 @@ test("TC: SALEOR_85 Create voucher with manual code and percentage discount @vou

const manualActiveCodesRows = await vouchersPage.getNumberOfGridRowsWithText("Active");

await expect(
expect(
manualActiveCodesRows,
`Given codes: ${code} should have status Active displayed on grid`,
).toEqual(1);
Expand All @@ -94,7 +92,7 @@ test("TC: SALEOR_86 Edit voucher to have free shipping discount @vouchers @e2e",

const codesRowsAfterSave = await vouchersPage.getNumberOfGridRows();

await expect(
expect(
codesRows,
`Same amount of codes should have status Active displayed on grid after switching to free shipping`,
).toEqual(codesRowsAfterSave);
Expand Down Expand Up @@ -128,9 +126,7 @@ test("TC: SALEOR_89 Create voucher with minimum value of order @vouchers @e2e",

const manualCodesRows = await vouchersPage.getNumberOfGridRowsWithText(code);

await expect(manualCodesRows, `Manually added code: ${code} should be visible on grid`).toEqual(
1,
);
expect(manualCodesRows, `Manually added code: ${code} should be visible on grid`).toEqual(1);
await vouchersPage.clickMinimalOrderValueButton();
await vouchersPage.typeMinimumOrderValue("Channel-PLN", "50");
await vouchersPage.clickSaveButton();
Expand All @@ -139,7 +135,7 @@ test("TC: SALEOR_89 Create voucher with minimum value of order @vouchers @e2e",

const manualActiveCodesRows = await vouchersPage.getNumberOfGridRowsWithText("Active");

await expect(
expect(
manualActiveCodesRows,
`Given codes: ${code} should have status Active displayed on grid`,
).toEqual(1);
Expand All @@ -159,7 +155,7 @@ test("TC: SALEOR_92 Delete voucher @vouchers @e2e", async () => {
await vouchersPage.expectSuccessBanner();
await vouchersPage.createVoucherButton.waitFor({ state: "visible" });
await vouchersPage.waitForGrid();
await expect(
expect(
await vouchersPage.findRowIndexBasedOnText([VOUCHERS.vouchers.voucherToBeDeleted.name]),
`Given vouchers: ${VOUCHERS.vouchers.voucherToBeBulkDeleted.names} should be deleted from the list`,
).toEqual([]);
Expand All @@ -173,7 +169,7 @@ test("TC: SALEOR_93 Bulk delete voucher @vouchers @e2e", async () => {
await vouchersPage.deleteVoucherDialog.clickDeleteButton();
await vouchersPage.expectSuccessBanner();
await vouchersPage.gotoVouchersListPage();
await expect(
expect(
await vouchersPage.findRowIndexBasedOnText(VOUCHERS.vouchers.voucherToBeBulkDeleted.names),
`Given vouchers: ${VOUCHERS.vouchers.voucherToBeBulkDeleted.names} should be deleted from the list`,
).toEqual([]);
Expand Down