From d171508c7ab858d333bd913a72578f9366553700 Mon Sep 17 00:00:00 2001 From: James Parslow Date: Thu, 3 Oct 2024 13:00:10 +0100 Subject: [PATCH] test: fix broken playwright tests affected by Dialog markup changes --- playwright/components/alert/index.ts | 13 +--- playwright/components/select/index.ts | 4 -- src/components/alert/alert.pw.tsx | 5 +- src/components/date/date.pw.tsx | 61 +++++++++++++------ .../filterable-select.pw.tsx | 28 +++++---- 5 files changed, 60 insertions(+), 51 deletions(-) diff --git a/playwright/components/alert/index.ts b/playwright/components/alert/index.ts index 2045f454b9..ddf73759d1 100644 --- a/playwright/components/alert/index.ts +++ b/playwright/components/alert/index.ts @@ -27,15 +27,4 @@ const alertDialog = (page: Page) => { return page.locator(ALERT_DIALOG); }; -const alertChildren = (page: Page) => { - return page.locator('[data-component="alert"] div:nth-of-type(2) div'); -}; - -export { - alert, - alertCrossIcon, - alertTitle, - alertSubtitle, - alertDialog, - alertChildren, -}; +export { alert, alertCrossIcon, alertTitle, alertSubtitle, alertDialog }; diff --git a/playwright/components/select/index.ts b/playwright/components/select/index.ts index 3b79b12fe3..c5f2f19bc4 100644 --- a/playwright/components/select/index.ts +++ b/playwright/components/select/index.ts @@ -14,7 +14,6 @@ import { SELECT_LIST_SCROLLABLE_WRAPPER, } from "./locators"; import { PILL_PREVIEW } from "../pill/locators"; -import { ALERT_DIALOG } from "../dialog/locators"; import { getDataElementByValue } from ".."; // component preview locators @@ -102,8 +101,5 @@ export const filterableSelectAddElementButton = (page: Page) => export const filterableSelectButtonIcon = (page: Page) => filterableSelectAddElementButton(page).locator("span:nth-child(2)"); -export const filterableSelectAddNewButton = (page: Page) => - page.locator(ALERT_DIALOG).locator("div:nth-child(3) > div > button"); - export const selectResetButton = (page: Page) => page.locator(SELECT_RESET_BUTTON); diff --git a/src/components/alert/alert.pw.tsx b/src/components/alert/alert.pw.tsx index 63e4aa0520..71b68e6973 100644 --- a/src/components/alert/alert.pw.tsx +++ b/src/components/alert/alert.pw.tsx @@ -4,7 +4,6 @@ import { alertCrossIcon, alertTitle, alertSubtitle, - alertChildren, alertDialog, } from "../../../playwright/components/alert"; import { @@ -50,9 +49,7 @@ test.describe("should render Alert component", () => { test(`with ${text} as children`, async ({ mount, page }) => { await mount({text}); - const children = alertChildren(page); - const alertChildrenText = await children.textContent(); - expect(alertChildrenText).toEqual(text); + await expect(page.getByText(text)).toBeVisible(); }); }); diff --git a/src/components/date/date.pw.tsx b/src/components/date/date.pw.tsx index 71b21b231c..34b8335059 100644 --- a/src/components/date/date.pw.tsx +++ b/src/components/date/date.pw.tsx @@ -1,7 +1,6 @@ import React from "react"; import { expect, test } from "@playwright/experimental-ct-react17"; import dayjs from "dayjs"; -import Confirm from "../confirm"; import { DateInputCustom, DateInputValidationNewDesign, @@ -784,26 +783,48 @@ test.describe("Functionality tests", () => { await expect(wrapper).toBeVisible(); }); - [true, false].forEach((state) => { - test(`should render with disablePortal prop ${state}`, async ({ - mount, - page, - }) => { - await mount( - {}}> - - - ); + test("date picker does not float above the rest of the page, when disablePortal prop is true", async ({ + mount, + page, + }) => { + await mount( +
+ +
+ ); - const input = getDataElementByValue(page, "input"); - await input.click(); - const wrapper = dayPickerWrapper(page); - if (state) { - await expect(wrapper).not.toBeInViewport(); - } else { - await expect(wrapper).toBeInViewport(); - } - }); + const input = page.getByLabel("Date"); + await input.click(); + const datePicker = dayPickerWrapper(page); + await expect(datePicker).not.toBeInViewport(); + }); + test("date picker floats above the rest of the page, when disablePortal prop is false", async ({ + mount, + page, + }) => { + await mount( +
+ +
+ ); + const input = page.getByLabel("Date"); + await input.click(); + const datePicker = dayPickerWrapper(page); + await expect(datePicker).toBeInViewport(); }); test(`should have the expected border radius styling`, async ({ diff --git a/src/components/select/filterable-select/filterable-select.pw.tsx b/src/components/select/filterable-select/filterable-select.pw.tsx index d004fb0e22..88abf4a845 100644 --- a/src/components/select/filterable-select/filterable-select.pw.tsx +++ b/src/components/select/filterable-select/filterable-select.pw.tsx @@ -31,7 +31,6 @@ import { boldedAndUnderlinedValue, dropdownButton, filterableSelectAddElementButton, - filterableSelectAddNewButton, filterableSelectButtonIcon, multiColumnsSelectListBody, multiColumnsSelectListHeader, @@ -1088,19 +1087,26 @@ test.describe("FilterableSelect component", () => { mount, page, }) => { + const newOption = "New10"; await mount(); - const newOption = "New10"; - await dropdownButton(page).click(); - await expect(selectListWrapper(page)).toBeVisible(); - const addElementButtonElement = filterableSelectAddElementButton(page); - await expect(addElementButtonElement).toBeVisible(); + // open select list + const input = page.getByRole("combobox"); + await input.click(); + await expect(page.getByRole("listbox")).toBeVisible(); + + const addElementButtonElement = page.getByRole("button", { + name: "Add a New Element", + }); await addElementButtonElement.click(); - await expect(alertDialogPreview(page)).toBeVisible(); - const addNewButtonElement = filterableSelectAddNewButton(page); - await expect(addNewButtonElement).toBeVisible(); - await addNewButtonElement.click(); - await expect(getDataElementByValue(page, "input")).toHaveValue(newOption); + + const alert = page.getByRole("dialog"); + await expect(alert).toBeVisible(); + + const alertAddNewButton = page.getByRole("button", { name: "Add new" }); + await alertAddNewButton.click(); + + await expect(input).toHaveValue(newOption); }); test("should have correct hover state of list option", async ({