From 84dfc5d22d84efcee2d118f2ae6448bb77b0b319 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 13 Jan 2025 10:43:56 +0000 Subject: [PATCH] Fix flaky tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../e2e/right-panel/right-panel.spec.ts | 1 + .../general-room-settings-tab.spec.ts | 1 + playwright/pages/client.ts | 19 +++++++++---------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/playwright/e2e/right-panel/right-panel.spec.ts b/playwright/e2e/right-panel/right-panel.spec.ts index cb2a11ac00..0bdd0a283a 100644 --- a/playwright/e2e/right-panel/right-panel.spec.ts +++ b/playwright/e2e/right-panel/right-panel.spec.ts @@ -47,6 +47,7 @@ test.describe("RightPanel", () => { // Set a local room address const localAddresses = page.locator(".mx_SettingsFieldset", { hasText: "Local Addresses" }); await localAddresses.getByRole("textbox").fill(ROOM_ADDRESS_LONG); + await expect(page.getByText("This address is available to use")).toBeVisible(); await localAddresses.getByRole("button", { name: "Add" }).click(); await expect(localAddresses.getByText(`#${ROOM_ADDRESS_LONG}:localhost`)).toHaveClass( "mx_EditableItem_item", diff --git a/playwright/e2e/settings/general-room-settings-tab.spec.ts b/playwright/e2e/settings/general-room-settings-tab.spec.ts index eec32f7af5..5e29f802c2 100644 --- a/playwright/e2e/settings/general-room-settings-tab.spec.ts +++ b/playwright/e2e/settings/general-room-settings-tab.spec.ts @@ -41,6 +41,7 @@ test.describe("General room settings tab", () => { // 1. Set the room-address to be a really long string const longString = "abcasdhjasjhdaj1jh1asdhasjdhajsdhjavhjksd".repeat(4); await settings.locator("#roomAliases input[label='Room address']").fill(longString); + await expect(page.getByText("This address is available to use")).toBeVisible(); await settings.locator("#roomAliases").getByText("Add", { exact: true }).click(); // 2. wait for the new setting to apply ... diff --git a/playwright/pages/client.ts b/playwright/pages/client.ts index c2586f1b5e..362915ce71 100644 --- a/playwright/pages/client.ts +++ b/playwright/pages/client.ts @@ -179,18 +179,17 @@ export class Client { public async createRoom(options: ICreateRoomOpts): Promise { const client = await this.prepareClient(); return await client.evaluate(async (cli, options) => { - const roomPromise = new Promise((resolve) => { - const onRoom = (room: Room) => { - if (room.roomId === roomId) { - cli.off(window.matrixcs.ClientEvent.Room, onRoom); - resolve(); - } - }; - cli.on(window.matrixcs.ClientEvent.Room, onRoom); - }); const { room_id: roomId } = await cli.createRoom(options); if (!cli.getRoom(roomId)) { - await roomPromise; + await new Promise((resolve) => { + const onRoom = (room: Room) => { + if (room.roomId === roomId) { + cli.off(window.matrixcs.ClientEvent.Room, onRoom); + resolve(); + } + }; + cli.on(window.matrixcs.ClientEvent.Room, onRoom); + }); } return roomId; }, options);