Test updating

This commit is contained in:
David Baker 2025-02-06 15:16:03 +01:00
parent 4a3a37323e
commit e70afdb04f
2 changed files with 24 additions and 1 deletions

View File

@ -82,6 +82,7 @@ const useKeyBackupIsEnabled = (): boolean | undefined => {
useEventEmitter(matrixClient, ClientEvent.AccountData, (event: MatrixEvent): void => {
const type = event.getType();
// Recheck the status if this account data has been updated as this implies it has changed
if (type === "m.org.matrix.custom.backup_disabled") {
checkStatus();
}

View File

@ -6,10 +6,11 @@
*/
import React from "react";
import { render, screen } from "jest-matrix-react";
import { act, render, screen } from "jest-matrix-react";
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import { waitFor } from "@testing-library/dom";
import userEvent from "@testing-library/user-event";
import { ClientEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
import type { KeyBackupInfo } from "matrix-js-sdk/src/crypto-api";
import {
@ -170,4 +171,25 @@ describe("<EncryptionUserSettingsTab />", () => {
}),
).toBeVisible();
});
it("should update when backup_disabled account data is changed", async () => {
jest.spyOn(matrixClient.getCrypto()!, "getKeyBackupInfo").mockResolvedValue({
version: "1",
} as KeyBackupInfo);
renderComponent();
await expect(await screen.findByRole("heading", { name: "Recovery" })).toBeVisible();
jest.spyOn(matrixClient.getCrypto()!, "getKeyBackupInfo").mockResolvedValue(null);
act(() => {
const accountDataEvent = new MatrixEvent({ type: "m.org.matrix.custom.backup_disabled" });
matrixClient.emit(ClientEvent.AccountData, accountDataEvent);
});
await waitFor(() => {
expect(screen.queryByRole("heading", { name: "Recovery" })).toBeNull();
});
});
});