Log when we show, and hide, encryption setup toasts (#29235)
It's currently hard to debug when someone sees or hides one of these toasts. Lets's add some logging.
This commit is contained in:
committed by
GitHub
parent
ef69c0ddc7
commit
f2fae82e32
@@ -8,7 +8,6 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import { type Mocked, mocked } from "jest-mock";
|
||||
import { MatrixEvent, type Room, type MatrixClient, Device, ClientStoppedError } from "matrix-js-sdk/src/matrix";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import {
|
||||
CryptoEvent,
|
||||
type CrossSigningStatus,
|
||||
@@ -33,9 +32,6 @@ import { UIFeature } from "../../src/settings/UIFeature";
|
||||
import { isBulkUnverifiedDeviceReminderSnoozed } from "../../src/utils/device/snoozeBulkUnverifiedDeviceReminder";
|
||||
import { PosthogAnalytics } from "../../src/PosthogAnalytics";
|
||||
|
||||
// don't litter test console with logs
|
||||
jest.mock("matrix-js-sdk/src/logger");
|
||||
|
||||
jest.mock("../../src/dispatcher/dispatcher", () => ({
|
||||
dispatch: jest.fn(),
|
||||
register: jest.fn(),
|
||||
@@ -63,6 +59,12 @@ describe("DeviceListener", () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
// don't litter the console with logs
|
||||
jest.spyOn(console, "debug").mockImplementation(() => {});
|
||||
jest.spyOn(console, "info").mockImplementation(() => {});
|
||||
jest.spyOn(console, "warn").mockImplementation(() => {});
|
||||
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
// spy on various toasts' hide and show functions
|
||||
// easier than mocking
|
||||
jest.spyOn(SetupEncryptionToast, "showToast").mockReturnValue(undefined);
|
||||
@@ -158,14 +160,17 @@ describe("DeviceListener", () => {
|
||||
});
|
||||
|
||||
it("catches error and logs when saving client information fails", async () => {
|
||||
const errorLogSpy = jest.spyOn(logger, "error");
|
||||
const error = new Error("oups");
|
||||
mockClient!.setAccountData.mockRejectedValue(error);
|
||||
|
||||
// doesn't throw
|
||||
await createAndStart();
|
||||
|
||||
expect(errorLogSpy).toHaveBeenCalledWith("Failed to update client information", error);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
"DeviceListener:",
|
||||
"Failed to update client information",
|
||||
error,
|
||||
);
|
||||
});
|
||||
|
||||
it("saves client information on logged in action", async () => {
|
||||
@@ -275,14 +280,14 @@ describe("DeviceListener", () => {
|
||||
throw new ClientStoppedError();
|
||||
});
|
||||
await createAndStart();
|
||||
expect(logger.error).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
});
|
||||
it("correctly handles other errors", async () => {
|
||||
mockCrypto!.isCrossSigningReady.mockImplementation(() => {
|
||||
throw new Error("blah");
|
||||
});
|
||||
await createAndStart();
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
describe("set up encryption", () => {
|
||||
|
||||
Reference in New Issue
Block a user