Skip to content

Commit 9153ca7

Browse files
committed
Playwright tests for the Turn on key storage toast
1 parent 20124be commit 9153ca7

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

playwright/e2e/crypto/toasts.spec.ts

Lines changed: 111 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,112 @@ 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+
await page.reload();
82+
83+
// Give the toasts time to appear
84+
await new Promise((resolve) => setTimeout(resolve, 2000));
85+
86+
// Then no toast is shown
87+
await toasts.assertNoToasts();
88+
});
89+
90+
test.only("should not show toast if key storage is off because we turned it off", async ({ app, page, toasts }) => {
91+
test.setTimeout(60000);
92+
93+
// Given the backup is disabled because we disabled it
94+
await disableKeyBackup(app);
95+
// Wait for the account data setting to stick
96+
await new Promise((resolve) => setTimeout(resolve, 2000));
97+
98+
TODO: it should not appear here!
99+
100+
// When we reload
101+
await page.reload();
102+
103+
// Give the toasts time to appear
104+
await new Promise((resolve) => setTimeout(resolve, 2000));
105+
106+
// Then still no toast is shown
107+
await toasts.assertNoToasts();
108+
});
109+
110+
test.only("should show toast if key storage is off but account data is missing", async ({ app, page, toasts }) => {
111+
// Given the backup is disabled but we didn't set account data saying that is expected
112+
await disableKeyBackup(app);
113+
await botClient.setAccountData("m.org.matrix.custom.backup_disabled", { disabled: false });
114+
// Wait for the account data setting to stick
115+
await new Promise((resolve) => setTimeout(resolve, 2000));
116+
117+
// When we enter the app
118+
await page.reload();
119+
120+
// Then the toast is displayed
121+
let toast = await toasts.getToast("Turn on key storage");
122+
123+
// And when we click "Continue"
124+
await toast.getByRole("button", { name: "Continue" }).click();
125+
126+
// Then we see the Encryption settings dialog with an option to turn on key storage
127+
await expect(page.getByRole("checkbox", { name: "Allow key storage" })).toBeVisible();
128+
129+
// And when we close that
130+
await page.getByRole("button", { name: "Close dialog" }).click();
131+
132+
// Then we see the toast again
133+
toast = await toasts.getToast("Turn on key storage");
134+
135+
// And when we click "Dismiss"
136+
await toast.getByRole("button", { name: "Dismiss" }).click();
137+
138+
// Then we see the "are you sure?" dialog
139+
await expect(
140+
page.getByRole("heading", { name: "Are you sure you want to keep key storage turned off?" }),
141+
).toBeVisible();
142+
143+
// And when we close it by clicking away
144+
await page.getByTestId("dialog-background").click({ force: true, position: { x: 10, y: 10 } });
145+
146+
// Then we see the toast again
147+
toast = await toasts.getToast("Turn on key storage");
148+
149+
// And when we click Dismiss and then "Go to Settings"
150+
await toast.getByRole("button", { name: "Dismiss" }).click();
151+
await page.getByRole("button", { name: "Go to Settings" }).click();
152+
153+
// Then we see Encryption settings again
154+
await expect(page.getByRole("checkbox", { name: "Allow key storage" })).toBeVisible();
155+
156+
// And when we close that, see the toast, click Dismiss, and Yes, Dismiss
157+
await page.getByRole("button", { name: "Close dialog" }).click();
158+
toast = await toasts.getToast("Turn on key storage");
159+
await toast.getByRole("button", { name: "Dismiss" }).click();
160+
await page.getByRole("button", { name: "Yes, dismiss" }).click();
161+
162+
// Then the toast is gone
163+
await toasts.assertNoToasts();
164+
});
165+
});

playwright/e2e/crypto/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,22 @@ 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+
await app.settings.closeDialog();
333+
}
334+
319335
/**
320336
* Go through the "Set up Secure Backup" dialog (aka the `CreateSecretStorageDialog`).
321337
*

0 commit comments

Comments
 (0)