From 013b7204d3bee6aec0f78964cc4e66d128f2d87e Mon Sep 17 00:00:00 2001 From: Suguru Hirahara Date: Mon, 17 Apr 2023 09:54:35 +0000 Subject: [PATCH] Update room-directory.spec.ts - use Cypress Testing Library (#10596) Signed-off-by: Suguru Hirahara --- .../e2e/room-directory/room-directory.spec.ts | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cypress/e2e/room-directory/room-directory.spec.ts b/cypress/e2e/room-directory/room-directory.spec.ts index 8a70c50fdb..a7fcfaf61f 100644 --- a/cypress/e2e/room-directory/room-directory.spec.ts +++ b/cypress/e2e/room-directory/room-directory.spec.ts @@ -48,15 +48,15 @@ describe("Room Directory", () => { // First add a local address `gaming` cy.contains(".mx_SettingsFieldset", "Local Addresses").within(() => { - cy.get(".mx_Field input").type("gaming"); - cy.contains(".mx_AccessibleButton", "Add").click(); - cy.get(".mx_EditableItem_item").should("contain", "#gaming:localhost"); + cy.findByRole("textbox").type("gaming"); + cy.findByRole("button", { name: "Add" }).click(); + cy.findByText("#gaming:localhost").should("have.class", "mx_EditableItem_item").should("exist"); }); // Publish into the public rooms directory cy.contains(".mx_SettingsFieldset", "Published Addresses").within(() => { - cy.get("#canonicalAlias").find(":selected").should("contain", "#gaming:localhost"); - cy.get(`[aria-label="Publish this room to the public in localhost's room directory?"]`) + cy.get("#canonicalAlias").find(":selected").findByText("#gaming:localhost"); + cy.findByLabelText("Publish this room to the public in localhost's room directory?") .click() .should("have.attr", "aria-checked", "true"); }); @@ -81,20 +81,25 @@ describe("Room Directory", () => { }); }); - cy.get('[role="button"][aria-label="Explore rooms"]').click(); + cy.findByRole("button", { name: "Explore rooms" }).click(); - cy.get('.mx_SpotlightDialog [aria-label="Search"]').type("Unknown Room"); - cy.get(".mx_SpotlightDialog .mx_SpotlightDialog_otherSearches_messageSearchText").should( - "contain", - "can't find the room you're looking for", - ); + cy.get(".mx_SpotlightDialog").within(() => { + cy.findByRole("textbox", { name: "Search" }).type("Unknown Room"); + cy.findByText("If you can't find the room you're looking for, ask for an invite or create a new room.") + .should("have.class", "mx_SpotlightDialog_otherSearches_messageSearchText") + .should("exist"); + }); cy.get(".mx_SpotlightDialog_wrapper").percySnapshotElement("Room Directory - filtered no results"); - cy.get('.mx_SpotlightDialog [aria-label="Search"]').type("{selectAll}{backspace}test1234"); - cy.contains(".mx_SpotlightDialog .mx_SpotlightDialog_result_publicRoomName", name).should("exist"); + cy.get(".mx_SpotlightDialog").within(() => { + cy.findByRole("textbox", { name: "Search" }).type("{selectAll}{backspace}test1234"); + cy.findByText(name).should("have.class", "mx_SpotlightDialog_result_publicRoomName").should("exist"); + }); + // Disabled because flaky - see https://github.com/vector-im/element-web/issues/24881 //cy.get(".mx_SpotlightDialog_wrapper").percySnapshotElement("Room Directory - filtered one result"); - cy.get(".mx_SpotlightDialog .mx_SpotlightDialog_option").find(".mx_AccessibleButton").contains("Join").click(); + + cy.get(".mx_SpotlightDialog .mx_SpotlightDialog_option").findByRole("button", { name: "Join" }).click(); cy.url().should("contain", `/#/room/#test1234:localhost`); });