From 2ac2bae4fa703640ace5c1c165f0ed666edbb234 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Tue, 26 Nov 2024 10:43:21 +0100 Subject: [PATCH] Add spinner when room encryption is loading in room settings (#28535) --- .../tabs/room/SecurityRoomSettingsTab.tsx | 31 ++++++++++++------- .../room/SecurityRoomSettingsTab-test.tsx | 10 +++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index 1ade503bb2..7d9f75f828 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -17,6 +17,7 @@ import { EventType, } from "matrix-js-sdk/src/matrix"; import { logger } from "matrix-js-sdk/src/logger"; +import { InlineSpinner } from "@vector-im/compound-web"; import { Icon as WarningIcon } from "../../../../../../res/img/warning.svg"; import { _t } from "../../../../../languageHandler"; @@ -53,7 +54,7 @@ interface IState { guestAccess: GuestAccess; history: HistoryVisibility; hasAliases: boolean; - encrypted: boolean; + encrypted: boolean | null; showAdvancedSection: boolean; } @@ -78,7 +79,7 @@ export default class SecurityRoomSettingsTab extends React.Component - - {isEncryptionForceDisabled && !isEncrypted && ( - {_t("room_settings|security|encryption_forced")} + {isEncryptionLoading ? ( + + ) : ( + <> + + {isEncryptionForceDisabled && !isEncrypted && ( + {_t("room_settings|security|encryption_forced")} + )} + {encryptionSettings} + )} - {encryptionSettings} - {this.renderJoinRule()} {historySection} diff --git a/test/unit-tests/components/views/settings/tabs/room/SecurityRoomSettingsTab-test.tsx b/test/unit-tests/components/views/settings/tabs/room/SecurityRoomSettingsTab-test.tsx index 6534a34004..5fc10714e6 100644 --- a/test/unit-tests/components/views/settings/tabs/room/SecurityRoomSettingsTab-test.tsx +++ b/test/unit-tests/components/views/settings/tabs/room/SecurityRoomSettingsTab-test.tsx @@ -75,7 +75,7 @@ describe("", () => { beforeEach(async () => { client.sendStateEvent.mockReset().mockResolvedValue({ event_id: "test" }); - client.isRoomEncrypted.mockReturnValue(false); + jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(false); client.getClientWellKnown.mockReturnValue(undefined); jest.spyOn(SettingsStore, "getValue").mockRestore(); @@ -313,7 +313,7 @@ describe("", () => { setRoomStateEvents(room); getComponent(room); - expect(screen.getByLabelText("Encrypted")).not.toBeChecked(); + await waitFor(() => expect(screen.getByLabelText("Encrypted")).not.toBeChecked()); fireEvent.click(screen.getByLabelText("Encrypted")); @@ -330,7 +330,7 @@ describe("", () => { setRoomStateEvents(room); getComponent(room); - expect(screen.getByLabelText("Encrypted")).not.toBeChecked(); + await waitFor(() => expect(screen.getByLabelText("Encrypted")).not.toBeChecked()); fireEvent.click(screen.getByLabelText("Encrypted")); @@ -416,12 +416,12 @@ describe("", () => { expect(screen.getByText("Once enabled, encryption cannot be disabled.")).toBeInTheDocument(); }); - it("displays unencrypted rooms with toggle disabled", () => { + it("displays unencrypted rooms with toggle disabled", async () => { const room = new Room(roomId, client, userId); setRoomStateEvents(room); getComponent(room); - expect(screen.getByLabelText("Encrypted")).not.toBeChecked(); + await waitFor(() => expect(screen.getByLabelText("Encrypted")).not.toBeChecked()); expect(screen.getByLabelText("Encrypted").getAttribute("aria-disabled")).toEqual("true"); expect(screen.queryByText("Once enabled, encryption cannot be disabled.")).not.toBeInTheDocument(); expect(screen.getByText("Your server requires encryption to be disabled.")).toBeInTheDocument();