Skip to content

Commit f7b5dd7

Browse files
committed
Playwright tests for the Turn on key storage toast
1 parent fa5ea5f commit f7b5dd7

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

playwright/e2e/crypto/toasts.spec.ts

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import { type GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
99

1010
import { test, expect } from "../../element-web-test";
11-
import { createBot, deleteCachedSecrets, logIntoElement } from "./utils";
11+
import { createBot, deleteCachedSecrets, disableKeyBackup, logIntoElement } from "./utils";
12+
import { type Bot } from "../../pages/bot";
1213

1314
test.describe("Key storage out of sync toast", () => {
1415
let recoveryKey: GeneratedSecretStorageKey;
@@ -53,3 +54,114 @@ test.describe("Key storage out of sync toast", () => {
5354
).toBeVisible();
5455
});
5556
});
57+
58+
test.describe("Turn on key storage toast", () => {
59+
let botClient: Bot | undefined;
60+
61+
test.beforeEach(async ({ page, homeserver, credentials, toasts }) => {
62+
// Set up all crypto stuff. Key storage defaults to on.
63+
64+
const res = await createBot(page, homeserver, credentials);
65+
const recoveryKey = res.recoveryKey;
66+
botClient = res.botClient;
67+
68+
await logIntoElement(page, credentials, recoveryKey.encodedPrivateKey);
69+
70+
// We won't be prompted for crypto setup unless we have an e2e room, so make one
71+
await page.getByRole("button", { name: "Add room" }).click();
72+
await page.getByRole("menuitem", { name: "New room" }).click();
73+
await page.getByRole("textbox", { name: "Name" }).fill("Test room");
74+
await page.getByRole("button", { name: "Create room" }).click();
75+
76+
await toasts.rejectToast("Notifications");
77+
});
78+
79+
test.only("should not show toast if key storage is on", async ({ page, toasts }) => {
80+
// Given the default situation after signing in
81+
// Then no toast is shown (because key storage is on)
82+
await toasts.assertNoToasts();
83+
84+
// When we reload
85+
await page.reload();
86+
87+
// Give the toasts time to appear
88+
await new Promise((resolve) => setTimeout(resolve, 2000));
89+
90+
// Then still no toast is shown
91+
await toasts.assertNoToasts();
92+
});
93+
94+
test.only("should not show toast if key storage is off because we turned it off", async ({ app, page, toasts }) => {
95+
// Given the backup is disabled because we disabled it
96+
await disableKeyBackup(app);
97+
98+
// Then no toast is shown
99+
await toasts.assertNoToasts();
100+
101+
// When we reload
102+
await page.reload();
103+
104+
// Give the toasts time to appear
105+
await new Promise((resolve) => setTimeout(resolve, 2000));
106+
107+
// Then still no toast is shown
108+
await toasts.assertNoToasts();
109+
});
110+
111+
test.only("should show toast if key storage is off but account data is missing", async ({ app, page, toasts }) => {
112+
// Given the backup is disabled but we didn't set account data saying that is expected
113+
await disableKeyBackup(app);
114+
await botClient.setAccountData("m.org.matrix.custom.backup_disabled", { disabled: false });
115+
116+
// Wait for the account data setting to stick
117+
await new Promise((resolve) => setTimeout(resolve, 2000));
118+
119+
// When we enter the app
120+
await page.reload();
121+
122+
// Then the toast is displayed
123+
let toast = await toasts.getToast("Turn on key storage");
124+
125+
// And when we click "Continue"
126+
await toast.getByRole("button", { name: "Continue" }).click();
127+
128+
// Then we see the Encryption settings dialog with an option to turn on key storage
129+
await expect(page.getByRole("checkbox", { name: "Allow key storage" })).toBeVisible();
130+
131+
// And when we close that
132+
await page.getByRole("button", { name: "Close dialog" }).click();
133+
134+
// Then we see the toast again
135+
toast = await toasts.getToast("Turn on key storage");
136+
137+
// And when we click "Dismiss"
138+
await toast.getByRole("button", { name: "Dismiss" }).click();
139+
140+
// Then we see the "are you sure?" dialog
141+
await expect(
142+
page.getByRole("heading", { name: "Are you sure you want to keep key storage turned off?" }),
143+
).toBeVisible();
144+
145+
// And when we close it by clicking away
146+
await page.getByTestId("dialog-background").click({ force: true, position: { x: 10, y: 10 } });
147+
148+
// Then we see the toast again
149+
toast = await toasts.getToast("Turn on key storage");
150+
151+
// And when we click Dismiss and then "Go to Settings"
152+
await toast.getByRole("button", { name: "Dismiss" }).click();
153+
await page.getByRole("button", { name: "Go to Settings" }).click();
154+
155+
// Then we see Encryption settings again
156+
await expect(page.getByRole("checkbox", { name: "Allow key storage" })).toBeVisible();
157+
158+
// And when we close that, see the toast, click Dismiss, and Yes, Dismiss
159+
await page.getByRole("button", { name: "Close dialog" }).click();
160+
toast = await toasts.getToast("Turn on key storage");
161+
await toast.getByRole("button", { name: "Dismiss" }).click();
162+
await page.getByRole("button", { name: "Yes, dismiss" }).click();
163+
164+
// Then the toast is gone
165+
await toasts.assertNoToasts();
166+
});
167+
});

playwright/e2e/crypto/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,25 @@ export async function enableKeyBackup(app: ElementAppPage): Promise<string> {
316316
return recoveryKey;
317317
}
318318

319+
/**
320+
* Open the encryption settings and disable key storage (and recovery)
321+
* Assumes that the current device has been verified
322+
*/
323+
export async function disableKeyBackup(app: ElementAppPage): Promise<void> {
324+
const encryptionTab = await app.settings.openUserSettings("Encryption");
325+
326+
const keyStorageToggle = encryptionTab.getByRole("checkbox", { name: "Allow key storage" });
327+
if (await keyStorageToggle.isChecked()) {
328+
await encryptionTab.getByRole("checkbox", { name: "Allow key storage" }).click();
329+
await encryptionTab.getByRole("button", { name: "Delete key storage" }).click();
330+
await encryptionTab.getByRole("checkbox", { name: "Allow key storage" }).isVisible();
331+
332+
// Wait for the update to account data to stick
333+
await new Promise((resolve) => setTimeout(resolve, 2000));
334+
}
335+
await app.settings.closeDialog();
336+
}
337+
319338
/**
320339
* Go through the "Set up Secure Backup" dialog (aka the `CreateSecretStorageDialog`).
321340
*

0 commit comments

Comments
 (0)