Skip to content

Commit bccb180

Browse files
committed
add tests
1 parent ff53fc1 commit bccb180

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/unit-tests/toasts/SetupEncryptionToast-test.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import dis from "../../../src/dispatcher/dispatcher";
2020
import DeviceListener, { DeviceState } from "../../../src/DeviceListener";
2121
import Modal from "../../../src/Modal";
2222
import ConfirmKeyStorageOffDialog from "../../../src/components/views/dialogs/ConfirmKeyStorageOffDialog";
23+
import SetupEncryptionDialog from "../../../src/components/views/dialogs/security/SetupEncryptionDialog";
2324
import { stubClient } from "../../test-utils";
2425

2526
jest.mock("../../../src/dispatcher/dispatcher", () => ({
@@ -240,4 +241,65 @@ describe("SetupEncryptionToast", () => {
240241
expect(DeviceListener.sharedInstance().recordKeyBackupDisabled).toHaveBeenCalledTimes(1);
241242
});
242243
});
244+
245+
describe("Verify this session", () => {
246+
it("should render the toast", async () => {
247+
act(() => showToast(DeviceState.VERIFY_THIS_SESSION));
248+
249+
await expect(screen.findByText("Verify this session")).resolves.toBeInTheDocument();
250+
await expect(screen.findByRole("button", { name: "Later" })).resolves.toBeInTheDocument();
251+
await expect(screen.findByRole("button", { name: "Verify" })).resolves.toBeInTheDocument();
252+
});
253+
254+
it("should dismiss the toast when 'Later' button clicked, and remember it", async () => {
255+
jest.spyOn(DeviceListener.sharedInstance(), "dismissEncryptionSetup");
256+
257+
act(() => showToast(DeviceState.VERIFY_THIS_SESSION));
258+
259+
const user = userEvent.setup();
260+
await user.click(await screen.findByRole("button", { name: "Later" }));
261+
262+
expect(DeviceListener.sharedInstance().dismissEncryptionSetup).toHaveBeenCalled();
263+
});
264+
265+
it("should open the verification dialog when 'Verify' clicked", async () => {
266+
jest.spyOn(Modal, "createDialog");
267+
268+
// When we show the toast, and click Verify
269+
act(() => showToast(DeviceState.VERIFY_THIS_SESSION));
270+
271+
const user = userEvent.setup();
272+
await user.click(await screen.findByRole("button", { name: "Verify" }));
273+
274+
// Then the dialog was opened
275+
expect(Modal.createDialog).toHaveBeenCalledWith(SetupEncryptionDialog, {}, undefined, false, true);
276+
});
277+
});
278+
279+
describe("Identity needs reset", () => {
280+
it("should render the toast", async () => {
281+
act(() => showToast(DeviceState.IDENTITY_NEEDS_RESET));
282+
283+
await expect(screen.findByText("Your key storage is out of sync.")).resolves.toBeInTheDocument();
284+
await expect(
285+
screen.findByText(
286+
"You have to reset your cryptographic identity in order to ensure access to your message history",
287+
),
288+
).resolves.toBeInTheDocument();
289+
await expect(screen.findByRole("button", { name: "Continue with reset" })).resolves.toBeInTheDocument();
290+
});
291+
292+
it("should open settings to the reset flow when 'Continue with reset' clicked", async () => {
293+
act(() => showToast(DeviceState.IDENTITY_NEEDS_RESET));
294+
295+
const user = userEvent.setup();
296+
await user.click(await screen.findByText("Continue with reset"));
297+
298+
expect(dis.dispatch).toHaveBeenCalledWith({
299+
action: "view_user_settings",
300+
initialTabId: "USER_ENCRYPTION_TAB",
301+
props: { initialEncryptionState: "reset_identity_cant_recover" },
302+
});
303+
});
304+
});
243305
});

0 commit comments

Comments
 (0)