|
8 | 8 | import { type GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
|
9 | 9 |
|
10 | 10 | 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"; |
12 | 13 |
|
13 | 14 | test.describe("Key storage out of sync toast", () => {
|
14 | 15 | let recoveryKey: GeneratedSecretStorageKey;
|
@@ -53,3 +54,114 @@ test.describe("Key storage out of sync toast", () => {
|
53 | 54 | ).toBeVisible();
|
54 | 55 | });
|
55 | 56 | });
|
| 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 | +}); |
0 commit comments