mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 01:05:42 +03:00
d8800ef987
* Upgrade target to es2021 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Upgrade target to es2021 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Upgrade to es2022 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Upgrade to es2022 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix babel config Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix babel config Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix React contexts Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix types Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix React state Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update to React 18 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update to React 18 Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Install @testing-library/dom Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update lockfile Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Yarn lock update * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
/*
|
|
* Copyright 2024 New Vector Ltd.
|
|
*
|
|
* 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 { MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
import { render, screen, act } from "jest-matrix-react";
|
|
import { waitFor } from "@testing-library/dom";
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
import NewRecoveryMethodDialog from "../../../../../src/async-components/views/dialogs/security/NewRecoveryMethodDialog";
|
|
import { createTestClient } from "../../../../test-utils";
|
|
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext.tsx";
|
|
import dis from "../../../../../src/dispatcher/dispatcher.ts";
|
|
import { Action } from "../../../../../src/dispatcher/actions.ts";
|
|
import Modal from "../../../../../src/Modal.tsx";
|
|
|
|
describe("<NewRecoveryMethodDialog />", () => {
|
|
let matrixClient: MatrixClient;
|
|
beforeEach(() => {
|
|
matrixClient = createTestClient();
|
|
jest.spyOn(dis, "fire");
|
|
jest.spyOn(Modal, "createDialog");
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
function renderComponent(onFinished: () => void = jest.fn()) {
|
|
return render(
|
|
<MatrixClientContext.Provider value={matrixClient}>
|
|
<NewRecoveryMethodDialog onFinished={onFinished} />
|
|
</MatrixClientContext.Provider>,
|
|
);
|
|
}
|
|
|
|
test("when cancel is clicked", async () => {
|
|
const onFinished = jest.fn();
|
|
act(() => {
|
|
renderComponent(onFinished);
|
|
});
|
|
|
|
await userEvent.click(screen.getByRole("button", { name: "Go to Settings" }));
|
|
expect(onFinished).toHaveBeenCalled();
|
|
expect(dis.fire).toHaveBeenCalledWith(Action.ViewUserSettings);
|
|
});
|
|
|
|
test("when key backup is enabled", async () => {
|
|
jest.spyOn(matrixClient.getCrypto()!, "getActiveSessionBackupVersion").mockResolvedValue("version");
|
|
|
|
const onFinished = jest.fn();
|
|
|
|
const { asFragment } = renderComponent(onFinished);
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByText("This session is encrypting history using the new recovery method."),
|
|
).toBeInTheDocument(),
|
|
);
|
|
expect(asFragment()).toMatchSnapshot();
|
|
|
|
await userEvent.click(screen.getByRole("button", { name: "Set up Secure Messages" }));
|
|
expect(onFinished).toHaveBeenCalled();
|
|
});
|
|
|
|
test("when key backup is disabled", async () => {
|
|
const onFinished = jest.fn();
|
|
|
|
const { asFragment } = renderComponent(onFinished);
|
|
expect(asFragment()).toMatchSnapshot();
|
|
|
|
await userEvent.click(screen.getByRole("button", { name: "Set up Secure Messages" }));
|
|
await waitFor(() => expect(Modal.createDialog).toHaveBeenCalled());
|
|
});
|
|
});
|