diff --git a/cypress/components/dialog-full-screen/dialog-full-screen.cy.tsx b/cypress/components/dialog-full-screen/dialog-full-screen.cy.tsx deleted file mode 100644 index 2b409e2a85..0000000000 --- a/cypress/components/dialog-full-screen/dialog-full-screen.cy.tsx +++ /dev/null @@ -1,427 +0,0 @@ -import React from "react"; -import { DialogFullScreenProps } from "../../../src/components/dialog-full-screen"; -import { - DialogFullScreenComponent, - NestedDialog, - MultipleDialogsInDifferentProviders, - DialogFullScreenWithHeaderChildren, - mainDialogTitle, - nestedDialogTitle, - DialogFullScreenBackgroundScrollTestComponent, - DialogFullScreenBackgroundScrollWithOtherFocusableContainers, -} from "../../../src/components/dialog-full-screen/dialog-full-screen-test.stories"; -import { - Default as DefaultDocsStory, - WithComplexExample, - WithDisableContentPadding, - WithHeaderChildren, - WithHelp, - WithHideableHeaderChildren, - WithBox, - FocusingADifferentFirstElement, - OtherFocusableContainers, -} from "../../../src/components/dialog-full-screen/dialog-full-screen.stories"; -import { - dialogTitle, - dialogSubtitle, - alertDialogPreview as dialogPreview, -} from "../../locators/dialog"; -import { - dialogFullScreenPreview, - dialogFullScreenChildren, -} from "../../locators/dialog-full-screen"; -import { - closeIconButton, - openDialogByName, - portal, - getDataElementByValue, - tooltipPreview, - getComponent, - getElement, -} from "../../locators/index"; -import { buttonDataComponent } from "../../locators/button"; -import CypressMountWithProviders from "../../support/component-helper/cypress-mount"; -import { contentElement } from "../../locators/content/index"; -import { keyCode, continuePressingTABKey } from "../../support/helper"; -import { CHARACTERS } from "../../support/component-helper/constants"; - -const specialCharacters = [CHARACTERS.DIACRITICS, CHARACTERS.SPECIALCHARACTERS]; -const testAria = "cypress_aria"; - -context("Testing DialogFullScreen component", () => { - describe("render DialogFullScreen component and check properties", () => { - it("should close Dialog Full Screen component after click on closeIcon", () => { - CypressMountWithProviders(); - - closeIconButton().should("exist"); - dialogFullScreenPreview().should("exist"); - closeIconButton().click(); - dialogFullScreenPreview().should("not.exist"); - }); - - it.each(specialCharacters)( - "should render DialogFullScreen using %s as title", - (title) => { - CypressMountWithProviders(); - - dialogTitle().should("have.text", title); - } - ); - - it.each(specialCharacters)( - "should render DialogFullScreen using %s as subtitle", - (subtitle) => { - CypressMountWithProviders( - - ); - - dialogSubtitle().should("have.text", subtitle); - } - ); - - it.each(specialCharacters)( - "should render DialogFullScreen component with %s as a children", - (childrenValue) => { - CypressMountWithProviders( - {childrenValue} - ); - - dialogFullScreenChildren().should("have.text", childrenValue); - } - ); - - it("should render DialogFullScreen with disabledEscKey prop and not be closed after clicking Escape button", () => { - CypressMountWithProviders(); - - dialogFullScreenPreview().should("exist"); - dialogFullScreenPreview().trigger("keyup", keyCode("Esc")); - dialogFullScreenPreview().should("exist"); - }); - - it("should close DialogFullScreen after pressing Escape button", () => { - CypressMountWithProviders(); - dialogFullScreenPreview().should("exist"); - dialogFullScreenPreview().trigger("keyup", keyCode("Esc")); - dialogFullScreenPreview().should("not.exist"); - }); - - it("should call the cancel action after closing the DialogFullScreen", () => { - const callback: DialogFullScreenProps["onCancel"] = cy - .stub() - .as("onCancel"); - - CypressMountWithProviders( - - ); - - closeIconButton().click(); - cy.get("@onCancel").should("have.been.calledOnce"); - }); - - it("should allow to close nested DialogFullScreen and then the main DialogFullScreen window", () => { - CypressMountWithProviders(); - - openDialogByName(`Open ${mainDialogTitle}`).click(); - - openDialogByName(`Open ${nestedDialogTitle}`).click(); - - dialogPreview().should("exist"); - - portal().contains(nestedDialogTitle).should("be.visible"); - - dialogFullScreenPreview() - .contains(mainDialogTitle) - .should("not.be.visible"); - - portal().contains(nestedDialogTitle).trigger("keyup", keyCode("Esc")); - - dialogPreview().should("not.exist"); - - dialogFullScreenPreview().contains(mainDialogTitle).should("be.visible"); - - dialogFullScreenPreview().trigger("keyup", keyCode("Esc")); - - dialogFullScreenPreview().should("not.exist"); - }); - - it("should render nested dialogs with the aria-modal property only set on the top one", () => { - CypressMountWithProviders(); - - openDialogByName(`Open ${mainDialogTitle}`).click(); - - getElement("dialog-full-screen") - .should("have.attr", "aria-modal") - .and("eq", "true"); - - openDialogByName(`Open ${nestedDialogTitle}`).click(); - - getElement("dialog-full-screen").should("not.have.attr", "aria-modal"); - - getElement("dialog").should("have.attr", "aria-modal").and("eq", "true"); - }); - - it("should always place focus on the inner dialog when tabbing with nested dialogs after focus is lost", () => { - CypressMountWithProviders(); - - openDialogByName(`Open ${mainDialogTitle}`).click(); - - openDialogByName(`Open ${nestedDialogTitle}`).click(); - - // click on the body in order to lose focus - cy.get("body").click(); - cy.get("body").tab(); - - closeIconButton().eq(1).should("be.focused"); - }); - - it("should render nested dialogs with the aria-modal property only set on the top one, even when the dialogs are wrapped in separate CarbonProviders", () => { - cy.mount(); - - openDialogByName("Open Modal 1").click(); - - getElement("dialog-full-screen") - .should("have.attr", "aria-modal") - .and("eq", "true"); - - openDialogByName("Open Modal 2").click(); - - getElement("dialog-full-screen").should("not.have.attr", "aria-modal"); - - getElement("dialog").should("have.attr", "aria-modal").and("eq", "true"); - }); - - it("should render DialogFullScreen component with aria-describedby", () => { - CypressMountWithProviders( - - ); - - dialogFullScreenPreview() - .should("have.attr", "aria-describedby") - .and("contain", testAria); - }); - - it("should render DialogFullScreen component with aria-label", () => { - CypressMountWithProviders( - - ); - dialogFullScreenPreview() - .should("have.attr", "aria-label") - .and("contain", testAria); - }); - - it("should render DialogFullScreen component with aria-labelledby", () => { - CypressMountWithProviders( - - ); - - dialogFullScreenPreview() - .should("have.attr", "aria-labelledby") - .and("contain", testAria); - }); - - it("should render DialogFullScreen component using focusFirstElement", () => { - CypressMountWithProviders(); - cy.contains("This should be focused first now").should("have.focus"); - }); - - it("should render Dialog component disabling autofocus", () => { - CypressMountWithProviders(); - cy.contains("This should be focused first now").should("not.have.focus"); - }); - - it("should render DialogFullScreen component with help", () => { - CypressMountWithProviders( - - ); - getDataElementByValue("question").trigger("mouseover"); - tooltipPreview().should("have.text", "Some help text"); - }); - - it("should render DialogFullScreen component with role", () => { - CypressMountWithProviders(); - dialogFullScreenPreview() - .should("have.attr", "role") - .and("contain", "dialog"); - }); - - it("should not render close icon when ShowCloseIcon is set to false", () => { - CypressMountWithProviders( - - ); - - closeIconButton().should("not.exist"); - }); - - it("should render close icon when ShowCloseIcon is set to true. When you click the CloseIcon the Dialog is closed", () => { - CypressMountWithProviders(); - - dialogFullScreenPreview().should("exist"); - closeIconButton().click(); - dialogFullScreenPreview().should("not.exist"); - }); - - it("should render Dialog Full Screen with header children", () => { - CypressMountWithProviders(); - - getComponent("pill").eq(0).should("have.text", "A pill"); - - getComponent("pill").eq(1).should("have.text", "Another pill"); - }); - - it("should render Dialog component with content padding disabled", () => { - CypressMountWithProviders( - - ); - contentElement() - .should("have.css", "padding-right", "0px") - .should("have.css", "padding-bottom", "0px"); - }); - - // skip this test for now as FE-6053 has not been fixed yet - it.skip("should render DialogFullScreen component with DisableClose prop", () => { - CypressMountWithProviders(); - closeIconButton().click(); - dialogFullScreenPreview().should("exist"); - }); - }); - - describe("should check accessibility for Dialog Full Screen", () => { - it("should check accessibility for default Dialog Full Screen component", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen with complex example", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen with disabled content padding", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen component with header children", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen component with help", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen component with hideable header children", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen component with box", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen component using autoFocus", () => { - CypressMountWithProviders(); - - buttonDataComponent() - .contains("Open Demo using focusFirstElement") - .click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - closeIconButton().click(); - - buttonDataComponent().contains("Open Demo using autoFocus").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - - it("should check accessibility for default Dialog Full Screen component with other focusable containers", () => { - CypressMountWithProviders(); - - buttonDataComponent().contains("Open DialogFullScreen").click(); - closeIconButton().should("be.visible"); - cy.checkAccessibility(); - }); - }); - - describe("test background scroll when tabbing", () => { - it("tabbing forward through the dialog and back to the start should not make the background scroll to the bottom", () => { - CypressMountWithProviders( - - ); - - continuePressingTABKey(3); - - closeIconButton().should("be.focused"); - - cy.checkNotInViewport("#bottom-box"); - }); - - it("tabbing backward through the dialog and back to the start should not make the background scroll to the bottom", () => { - CypressMountWithProviders( - - ); - - continuePressingTABKey(2, true); - - closeIconButton().should("be.focused"); - - cy.checkNotInViewport("#bottom-box"); - }); - - it("tabbing forward through the dialog and other focusable containers back to the start should not make the background scroll to the bottom", () => { - CypressMountWithProviders( - - ); - - continuePressingTABKey(6); - - closeIconButton().eq(0).should("be.focused"); - - cy.checkNotInViewport("#bottom-box"); - }); - - it("tabbing backward through the dialog and other focusable containers back to the start should not make the background scroll to the bottom", () => { - CypressMountWithProviders( - - ); - - continuePressingTABKey(7, true); - - closeIconButton().eq(0).should("be.focused"); - - cy.checkNotInViewport("#bottom-box"); - }); - }); -}); diff --git a/cypress/components/navigation-bar/navigation-bar.cy.tsx b/cypress/components/navigation-bar/navigation-bar.cy.tsx deleted file mode 100644 index d74431b661..0000000000 --- a/cypress/components/navigation-bar/navigation-bar.cy.tsx +++ /dev/null @@ -1,242 +0,0 @@ -import React from "react"; -import Box from "../../../src/components/box"; -import NavigationBar, { - NavigationBarProps, -} from "../../../src/components/navigation-bar"; -import { NavigationBarComponent } from "../../../src/components/navigation-bar/navigation-bar-test.stories"; -import { Menu, MenuItem } from "../../../src/components/menu"; -import * as stories from "../../../src/components/navigation-bar/navigation-bar.stories"; -import CypressMountWithProviders from "../../support/component-helper/cypress-mount"; - -import navigationBar from "../../locators/navigation-bar"; -import { COLOR, CHARACTERS } from "../../support/component-helper/constants"; - -const specialCharacters = [CHARACTERS.DIACRITICS, CHARACTERS.SPECIALCHARACTERS]; -const testData = CHARACTERS.STANDARD; -const variants = [ - ["black", COLOR.BLACK], - ["light", "rgb(230, 235, 237)"], - ["white", "rgb(255, 255, 255)"], - ["dark", "rgb(0, 50, 76)"], -] as [NavigationBarProps["navigationType"], string][]; -const offsetVal = [25, 100, -100]; - -context("Testing NavigationBar component", () => { - describe("should render NavigationBar component", () => { - it.each(specialCharacters)( - "should render NavigationBar component with %s as a children", - (childrenValue) => { - CypressMountWithProviders( - {childrenValue} - ); - - navigationBar().should("have.text", childrenValue); - } - ); - - it("should render NavigationBar component with ariaLabel prop", () => { - CypressMountWithProviders( - - ); - - navigationBar().should("have.attr", "aria-label", testData); - }); - - it.each(variants)( - "should render NavigationBar component with %s as a navigationType", - (navigationType, color) => { - CypressMountWithProviders( - - ); - - navigationBar().should("have.css", "background-color", color); - } - ); - - it.each([ - [true, "not.exist"], - [false, "be.visible"], - ])( - "should render NavigationBar component with isLoading prop set to %s", - (boolean, assertion) => { - CypressMountWithProviders( - - {testData} - - ); - - cy.contains(testData).should(assertion); - } - ); - - it.each(["fixed", "sticky"] as NavigationBarProps["position"][])( - "should render NavigationBar component with position prop set to %s with orientation set to top", - (position) => { - CypressMountWithProviders( - - ); - - navigationBar().should("have.css", "position", position); - } - ); - - it.each(["fixed", "sticky"] as NavigationBarProps["position"][])( - "should render NavigationBar component with position prop set to %s with orientation set to bottom", - (position) => { - CypressMountWithProviders( - - ); - - navigationBar().should("have.css", "position", position); - } - ); - - describe.each(["top", "bottom"] as NavigationBarProps["orientation"][])( - "orientation %s", - (orientation) => { - it.each(offsetVal)( - "should render NavigationBar component with offset prop set to %s px", - (offset) => { - CypressMountWithProviders( - - ); - navigationBar().should("have.css", orientation, `${offset}px`); - } - ); - } - ); - - it.each(["top", "bottom"] as NavigationBarProps["orientation"][])( - "should render NavigationBar component with orientation prop set to %s", - (orientation) => { - CypressMountWithProviders( - - ); - - navigationBar().should("have.css", orientation, "0px"); - } - ); - - it.each([ - ["fixed", "be.visible"], - ["sticky", "not.be.visible"], - ] as [NavigationBarProps["position"], string][])( - "should render NavigationBar component with position prop set to %s and work as expected", - (position, assertionOfFirstNavBar) => { - CypressMountWithProviders( -
- - - - {}}> - Menu Item One - - - - -
- - - - {}}> - Menu Item One - - - - -
- ); - - navigationBar().eq(0).should("be.visible"); - navigationBar().eq(1).should("be.visible"); - cy.scrollTo("bottomRight"); - navigationBar().eq(0).should(assertionOfFirstNavBar); - navigationBar().eq(1).should("be.visible"); - } - ); - }); - - describe("Accessibility tests for NavigationBar component", () => { - it("should pass accessibility tests for NavigationBar Default story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar DarkTheme story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar WhiteTheme story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar BlackTheme story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar ExampleWithMenu story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar IsLoading story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar WithCustomSpacing story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar ContentMaxWidthBox story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar Sticky story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - - it("should pass accessibility tests for NavigationBar Fixed story", () => { - CypressMountWithProviders(); - - cy.checkAccessibility(); - }); - }); -}); diff --git a/cypress/locators/dialog-full-screen/index.js b/cypress/locators/dialog-full-screen/index.js deleted file mode 100644 index 24c62e1ff3..0000000000 --- a/cypress/locators/dialog-full-screen/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import { - DIALOG_FULL_SCREEN_CHILDREN, - DIALOG_FULL_SCREEN, - DIALOG_FULL_SCREEN_CLOSE_STATE, -} from "./locators"; - -// component preview locators -export const dialogFullScreenChildren = () => - cy.get(DIALOG_FULL_SCREEN_CHILDREN).eq(0); -export const dialogFullScreenPreview = () => cy.get(DIALOG_FULL_SCREEN); -export const dialogFullScreenPreviewClosedState = () => - cy.get(DIALOG_FULL_SCREEN_CLOSE_STATE); diff --git a/cypress/locators/dialog-full-screen/locators.js b/cypress/locators/dialog-full-screen/locators.js deleted file mode 100644 index 1e29e18766..0000000000 --- a/cypress/locators/dialog-full-screen/locators.js +++ /dev/null @@ -1,5 +0,0 @@ -// component preview locators -export const DIALOG_FULL_SCREEN_CHILDREN = '[data-component="form"]'; -export const DIALOG_FULL_SCREEN = 'div[data-element="dialog-full-screen"]'; -export const DIALOG_FULL_SCREEN_CLOSE_STATE = - 'div[data-component="dialog-full-screen"][data-state="closed"]'; diff --git a/playwright/components/index.ts b/playwright/components/index.ts index bd57a4605e..d98765264b 100644 --- a/playwright/components/index.ts +++ b/playwright/components/index.ts @@ -10,6 +10,7 @@ import { LABEL, STICKY_FOOTER, COMMMON_DATA_ELEMENT_INPUT, + PORTAL, } from "./locators"; export const icon = (page: Page) => { @@ -67,3 +68,11 @@ export const label = (page: Page) => { export const legendSpan = (page: Page) => { return page.locator("legend > span"); }; + +export const openDialogByName = (page: Page, name: string) => { + getDataElementByValue(page, "main-text").filter({ hasText: name }); +}; + +export const portal = (page: Page) => { + return page.locator(PORTAL).nth(1).locator("h1"); +}; diff --git a/playwright/components/navigation-bar/index.ts b/playwright/components/navigation-bar/index.ts new file mode 100644 index 0000000000..3213f928fb --- /dev/null +++ b/playwright/components/navigation-bar/index.ts @@ -0,0 +1,7 @@ +import { Page } from "playwright-core"; +import NAVIGATION_BAR from "./locators"; + +// component preview locators +const navigationBar = (page: Page) => page.locator(NAVIGATION_BAR); + +export default navigationBar; diff --git a/playwright/components/navigation-bar/locators.ts b/playwright/components/navigation-bar/locators.ts new file mode 100644 index 0000000000..1bc91e37c8 --- /dev/null +++ b/playwright/components/navigation-bar/locators.ts @@ -0,0 +1,4 @@ +// component preview locators +const NAVIGATION_BAR = '[data-component="navigation-bar"]'; + +export default NAVIGATION_BAR; diff --git a/playwright/support/helper.ts b/playwright/support/helper.ts index a26655bb1a..f33aa191f1 100644 --- a/playwright/support/helper.ts +++ b/playwright/support/helper.ts @@ -330,3 +330,23 @@ export const getDesignTokensByCssProperty = async ( } return tokens; }; + +export const continuePressingTAB = async (page: Page, count: number) => { + const promises = []; + + for (let i = 0; i < count; i++) { + promises.push(page.keyboard.press(`Tab`)); + } + + await Promise.all(promises); +}; + +export const continuePressingSHIFTTAB = async (page: Page, count: number) => { + const promises = []; + + for (let i = 0; i < count; i++) { + promises.push(page.keyboard.press(`Shift+Tab`)); + } + + await Promise.all(promises); +}; diff --git a/src/components/batch-selection/batch-selection.pw.tsx b/src/components/batch-selection/batch-selection.pw.tsx index 555d0685fe..04804f4e44 100644 --- a/src/components/batch-selection/batch-selection.pw.tsx +++ b/src/components/batch-selection/batch-selection.pw.tsx @@ -13,6 +13,7 @@ import { batchSelectionComponent, batchSelectionButtonsByPosition, } from "../../../playwright/components/batch-selection"; +import { getComponent } from "../../../playwright/components/index"; import { HooksConfig } from "../../../playwright"; const BATCH_SELECTION_COLOR = [ @@ -39,25 +40,25 @@ test.describe("check BatchSelection component properties", () => { test("should check hidden BatchSelection", async ({ mount, page }) => { await mount(