Tidy SetupEncryptionToast tests (#29887)
* Remove extraneous 'await' from SetupEncryptionToast * Group SetupEncryptionToast tests
This commit is contained in:
@@ -26,56 +26,60 @@ describe("SetupEncryptionToast", () => {
|
|||||||
render(<ToastContainer />);
|
render(<ToastContainer />);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render the 'set up recovery' toast", async () => {
|
describe("Set up recovery", () => {
|
||||||
showToast(Kind.SET_UP_RECOVERY);
|
it("should render the toast", async () => {
|
||||||
|
showToast(Kind.SET_UP_RECOVERY);
|
||||||
|
|
||||||
await expect(await screen.findByRole("heading", { name: "Set up recovery" })).toBeInTheDocument();
|
expect(await screen.findByRole("heading", { name: "Set up recovery" })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should dismiss toast when 'not now' button clicked", async () => {
|
it("should dismiss the toast when 'not now' button clicked", async () => {
|
||||||
jest.spyOn(DeviceListener.sharedInstance(), "dismissEncryptionSetup");
|
jest.spyOn(DeviceListener.sharedInstance(), "dismissEncryptionSetup");
|
||||||
|
|
||||||
showToast(Kind.SET_UP_RECOVERY);
|
showToast(Kind.SET_UP_RECOVERY);
|
||||||
|
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
await user.click(await screen.findByRole("button", { name: "Not now" }));
|
await user.click(await screen.findByRole("button", { name: "Not now" }));
|
||||||
|
|
||||||
expect(DeviceListener.sharedInstance().dismissEncryptionSetup).toHaveBeenCalled();
|
expect(DeviceListener.sharedInstance().dismissEncryptionSetup).toHaveBeenCalled();
|
||||||
});
|
|
||||||
|
|
||||||
it("should render the 'key storage out of sync' toast", async () => {
|
|
||||||
showToast(Kind.KEY_STORAGE_OUT_OF_SYNC);
|
|
||||||
|
|
||||||
await expect(screen.findByText("Your key storage is out of sync.")).resolves.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should open settings to the reset flow when 'forgot recovery key' clicked", async () => {
|
|
||||||
showToast(Kind.KEY_STORAGE_OUT_OF_SYNC);
|
|
||||||
|
|
||||||
const user = userEvent.setup();
|
|
||||||
await user.click(await screen.findByText("Forgot recovery key?"));
|
|
||||||
|
|
||||||
expect(dis.dispatch).toHaveBeenCalledWith({
|
|
||||||
action: "view_user_settings",
|
|
||||||
initialTabId: "USER_ENCRYPTION_TAB",
|
|
||||||
props: { initialEncryptionState: "reset_identity_forgot" },
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should open settings to the reset flow when recovering fails clicked", async () => {
|
describe("Key storage out of sync", () => {
|
||||||
jest.spyOn(SecurityManager, "accessSecretStorage").mockImplementation(async () => {
|
it("should render the toast", async () => {
|
||||||
throw new Error("Something went wrong while recovering!");
|
showToast(Kind.KEY_STORAGE_OUT_OF_SYNC);
|
||||||
|
|
||||||
|
await expect(screen.findByText("Your key storage is out of sync.")).resolves.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
showToast(Kind.KEY_STORAGE_OUT_OF_SYNC);
|
it("should open settings to the reset flow when 'forgot recovery key' clicked", async () => {
|
||||||
|
showToast(Kind.KEY_STORAGE_OUT_OF_SYNC);
|
||||||
|
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
await user.click(await screen.findByText("Enter recovery key"));
|
await user.click(await screen.findByText("Forgot recovery key?"));
|
||||||
|
|
||||||
expect(dis.dispatch).toHaveBeenCalledWith({
|
expect(dis.dispatch).toHaveBeenCalledWith({
|
||||||
action: "view_user_settings",
|
action: "view_user_settings",
|
||||||
initialTabId: "USER_ENCRYPTION_TAB",
|
initialTabId: "USER_ENCRYPTION_TAB",
|
||||||
props: { initialEncryptionState: "reset_identity_forgot" },
|
props: { initialEncryptionState: "reset_identity_forgot" },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should open settings to the reset flow when recovering fails clicked", async () => {
|
||||||
|
jest.spyOn(SecurityManager, "accessSecretStorage").mockImplementation(async () => {
|
||||||
|
throw new Error("Something went wrong while recovering!");
|
||||||
|
});
|
||||||
|
|
||||||
|
showToast(Kind.KEY_STORAGE_OUT_OF_SYNC);
|
||||||
|
|
||||||
|
const user = userEvent.setup();
|
||||||
|
await user.click(await screen.findByText("Enter recovery key"));
|
||||||
|
|
||||||
|
expect(dis.dispatch).toHaveBeenCalledWith({
|
||||||
|
action: "view_user_settings",
|
||||||
|
initialTabId: "USER_ENCRYPTION_TAB",
|
||||||
|
props: { initialEncryptionState: "reset_identity_forgot" },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user