Update key storage toggle when key storage status changes (#30934)
* update key storage toggle when key storage status changes Listen for the CryptoEvent.KeyBackupStatus event and update the state when it changes. * fixup! update key storage toggle when key storage status changes * add comment about handling event
This commit is contained in:
@@ -5,9 +5,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { renderHook } from "jest-matrix-react";
|
||||
import { renderHook, waitFor } from "jest-matrix-react";
|
||||
import { act } from "react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto-api";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import type { BackupTrustInfo, KeyBackupCheck, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api";
|
||||
@@ -37,6 +38,23 @@ describe("KeyStoragePanelViewModel", () => {
|
||||
expect(result.current.busy).toBe(true);
|
||||
});
|
||||
|
||||
it("should update if a KeyBackupStatus event is received", async () => {
|
||||
const { result } = renderHook(
|
||||
() => useKeyStoragePanelViewModel(),
|
||||
withClientContextRenderOptions(matrixClient),
|
||||
);
|
||||
await waitFor(() => expect(result.current.isEnabled).toBe(false));
|
||||
|
||||
const mock = mocked(matrixClient.getCrypto()!.getActiveSessionBackupVersion);
|
||||
mock.mockResolvedValue("1");
|
||||
matrixClient.emit(CryptoEvent.KeyBackupStatus, true);
|
||||
await waitFor(() => expect(result.current.isEnabled).toBe(true));
|
||||
|
||||
mock.mockResolvedValue(null);
|
||||
matrixClient.emit(CryptoEvent.KeyBackupStatus, false);
|
||||
await waitFor(() => expect(result.current.isEnabled).toBe(false));
|
||||
});
|
||||
|
||||
it("should call resetKeyBackup if there is no backup currently", async () => {
|
||||
mocked(matrixClient.getCrypto()!.checkKeyBackupAndEnable).mockResolvedValue(null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user