Update spotlight.spec.ts - use Cypress Testing Library (#10621)

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>
This commit is contained in:
Suguru Hirahara 2023-04-17 14:06:20 +00:00 committed by GitHub
parent 568ec77208
commit 7114f82e6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -100,7 +100,7 @@ Cypress.Commands.add(
Cypress.Commands.add( Cypress.Commands.add(
"spotlightSearch", "spotlightSearch",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => { (options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_SpotlightDialog_searchBox input", options); return cy.get(".mx_SpotlightDialog_searchBox", options).findByRole("textbox", { name: "Search" });
}, },
); );
@ -129,10 +129,10 @@ Cypress.Commands.add("startDM", (name: string) => {
cy.spotlightResults().eq(0).click(); cy.spotlightResults().eq(0).click();
}); });
// send first message to start DM // send first message to start DM
cy.get(".mx_BasicMessageComposer_input").should("have.focus").type("Hey!{enter}"); cy.findByRole("textbox", { name: "Send a message…" }).should("have.focus").type("Hey!{enter}");
// The DM room is created at this point, this can take a little bit of time // The DM room is created at this point, this can take a little bit of time
cy.contains(".mx_EventTile_body", "Hey!", { timeout: 30000 }); cy.get(".mx_EventTile_body", { timeout: 30000 }).findByText("Hey!");
cy.contains(".mx_RoomSublist[aria-label=People]", name); cy.findByRole("group", { name: "People" }).findByText(name);
}); });
describe("Spotlight", () => { describe("Spotlight", () => {
@ -290,7 +290,7 @@ describe("Spotlight", () => {
cy.url().should("contain", room3Id); cy.url().should("contain", room3Id);
}) })
.then(() => { .then(() => {
cy.get(".mx_RoomPreviewBar_actions .mx_AccessibleButton").click(); cy.findByRole("button", { name: "Join the discussion" }).click();
cy.roomHeaderName().should("contain", room3Name); cy.roomHeaderName().should("contain", room3Name);
}); });
}); });
@ -365,11 +365,11 @@ describe("Spotlight", () => {
// Send first message to actually start DM // Send first message to actually start DM
cy.roomHeaderName().should("contain", bot2Name); cy.roomHeaderName().should("contain", bot2Name);
cy.get(".mx_BasicMessageComposer_input").click().should("have.focus").type("Hey!{enter}"); cy.findByRole("textbox", { name: "Send a message…" }).type("Hey!{enter}");
// Assert DM exists by checking for the first message and the room being in the room list // Assert DM exists by checking for the first message and the room being in the room list
cy.contains(".mx_EventTile_body", "Hey!", { timeout: 30000 }); cy.contains(".mx_EventTile_body", "Hey!", { timeout: 30000 });
cy.get(".mx_RoomSublist[aria-label=People]").should("contain", bot2Name); cy.findByRole("group", { name: "People" }).should("contain", bot2Name);
// Invite BotBob into existing DM with ByteBot // Invite BotBob into existing DM with ByteBot
cy.getDmRooms(bot2.getUserId()) cy.getDmRooms(bot2.getUserId())
@ -378,7 +378,7 @@ describe("Spotlight", () => {
.then((groupDm) => { .then((groupDm) => {
cy.inviteUser(groupDm.roomId, bot1.getUserId()); cy.inviteUser(groupDm.roomId, bot1.getUserId());
cy.roomHeaderName().should(($element) => expect($element.get(0).innerText).contains(groupDm.name)); cy.roomHeaderName().should(($element) => expect($element.get(0).innerText).contains(groupDm.name));
cy.get(".mx_RoomSublist[aria-label=People]").should(($element) => cy.findByRole("group", { name: "People" }).should(($element) =>
expect($element.get(0).innerText).contains(groupDm.name), expect($element.get(0).innerText).contains(groupDm.name),
); );
@ -440,7 +440,7 @@ describe("Spotlight", () => {
cy.get(".mx_SpotlightDialog_startGroupChat").click(); cy.get(".mx_SpotlightDialog_startGroupChat").click();
}) })
.then(() => { .then(() => {
cy.get("[role=dialog]").should("contain", "Direct Messages"); cy.findByRole("dialog").should("contain", "Direct Messages");
}); });
}); });