diff --git a/src/components/views/settings/encryption/AdvancedPanel.tsx b/src/components/views/settings/encryption/AdvancedPanel.tsx index 214164ec91..6bbc48dbcb 100644 --- a/src/components/views/settings/encryption/AdvancedPanel.tsx +++ b/src/components/views/settings/encryption/AdvancedPanel.tsx @@ -61,18 +61,20 @@ function EncryptionDetails({ onResetIdentityClick }: EncryptionDetails): JSX.Ele ); return ( -
+

{_t("settings|encryption|advanced|details_title")}

{_t("settings|encryption|advanced|session_id")} - {matrixClient.deviceId} + {matrixClient.deviceId}
{_t("settings|encryption|advanced|session_key")} - {keys ? keys.ed25519 : } + + {keys ? keys.ed25519 : } +
@@ -124,7 +126,7 @@ function OtherSettings(): JSX.Element | null { return ( { const checked = new FormData(evt.currentTarget).get("neverSendEncrypted") === "on"; diff --git a/test/unit-tests/components/views/settings/encryption/AdvancedPanel-test.tsx b/test/unit-tests/components/views/settings/encryption/AdvancedPanel-test.tsx new file mode 100644 index 0000000000..2ec51b5363 --- /dev/null +++ b/test/unit-tests/components/views/settings/encryption/AdvancedPanel-test.tsx @@ -0,0 +1,99 @@ +/* + * 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, waitFor } from "jest-matrix-react"; +import userEvent from "@testing-library/user-event"; + +import { createTestClient, withClientContextRenderOptions } from "../../../../../test-utils"; +import { AdvancedPanel } from "../../../../../../src/components/views/settings/encryption/AdvancedPanel"; +import SettingsStore from "../../../../../../src/settings/SettingsStore"; +import { SettingLevel } from "../../../../../../src/settings/SettingLevel"; + +describe("", () => { + let matrixClient: MatrixClient; + + beforeEach(() => { + matrixClient = createTestClient(); + }); + + async function renderAdvancedPanel(onResetIdentityClick = jest.fn()) { + const renderResult = render( + , + withClientContextRenderOptions(matrixClient), + ); + // Wait for the device keys to be displayed + await waitFor(() => expect(screen.getByText("ed25519")).toBeInTheDocument()); + return renderResult; + } + + describe("", () => { + it("should display a spinner when loading the device keys", async () => { + jest.spyOn(matrixClient.getCrypto()!, "getOwnDeviceKeys").mockImplementation(() => new Promise(() => {})); + render(, withClientContextRenderOptions(matrixClient)); + + expect(screen.getByTestId("encryptionDetails")).toMatchSnapshot(); + }); + + it("should display the device keys", async () => { + await renderAdvancedPanel(); + + // session id + expect(screen.getByText("ABCDEFGHI")).toBeInTheDocument(); + // session key + expect(screen.getByText("ed25519")).toBeInTheDocument(); + expect(screen.getByTestId("encryptionDetails")).toMatchSnapshot(); + }); + + it("should call the onResetIdentityClick callback when the reset cryptographic identity button is clicked", async () => { + const user = userEvent.setup(); + + const onResetIdentityClick = jest.fn(); + await renderAdvancedPanel(onResetIdentityClick); + + const resetIdentityButton = screen.getByRole("button", { name: "Reset cryptographic identity" }); + await user.click(resetIdentityButton); + + expect(onResetIdentityClick).toHaveBeenCalled(); + }); + }); + + describe("", () => { + it("should display the blacklist of unverified devices settings", async () => { + const user = userEvent.setup(); + + jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(true); + jest.spyOn(SettingsStore, "canSetValue").mockReturnValue(true); + jest.spyOn(SettingsStore, "setValue"); + + await renderAdvancedPanel(); + + expect(screen.getByTestId("otherSettings")).toMatchSnapshot(); + const checkbox = screen.getByRole("checkbox", { + name: "Never send encrypted messages to unverified devices", + }); + expect(checkbox).toBeChecked(); + + await user.click(checkbox); + expect(SettingsStore.setValue).toHaveBeenCalledWith( + "blacklistUnverifiedDevices", + null, + SettingLevel.DEVICE, + false, + ); + }); + + it("should not display the section when the user can not set the value", async () => { + jest.spyOn(SettingsStore, "canSetValue").mockReturnValue(false); + jest.spyOn(SettingsStore, "setValue"); + + await renderAdvancedPanel(); + expect(screen.queryByTestId("otherSettings")).toBeNull(); + }); + }); +}); diff --git a/test/unit-tests/components/views/settings/encryption/__snapshots__/AdvancedPanel-test.tsx.snap b/test/unit-tests/components/views/settings/encryption/__snapshots__/AdvancedPanel-test.tsx.snap new file mode 100644 index 0000000000..227e37e033 --- /dev/null +++ b/test/unit-tests/components/views/settings/encryption/__snapshots__/AdvancedPanel-test.tsx.snap @@ -0,0 +1,253 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should display a spinner when loading the device keys 1`] = ` +
+
+

+ Encryption details +

+
+ + Session ID: + + + ABCDEFGHI + +
+
+ + Session key: + + + + + + +
+
+
+ + +
+ +
+`; + +exports[` should display the device keys 1`] = ` +
+
+

+ Encryption details +

+
+ + Session ID: + + + ABCDEFGHI + +
+
+ + Session key: + + + ed25519 + +
+
+
+ + +
+ +
+`; + +exports[` should display the blacklist of unverified devices settings 1`] = ` +
+

+ Other people’s devices +

+
+
+
+ +
+
+
+
+ + + By default in encrypted rooms, do not send encrypted messages to anyone until you’ve verified them + +
+
+ +`;