From 4c0efc5e68398b34d273f1582be37057a267d72a Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Mon, 17 Apr 2023 07:37:49 +0000 Subject: [PATCH] Update Cypress test files under `support/` directory - use Cypress Testing Library (#10619) * Update support files - use Cypress Testing Library Signed-off-by: Suguru Hirahara * Fix openMessageComposerOptions() Signed-off-by: Suguru Hirahara --------- Signed-off-by: Suguru Hirahara --- cypress/support/composer.ts | 2 +- cypress/support/settings.ts | 14 +++++++------- cypress/support/views.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cypress/support/composer.ts b/cypress/support/composer.ts index 347c581a47..ab094d6280 100644 --- a/cypress/support/composer.ts +++ b/cypress/support/composer.ts @@ -39,7 +39,7 @@ Cypress.Commands.add("getComposer", (isRightPanel?: boolean): Chainable Cypress.Commands.add("openMessageComposerOptions", (isRightPanel?: boolean): Chainable => { cy.getComposer(isRightPanel).within(() => { - cy.get('[aria-label="More options"]').click(); + cy.findByRole("button", { name: "More options" }).click(); }); return cy.get(".mx_MessageComposer_Menu"); }); diff --git a/cypress/support/settings.ts b/cypress/support/settings.ts index 78c3f68878..d94811af6e 100644 --- a/cypress/support/settings.ts +++ b/cypress/support/settings.ts @@ -125,13 +125,13 @@ Cypress.Commands.add( ); Cypress.Commands.add("openUserMenu", (): Chainable> => { - cy.get('[aria-label="User menu"]').click(); + cy.findByRole("button", { name: "User menu" }).click(); return cy.get(".mx_ContextualMenu"); }); Cypress.Commands.add("openUserSettings", (tab?: string): Chainable> => { cy.openUserMenu().within(() => { - cy.get('[aria-label="All settings"]').click(); + cy.findByRole("menuitem", { name: "All settings" }).click(); }); return cy.get(".mx_UserSettingsDialog").within(() => { if (tab) { @@ -141,9 +141,9 @@ Cypress.Commands.add("openUserSettings", (tab?: string): Chainable> => { - cy.get(".mx_RoomHeader_name").click(); + cy.findByRole("button", { name: "Room options" }).click(); cy.get(".mx_RoomTile_contextMenu").within(() => { - cy.get('[aria-label="Settings"]').click(); + cy.findByRole("menuitem", { name: "Settings" }).click(); }); return cy.get(".mx_RoomSettingsDialog").within(() => { if (tab) { @@ -159,7 +159,7 @@ Cypress.Commands.add("switchTab", (tab: string): Chainable> }); Cypress.Commands.add("closeDialog", (): Chainable> => { - return cy.get('[aria-label="Close dialog"]').click(); + return cy.findByRole("button", { name: "Close dialog" }).click(); }); Cypress.Commands.add("joinBeta", (name: string): Chainable> => { @@ -167,7 +167,7 @@ Cypress.Commands.add("joinBeta", (name: string): Chainable> .contains(".mx_BetaCard_title", name) .closest(".mx_BetaCard") .within(() => { - return cy.get(".mx_BetaCard_buttons").contains("Join the beta").click(); + return cy.get(".mx_BetaCard_buttons").findByRole("button", { name: "Join the beta" }).click(); }); }); @@ -176,7 +176,7 @@ Cypress.Commands.add("leaveBeta", (name: string): Chainable> .contains(".mx_BetaCard_title", name) .closest(".mx_BetaCard") .within(() => { - return cy.get(".mx_BetaCard_buttons").contains("Leave the beta").click(); + return cy.get(".mx_BetaCard_buttons").findByRole("button", { name: "Leave the beta" }).click(); }); }); diff --git a/cypress/support/views.ts b/cypress/support/views.ts index 45337cd558..2100e89459 100644 --- a/cypress/support/views.ts +++ b/cypress/support/views.ts @@ -54,11 +54,11 @@ declare global { } Cypress.Commands.add("viewRoomByName", (name: string): Chainable> => { - return cy.get(`.mx_RoomTile[aria-label="${name}"]`).click(); + return cy.findByRole("treeitem", { name: name }).should("have.class", "mx_RoomTile").click(); }); Cypress.Commands.add("getSpacePanelButton", (name: string): Chainable> => { - return cy.get(`.mx_SpaceButton[aria-label="${name}"]`); + return cy.findByRole("button", { name: name }).should("have.class", "mx_SpaceButton"); }); Cypress.Commands.add("viewSpaceByName", (name: string): Chainable> => {