diff --git a/cypress/e2e/composer/composer.spec.ts b/cypress/e2e/composer/composer.spec.ts index 2b49b5e32e..54e8441987 100644 --- a/cypress/e2e/composer/composer.spec.ts +++ b/cypress/e2e/composer/composer.spec.ts @@ -36,10 +36,8 @@ describe("Composer", () => { describe("CIDER", () => { beforeEach(() => { - cy.initTestUser(homeserver, "Janet").then(() => { - cy.createRoom({ name: "Composing Room" }); - }); - cy.viewRoomByName("Composing Room"); + cy.initTestUser(homeserver, "Janet"); + cy.createRoom({ name: "Composing Room" }).then((roomId) => cy.viewRoomById(roomId)); }); it("sends a message when you click send or press Enter", () => { @@ -113,10 +111,8 @@ describe("Composer", () => { describe("Rich text editor", () => { beforeEach(() => { cy.enableLabsFeature("feature_wysiwyg_composer"); - cy.initTestUser(homeserver, "Janet").then(() => { - cy.createRoom({ name: "Composing Room" }); - }); - cy.viewRoomByName("Composing Room"); + cy.initTestUser(homeserver, "Janet"); + cy.createRoom({ name: "Composing Room" }).then((roomId) => cy.viewRoomById(roomId)); }); describe("Commands", () => { @@ -188,7 +184,7 @@ describe("Composer", () => { describe("Plain text mode", () => { it("autocomplete behaviour tests", () => { - // Setup a private room so we have another user to mention + // Set up a private room so we have another user to mention const otherUserName = "Bob"; let bobClient: MatrixClient; cy.getBot(homeserver, { @@ -197,15 +193,16 @@ describe("Composer", () => { bobClient = bob; }); // create DM with bob - cy.getClient().then(async (cli) => { - const bobRoom = await cli.createRoom({ is_direct: true }); - await cli.invite(bobRoom.room_id, bobClient.getUserId()); - await cli.setAccountData("m.direct" as EventType, { - [bobClient.getUserId()]: [bobRoom.room_id], - }); - }); - - cy.viewRoomByName("Bob"); + cy.getClient() + .then(async (cli) => { + const bobRoom = await cli.createRoom({ is_direct: true }); + await cli.invite(bobRoom.room_id, bobClient.getUserId()); + await cli.setAccountData("m.direct" as EventType, { + [bobClient.getUserId()]: [bobRoom.room_id], + }); + return bobRoom.room_id; + }) + .then((bobRoomId) => cy.viewRoomById(bobRoomId)); // Select plain text mode after composer is ready cy.get("div[contenteditable=true]").should("exist"); diff --git a/cypress/support/views.ts b/cypress/support/views.ts index 2100e89459..d5bf917989 100644 --- a/cypress/support/views.ts +++ b/cypress/support/views.ts @@ -29,6 +29,15 @@ declare global { */ viewRoomByName(name: string): Chainable>; + /** + * Opens the given room by room ID. + * + * This works by browsing to `/#/room/${id}`, so it will also work for room aliases. + * + * @param id + */ + viewRoomById(id: string): void; + /** * Returns the space panel space button based on a name. The space * must be visible in the space panel @@ -57,6 +66,10 @@ Cypress.Commands.add("viewRoomByName", (name: string): Chainable { + cy.visit(`/#/room/${id}`); +}); + Cypress.Commands.add("getSpacePanelButton", (name: string): Chainable> => { return cy.findByRole("button", { name: name }).should("have.class", "mx_SpaceButton"); });