From 2e2ff4b3641d474873d542676cf54b8f5da3236d Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 16 Jan 2025 16:34:23 +0100 Subject: [PATCH] Add tests to `ResetIdentityPanel` --- test/test-utils/test-utils.ts | 1 + .../encryption/ResetIdentityPanel-test.tsx | 37 ++++ .../ResetIdentityPanel-test.tsx.snap | 184 ++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 test/unit-tests/components/views/settings/encryption/ResetIdentityPanel-test.tsx create mode 100644 test/unit-tests/components/views/settings/encryption/__snapshots__/ResetIdentityPanel-test.tsx.snap diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 3be82e3ee86..b474a24aa81 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -151,6 +151,7 @@ export function createTestClient(): MatrixClient { }, }), isCrossSigningReady: jest.fn().mockResolvedValue(false), + resetEncryption: jest.fn(), }), getPushActionsForEvent: jest.fn(), diff --git a/test/unit-tests/components/views/settings/encryption/ResetIdentityPanel-test.tsx b/test/unit-tests/components/views/settings/encryption/ResetIdentityPanel-test.tsx new file mode 100644 index 00000000000..dc791a6a35c --- /dev/null +++ b/test/unit-tests/components/views/settings/encryption/ResetIdentityPanel-test.tsx @@ -0,0 +1,37 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +import React from "react"; +import { MatrixClient } from "matrix-js-sdk/src/matrix"; +import { render, screen } from "jest-matrix-react"; +import userEvent from "@testing-library/user-event"; + +import { ResetIdentityPanel } from "../../../../../../src/components/views/settings/encryption/ResetIdentityPanel"; +import { createTestClient, withClientContextRenderOptions } from "../../../../../test-utils"; + +describe("", () => { + let matrixClient: MatrixClient; + + beforeEach(() => { + matrixClient = createTestClient(); + }); + + it("should reset the encryption when the continue button is clicked", async () => { + const user = userEvent.setup(); + + const onFinish = jest.fn(); + const { asFragment } = render( + , + withClientContextRenderOptions(matrixClient), + ); + expect(asFragment()).toMatchSnapshot(); + + await user.click(screen.getByRole("button", { name: "Continue" })); + expect(matrixClient.getCrypto()!.resetEncryption).toHaveBeenCalled(); + expect(onFinish).toHaveBeenCalled(); + }); +}); diff --git a/test/unit-tests/components/views/settings/encryption/__snapshots__/ResetIdentityPanel-test.tsx.snap b/test/unit-tests/components/views/settings/encryption/__snapshots__/ResetIdentityPanel-test.tsx.snap new file mode 100644 index 00000000000..7635ad06121 --- /dev/null +++ b/test/unit-tests/components/views/settings/encryption/__snapshots__/ResetIdentityPanel-test.tsx.snap @@ -0,0 +1,184 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should reset the encryption when the continue button is clicked 1`] = ` + + +
+
+
+ + + +
+

+ Are you sure you want to reset your identity? +

+
+
+
    +
  • + + Your account details, contacts, preferences, and chat list will be kept +
  • +
  • + + You will lose any message history that’s stored only on the server +
  • +
  • + + You will need to verify all your existing devices and contacts again +
  • +
+ + Only do this if you believe your account has been compromised. + +
+ +
+
+`;