Add cy.viewRoomById command (#11317)

... and use it to fix a racy composer test.

Fixes https://github.com/vector-im/element-web/issues/25527
This commit is contained in:
Richard van der Hoff 2023-07-25 22:55:13 +01:00 committed by GitHub
parent c57a4cb090
commit a47ee92094
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 18 deletions

View file

@ -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");

View file

@ -29,6 +29,15 @@ declare global {
*/
viewRoomByName(name: string): Chainable<JQuery<HTMLElement>>;
/**
* 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<JQuery<HTMLElem
return cy.findByRole("treeitem", { name: name }).should("have.class", "mx_RoomTile").click();
});
Cypress.Commands.add("viewRoomById", (id: string): void => {
cy.visit(`/#/room/${id}`);
});
Cypress.Commands.add("getSpacePanelButton", (name: string): Chainable<JQuery<HTMLElement>> => {
return cy.findByRole("button", { name: name }).should("have.class", "mx_SpaceButton");
});