From a02d1f20ff1e92758023ccb78ecd3b101f4bde77 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 17 Oct 2024 17:32:59 +0200 Subject: [PATCH] Add test to `MatrixChat` --- .../components/structures/MatrixChat-test.tsx | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/unit-tests/components/structures/MatrixChat-test.tsx b/test/unit-tests/components/structures/MatrixChat-test.tsx index 4b10043ad2e..da6e005a23d 100644 --- a/test/unit-tests/components/structures/MatrixChat-test.tsx +++ b/test/unit-tests/components/structures/MatrixChat-test.tsx @@ -22,7 +22,7 @@ import { logger } from "matrix-js-sdk/src/logger"; import { OidcError } from "matrix-js-sdk/src/oidc/error"; import { BearerTokenResponse } from "matrix-js-sdk/src/oidc/validate"; import { defer, IDeferred, sleep } from "matrix-js-sdk/src/utils"; -import { UserVerificationStatus } from "matrix-js-sdk/src/crypto-api"; +import { CryptoEvent, UserVerificationStatus } from "matrix-js-sdk/src/crypto-api"; import MatrixChat from "../../../../src/components/structures/MatrixChat"; import * as StorageAccess from "../../../../src/utils/StorageAccess"; @@ -135,6 +135,7 @@ describe("", () => { getVersion: jest.fn().mockReturnValue("1"), setDeviceIsolationMode: jest.fn(), userHasCrossSigningKeys: jest.fn(), + getActiveSessionBackupVersion: jest.fn().mockResolvedValue(null), }), // This needs to not finish immediately because we need to test the screen appears bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise), @@ -1515,4 +1516,22 @@ describe("", () => { expect(screen.getByTestId("mobile-register")).toBeInTheDocument(); }); }); + + describe("when key backup failed", () => { + it("should show the new recovery method dialog", async () => { + jest.mock("../../../../src/async-components/views/dialogs/security/NewRecoveryMethodDialog", () => ({ + __esModule: true, + default: () => mocked dialog, + })); + jest.spyOn(mockClient.getCrypto()!, "getActiveSessionBackupVersion").mockResolvedValue("version"); + + getComponent({}); + defaultDispatcher.dispatch({ + action: "will_start_client", + }); + await flushPromises(); + mockClient.emit(CryptoEvent.KeyBackupFailed, "error code"); + await waitFor(() => expect(screen.getByText("mocked dialog")).toBeInTheDocument()); + }); + }); });