Rename CreateCrossSigningDialog to InitialCryptoSetupDialog (#28658)
* Rename CreateCrossSigningDialog to InitialCryptoSetup because it will soon encompass things other than just creating cross signing. * Fix name & tests * Fix import * Remove code creating key backup Because this was split out from my key backup by default PR * Fix comment * Convert to named export
This commit is contained in:
parent
9cc5564d50
commit
c659afa8db
3 changed files with 23 additions and 19 deletions
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2018-2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { render, screen, waitFor } from "jest-matrix-react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { createCrossSigning } from "../../../../../src/CreateCrossSigning";
|
||||
import { InitialCryptoSetupDialog } from "../../../../../src/components/views/dialogs/security/InitialCryptoSetupDialog";
|
||||
import { createTestClient } from "../../../../test-utils";
|
||||
|
||||
jest.mock("../../../../../src/CreateCrossSigning", () => ({
|
||||
createCrossSigning: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("InitialCryptoSetupDialog", () => {
|
||||
let client: MatrixClient;
|
||||
let createCrossSigningResolve: () => void;
|
||||
let createCrossSigningReject: (e: Error) => void;
|
||||
|
||||
beforeEach(() => {
|
||||
client = createTestClient();
|
||||
mocked(createCrossSigning).mockImplementation(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
createCrossSigningResolve = resolve;
|
||||
createCrossSigningReject = reject;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("should call createCrossSigning and show a spinner while it runs", async () => {
|
||||
const onFinished = jest.fn();
|
||||
|
||||
render(
|
||||
<InitialCryptoSetupDialog
|
||||
matrixClient={client}
|
||||
accountPassword="hunter2"
|
||||
tokenLogin={false}
|
||||
onFinished={onFinished}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(createCrossSigning).toHaveBeenCalledWith(client, false, "hunter2");
|
||||
expect(screen.getByTestId("spinner")).toBeInTheDocument();
|
||||
|
||||
createCrossSigningResolve!();
|
||||
|
||||
await waitFor(() => expect(onFinished).toHaveBeenCalledWith(true));
|
||||
});
|
||||
|
||||
it("should display an error if createCrossSigning fails", async () => {
|
||||
render(
|
||||
<InitialCryptoSetupDialog
|
||||
matrixClient={client}
|
||||
accountPassword="hunter2"
|
||||
tokenLogin={false}
|
||||
onFinished={jest.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
createCrossSigningReject!(new Error("generic error message"));
|
||||
|
||||
await expect(await screen.findByRole("button", { name: "Retry" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("ignores failures when tokenLogin is true", async () => {
|
||||
const onFinished = jest.fn();
|
||||
|
||||
render(
|
||||
<InitialCryptoSetupDialog
|
||||
matrixClient={client}
|
||||
accountPassword="hunter2"
|
||||
tokenLogin={true}
|
||||
onFinished={onFinished}
|
||||
/>,
|
||||
);
|
||||
|
||||
createCrossSigningReject!(new Error("generic error message"));
|
||||
|
||||
await waitFor(() => expect(onFinished).toHaveBeenCalledWith(false));
|
||||
});
|
||||
|
||||
it("cancels the dialog when the cancel button is clicked", async () => {
|
||||
const onFinished = jest.fn();
|
||||
|
||||
render(
|
||||
<InitialCryptoSetupDialog
|
||||
matrixClient={client}
|
||||
accountPassword="hunter2"
|
||||
tokenLogin={false}
|
||||
onFinished={onFinished}
|
||||
/>,
|
||||
);
|
||||
|
||||
createCrossSigningReject!(new Error("generic error message"));
|
||||
|
||||
const cancelButton = await screen.findByRole("button", { name: "Cancel" });
|
||||
cancelButton.click();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it("should retry when the retry button is clicked", async () => {
|
||||
render(
|
||||
<InitialCryptoSetupDialog
|
||||
matrixClient={client}
|
||||
accountPassword="hunter2"
|
||||
tokenLogin={false}
|
||||
onFinished={jest.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
createCrossSigningReject!(new Error("generic error message"));
|
||||
|
||||
const retryButton = await screen.findByRole("button", { name: "Retry" });
|
||||
retryButton.click();
|
||||
|
||||
expect(createCrossSigning).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue