Skip to content

Commit d1a9f95

Browse files
authored
Use the toasts utils instead of the toasts fixture in playwright tests (#33495)
1 parent bf820c5 commit d1a9f95

6 files changed

Lines changed: 50 additions & 47 deletions

File tree

apps/web/playwright/e2e/crypto/device-verification.spec.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Please see LICENSE files in the repository root for full details.
77
*/
88

99
import jsQR from "jsqr";
10+
import { assertNoToasts, getToast, rejectToast } from "@element-hq/element-web-playwright-common";
1011

1112
import type { JSHandle, Locator, Page } from "@playwright/test";
1213
import type { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
@@ -81,11 +82,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
8182
);
8283

8384
// Regression test for https://github.com/element-hq/element-web/issues/29110
84-
test("No toast after verification, even if the secrets take a while to arrive", async ({
85-
page,
86-
credentials,
87-
toasts,
88-
}) => {
85+
test("No toast after verification, even if the secrets take a while to arrive", async ({ page, credentials }) => {
8986
// Before we log in, the bot creates an encrypted room, so that we can test the toast behaviour that only happens
9087
// when we are in an encrypted room.
9188
await aliceBotClient.createRoom({
@@ -124,9 +121,9 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
124121
await infoDialog.getByRole("button", { name: "Got it" }).click();
125122

126123
// There should be no toast (other than the notifications one)
127-
await toasts.rejectToast("Verify this device");
128-
await toasts.rejectToast("Notifications");
129-
await toasts.assertNoToasts();
124+
await rejectToast(page, "Verify this device");
125+
await rejectToast(page, "Notifications");
126+
await assertNoToasts(page);
130127

131128
// There may still be a `/sendToDevice/m.secret.request` in flight, which will later throw an error and cause
132129
// a *subsequent* test to fail. Tell playwright to ignore any errors resulting from in-flight routes.
@@ -273,7 +270,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
273270
await checkDeviceIsConnectedKeyBackup(app, expectedBackupVersion, true);
274271
}
275272

276-
test("Handle incoming verification request with SAS", async ({ page, credentials, homeserver, toasts, app }) => {
273+
test("Handle incoming verification request with SAS", async ({ page, credentials, homeserver, app }) => {
277274
/* Log in but don't verify the device */
278275
await logIntoElement(page, credentials);
279276
const authPage = page.locator(".mx_AuthPage");
@@ -303,7 +300,7 @@ test.describe("Device verification", { tag: "@no-webkit" }, () => {
303300
);
304301

305302
/* Check the toast for the incoming request */
306-
const toast = await toasts.getToast("Verification requested");
303+
const toast = await getToast(page, "Verification requested");
307304
// it should contain the device ID of the requesting device
308305
await expect(toast.getByText(`${aliceBotClient.credentials.deviceId} from `)).toBeVisible();
309306
// Accept

apps/web/playwright/e2e/crypto/toasts.spec.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { type GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
9+
import { assertNoToasts, getToast, rejectToast } from "@element-hq/element-web-playwright-common";
910

1011
import { test, expect } from "../../element-web-test";
1112
import { createBot, deleteCachedSecrets, disableKeyBackup, logIntoElement, logIntoElementAndVerify } from "./utils";
@@ -63,7 +64,7 @@ test.describe("Key storage out of sync toast", () => {
6364
test.describe("'Turn on key storage' toast", () => {
6465
let botClient: Bot | undefined;
6566

66-
test.beforeEach(async ({ page, homeserver, credentials, toasts }) => {
67+
test.beforeEach(async ({ page, homeserver, credentials }) => {
6768
// Set up all crypto stuff. Key storage defaults to on.
6869

6970
const res = await createBot(page, homeserver, credentials);
@@ -81,13 +82,13 @@ test.describe("'Turn on key storage' toast", () => {
8182
await page.getByRole("textbox", { name: "Name" }).fill("Test room");
8283
await page.getByRole("button", { name: "Create room" }).click();
8384

84-
await toasts.rejectToast("Notifications");
85+
await rejectToast(page, "Notifications");
8586
});
8687

87-
test("should not show toast if key storage is on", async ({ page, toasts }) => {
88+
test("should not show toast if key storage is on", async ({ page }) => {
8889
// Given the default situation after signing in
8990
// Then no toast is shown (because key storage is on)
90-
await toasts.assertNoToasts();
91+
await assertNoToasts(page);
9192

9293
// When we reload
9394
await page.reload();
@@ -96,15 +97,15 @@ test.describe("'Turn on key storage' toast", () => {
9697
await new Promise((resolve) => setTimeout(resolve, 2000));
9798

9899
// Then still no toast is shown
99-
await toasts.assertNoToasts();
100+
await assertNoToasts(page);
100101
});
101102

102-
test("should not show toast if key storage is off because we turned it off", async ({ app, page, toasts }) => {
103+
test("should not show toast if key storage is off because we turned it off", async ({ app, page }) => {
103104
// Given the backup is disabled because we disabled it
104105
await disableKeyBackup(app);
105106

106107
// Then no toast is shown
107-
await toasts.assertNoToasts();
108+
await assertNoToasts(page);
108109

109110
// When we reload
110111
await page.reload();
@@ -113,10 +114,10 @@ test.describe("'Turn on key storage' toast", () => {
113114
await new Promise((resolve) => setTimeout(resolve, 2000));
114115

115116
// Then still no toast is shown
116-
await toasts.assertNoToasts();
117+
await assertNoToasts(page);
117118
});
118119

119-
test("should show toast if key storage is off but account data is missing", async ({ app, page, toasts }) => {
120+
test("should show toast if key storage is off but account data is missing", async ({ app, page }) => {
120121
// Given the backup is disabled but we didn't set account data saying that is expected
121122
await disableKeyBackup(app);
122123
await botClient.setAccountData("m.org.matrix.custom.backup_disabled", { disabled: false });
@@ -128,7 +129,7 @@ test.describe("'Turn on key storage' toast", () => {
128129
await page.reload();
129130

130131
// Then the toast is displayed
131-
let toast = await toasts.getToast("Turn on key storage");
132+
let toast = await getToast(page, "Turn on key storage");
132133

133134
// And when we click "Continue"
134135
await toast.getByRole("button", { name: "Continue" }).click();
@@ -140,7 +141,7 @@ test.describe("'Turn on key storage' toast", () => {
140141
await page.getByRole("button", { name: "Close dialog" }).click();
141142

142143
// Then we see the toast again
143-
toast = await toasts.getToast("Turn on key storage");
144+
toast = await getToast(page, "Turn on key storage");
144145

145146
// And when we click "Dismiss"
146147
await toast.getByRole("button", { name: "Dismiss" }).click();
@@ -154,7 +155,7 @@ test.describe("'Turn on key storage' toast", () => {
154155
await page.getByTestId("dialog-background").click({ force: true, position: { x: 10, y: 10 } });
155156

156157
// Then we see the toast again
157-
toast = await toasts.getToast("Turn on key storage");
158+
toast = await getToast(page, "Turn on key storage");
158159

159160
// And when we click Dismiss and then "Go to Settings"
160161
await toast.getByRole("button", { name: "Dismiss" }).click();
@@ -165,12 +166,12 @@ test.describe("'Turn on key storage' toast", () => {
165166

166167
// And when we close that, see the toast, click Dismiss, and Yes, Dismiss
167168
await page.getByRole("button", { name: "Close dialog" }).click();
168-
toast = await toasts.getToast("Turn on key storage");
169+
toast = await getToast(page, "Turn on key storage");
169170
await toast.getByRole("button", { name: "Dismiss" }).click();
170171
await page.getByRole("button", { name: "Yes, dismiss" }).click();
171172

172173
// Then the toast is gone
173-
await toasts.assertNoToasts();
174+
await assertNoToasts(page);
174175
});
175176
});
176177

apps/web/playwright/e2e/crypto/user-verification.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Please see LICENSE files in the repository root for full details.
77
*/
88

99
import { type Preset, type Visibility } from "matrix-js-sdk/src/matrix";
10+
import { getToast } from "@element-hq/element-web-playwright-common";
1011

1112
import { test, expect } from "../../element-web-test";
1213
import { doTwoWaySasVerification, awaitVerifier, waitForDevices } from "./utils";
@@ -36,7 +37,6 @@ test.describe("User verification", () => {
3637
page,
3738
bot: bob,
3839
user: aliceCredentials,
39-
toasts,
4040
room: { roomId: dmRoomId },
4141
}) => {
4242
await waitForDevices(app, bob.credentials.userId, 1);
@@ -60,7 +60,7 @@ test.describe("User verification", () => {
6060
);
6161

6262
// there should also be a toast
63-
const toast = await toasts.getToast("Verification requested");
63+
const toast = await getToast(page, "Verification requested");
6464
// it should contain the details of the requesting user
6565
await expect(toast.getByText(`Bob (${bob.credentials.userId})`)).toBeVisible();
6666
// Accept
@@ -91,7 +91,6 @@ test.describe("User verification", () => {
9191
page,
9292
bot: bob,
9393
user: aliceCredentials,
94-
toasts,
9594
room: { roomId: dmRoomId },
9695
}) => {
9796
await waitForDevices(app, bob.credentials.userId, 1);
@@ -115,7 +114,7 @@ test.describe("User verification", () => {
115114
);
116115

117116
// Accept verification via toast
118-
const toast = await toasts.getToast("Verification requested");
117+
const toast = await getToast(page, "Verification requested");
119118
await toast.getByRole("button", { name: "Verify User" }).click();
120119

121120
// Wait for the QR code to be rendered. If we don't do this, then the QR code can be rendered just as

apps/web/playwright/e2e/room/room-status-bar.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
44
Please see LICENSE files in the repository root for full details.
55
*/
66

7+
import { getToast } from "@element-hq/element-web-playwright-common";
8+
79
import { test, expect } from "../../element-web-test";
810

911
test.describe("Room Status Bar", () => {
@@ -39,7 +41,7 @@ test.describe("Room Status Bar", () => {
3941
await expect(banner).toBeVisible({ timeout: 15000 });
4042
await expect(banner).toMatchScreenshot("connectivity_lost.png");
4143
});
42-
test("should NOT an error when a resource limit is hit", async ({ page, user, app, room, axe, toasts }) => {
44+
test("should NOT an error when a resource limit is hit", async ({ page, user, app, room, axe }) => {
4345
await app.viewRoomById(room.roomId);
4446
await page.route("**/_matrix/client/*/sync*", async (route, req) => {
4547
await route.fulfill({
@@ -55,7 +57,7 @@ test.describe("Room Status Bar", () => {
5557
});
5658
await app.client.sendMessage(room.roomId, "forcing sync to run");
5759
// Wait for the MAU warning toast to appear so we know this status bar would have appeared.
58-
await toasts.getToast("Warning", 15000);
60+
await getToast(page, "Warning", 15000);
5961
await expect(page.getByRole("region", { name: "Room status bar" })).not.toBeVisible();
6062
});
6163
test(

apps/web/playwright/e2e/toasts/analytics-toast.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9+
import { acceptToast, assertNoToasts, rejectToast } from "@element-hq/element-web-playwright-common";
10+
911
import { test } from "../../element-web-test";
1012

1113
test.describe("Analytics Toast", () => {
1214
test.use({
1315
displayName: "Tod",
1416
});
1517

16-
test("should not show an analytics toast if config has nothing about posthog", async ({ user, toasts }) => {
17-
await toasts.rejectToast("Verify this device");
18-
await toasts.rejectToast("Notifications");
19-
await toasts.assertNoToasts();
18+
test("should not show an analytics toast if config has nothing about posthog", async ({ user, page }) => {
19+
await rejectToast(page, "Verify this device");
20+
await rejectToast(page, "Notifications");
21+
await assertNoToasts(page);
2022
});
2123

2224
test.describe("with posthog enabled", () => {
@@ -29,19 +31,19 @@ test.describe("Analytics Toast", () => {
2931
},
3032
});
3133

32-
test.beforeEach(async ({ user, toasts }) => {
33-
await toasts.rejectToast("Verify this device");
34-
await toasts.rejectToast("Notifications");
34+
test.beforeEach(async ({ user, page }) => {
35+
await rejectToast(page, "Verify this device");
36+
await rejectToast(page, "Notifications");
3537
});
3638

37-
test("should show an analytics toast which can be accepted", async ({ user, toasts }) => {
38-
await toasts.acceptToast("Help improve Element");
39-
await toasts.assertNoToasts();
39+
test("should show an analytics toast which can be accepted", async ({ user, page }) => {
40+
await acceptToast(page, "Help improve Element");
41+
await assertNoToasts(page);
4042
});
4143

42-
test("should show an analytics toast which can be rejected", async ({ user, toasts }) => {
43-
await toasts.rejectToast("Help improve Element");
44-
await toasts.assertNoToasts();
44+
test("should show an analytics toast which can be rejected", async ({ user, page }) => {
45+
await rejectToast(page, "Help improve Element");
46+
await assertNoToasts(page);
4547
});
4648
});
4749
});

apps/web/playwright/e2e/voip/pstn.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
55
Please see LICENSE files in the repository root for full details.
66
*/
77

8+
import { assertNoToasts, rejectToast } from "@element-hq/element-web-playwright-common";
9+
810
import { test, expect } from "../../element-web-test";
911

1012
test.describe("PSTN", () => {
@@ -20,10 +22,10 @@ test.describe("PSTN", () => {
2022
});
2123
});
2224

23-
test("should render dialpad as expected", { tag: "@screenshot" }, async ({ page, user, toasts }) => {
24-
await toasts.rejectToast("Verify this device");
25-
await toasts.rejectToast("Notifications");
26-
await toasts.assertNoToasts();
25+
test("should render dialpad as expected", { tag: "@screenshot" }, async ({ page, user }) => {
26+
await rejectToast(page, "Verify this device");
27+
await rejectToast(page, "Notifications");
28+
await assertNoToasts(page);
2729

2830
await expect(page.getByTestId("room-list-search")).toMatchScreenshot("dialpad-trigger.png");
2931
await page.getByLabel("Open dial pad").click();

0 commit comments

Comments
 (0)