Skip to content

Commit

Permalink
Split select options into 2 (#5301)
Browse files Browse the repository at this point in the history
* Split select options into 2

* Update .changeset/stupid-peas-work.md

Co-authored-by: Jonatan Witoszek <[email protected]>

---------

Co-authored-by: Jonatan Witoszek <[email protected]>
  • Loading branch information
michalina-graczyk and witoszekdev authored Dec 27, 2024
1 parent 0da914a commit 7c0c89d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-peas-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Split select link option into 2 different ones to avoid flakyness in tests
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
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}"`);
}
}

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
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

0 comments on commit 7c0c89d

Please sign in to comment.