ChangeRecoveryKey: error handling (#29262)
* CreateSecretStorageDialog: error handling I'm fed up with setup operations in EW failing silently. Rather than leaving the user with a mysteriously broken client, let's at least tell them that something has gone wrong, so that they can report the issue and we can investigate. Obviously, showing an unactionable Error dialog is a last resort: ideally, we should handle the error ourselves, or give the user actionable steps to resolve the problem. But that takes significant design and engineering. Just swallowing errors is the worst of all possible options. * Fix typo in test name * Improve test coverage
This commit is contained in:
committed by
GitHub
parent
6dbc3b489a
commit
a365533367
@@ -9,6 +9,7 @@ import React from "react";
|
||||
import { render, screen, waitFor } from "jest-matrix-react";
|
||||
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { ChangeRecoveryKey } from "../../../../../../src/components/views/settings/encryption/ChangeRecoveryKey";
|
||||
import { createTestClient, withClientContextRenderOptions } from "../../../../../test-utils";
|
||||
@@ -18,6 +19,10 @@ jest.mock("../../../../../../src/utils/strings", () => ({
|
||||
copyPlaintext: jest.fn(),
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("<ChangeRecoveryKey />", () => {
|
||||
let matrixClient: MatrixClient;
|
||||
|
||||
@@ -36,7 +41,7 @@ describe("<ChangeRecoveryKey />", () => {
|
||||
);
|
||||
}
|
||||
|
||||
describe("flow to setup a recovery key", () => {
|
||||
describe("flow to set up a recovery key", () => {
|
||||
it("should display information about the recovery key", async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
@@ -107,6 +112,33 @@ describe("<ChangeRecoveryKey />", () => {
|
||||
await user.click(finishButton);
|
||||
expect(onFinish).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it("should display errors from bootstrapSecretStorage", async () => {
|
||||
const consoleErrorSpy = jest.spyOn(console, "error").mockReturnValue(undefined);
|
||||
mocked(matrixClient.getCrypto()!).bootstrapSecretStorage.mockRejectedValue(new Error("can't bootstrap"));
|
||||
|
||||
const user = userEvent.setup();
|
||||
renderComponent(false);
|
||||
|
||||
// Display the recovery key to save
|
||||
await waitFor(() => user.click(screen.getByRole("button", { name: "Continue" })));
|
||||
// Display the form to confirm the recovery key
|
||||
await waitFor(() => user.click(screen.getByRole("button", { name: "Continue" })));
|
||||
|
||||
await waitFor(() => expect(screen.getByText("Enter your recovery key to confirm")).toBeInTheDocument());
|
||||
|
||||
const finishButton = screen.getByRole("button", { name: "Finish set up" });
|
||||
const input = screen.getByRole("textbox");
|
||||
await userEvent.type(input, "encoded private key");
|
||||
await user.click(finishButton);
|
||||
|
||||
await screen.findByText("Failed to set up secret storage");
|
||||
await screen.findByText("Error: can't bootstrap");
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
"Failed to set up secret storage:",
|
||||
new Error("can't bootstrap"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("flow to change the recovery key", () => {
|
||||
|
||||
@@ -160,7 +160,7 @@ exports[`<ChangeRecoveryKey /> flow to change the recovery key should display th
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<ChangeRecoveryKey /> flow to setup a recovery key should ask the user to enter the recovery key 1`] = `
|
||||
exports[`<ChangeRecoveryKey /> flow to set up a recovery key should ask the user to enter the recovery key 1`] = `
|
||||
<DocumentFragment>
|
||||
<nav
|
||||
class="_breadcrumb_ikpbb_17"
|
||||
@@ -293,7 +293,7 @@ exports[`<ChangeRecoveryKey /> flow to setup a recovery key should ask the user
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<ChangeRecoveryKey /> flow to setup a recovery key should ask the user to enter the recovery key 2`] = `
|
||||
exports[`<ChangeRecoveryKey /> flow to set up a recovery key should ask the user to enter the recovery key 2`] = `
|
||||
<DocumentFragment>
|
||||
<nav
|
||||
class="_breadcrumb_ikpbb_17"
|
||||
@@ -448,7 +448,7 @@ exports[`<ChangeRecoveryKey /> flow to setup a recovery key should ask the user
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<ChangeRecoveryKey /> flow to setup a recovery key should display information about the recovery key 1`] = `
|
||||
exports[`<ChangeRecoveryKey /> flow to set up a recovery key should display information about the recovery key 1`] = `
|
||||
<DocumentFragment>
|
||||
<nav
|
||||
class="_breadcrumb_ikpbb_17"
|
||||
@@ -564,7 +564,7 @@ exports[`<ChangeRecoveryKey /> flow to setup a recovery key should display infor
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<ChangeRecoveryKey /> flow to setup a recovery key should display the recovery key 1`] = `
|
||||
exports[`<ChangeRecoveryKey /> flow to set up a recovery key should display the recovery key 1`] = `
|
||||
<DocumentFragment>
|
||||
<nav
|
||||
class="_breadcrumb_ikpbb_17"
|
||||
|
||||
Reference in New Issue
Block a user