Encryption tab: display correct encryption panel when user cancels the reset identity flow (#29216)

* fix(encryption settings): check encryption state when user cancels the reset identity flow

* test(encryption settings): add test to check encryption state when user cancels the reset identity flow
This commit is contained in:
Florian D
2025-02-07 14:57:02 +01:00
committed by GitHub
parent 40a6c69f1a
commit 4a8ba810a9
2 changed files with 29 additions and 11 deletions

View File

@@ -102,20 +102,12 @@ export function EncryptionUserSettingsTab({ initialState = "loading" }: Encrypti
);
break;
case "reset_identity_compromised":
content = (
<ResetIdentityPanel
variant="compromised"
onCancelClick={() => setState("main")}
onFinish={() => setState("main")}
/>
);
break;
case "reset_identity_forgot":
content = (
<ResetIdentityPanel
variant="forgot"
onCancelClick={() => setState("main")}
onFinish={() => setState("main")}
variant={state === "reset_identity_compromised" ? "compromised" : "forgot"}
onCancelClick={checkEncryptionState}
onFinish={checkEncryptionState}
/>
);
break;

View File

@@ -144,4 +144,30 @@ describe("<EncryptionUserSettingsTab />", () => {
screen.getByRole("heading", { name: "Forgot your recovery key? Youll need to reset your identity." }),
).toBeVisible();
});
it("should re-check the encryption state and displays the correct panel when the user clicks cancel the reset identity flow", async () => {
const user = userEvent.setup();
// Secrets are not cached
jest.spyOn(matrixClient.getCrypto()!, "getCrossSigningStatus").mockResolvedValue({
privateKeysInSecretStorage: true,
publicKeysOnDevice: true,
privateKeysCachedLocally: {
masterKey: false,
selfSigningKey: true,
userSigningKey: true,
},
});
renderComponent({ initialState: "reset_identity_forgot" });
expect(
screen.getByRole("heading", { name: "Forgot your recovery key? Youll need to reset your identity." }),
).toBeVisible();
await user.click(screen.getByRole("button", { name: "Back" }));
await waitFor(() =>
screen.getByText("Your key storage is out of sync. Click one of the buttons below to fix the problem."),
);
});
});