Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed May 12, 2023
1 parent 21daeed commit 3f48834
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions test/DeviceListener-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,34 +243,34 @@ describe("DeviceListener", () => {
await createAndStart();

expect(mockClient!.isVersionSupported).toHaveBeenCalledWith("v1.1");
expect(mockClient!.isCrossSigningReady).not.toHaveBeenCalled();
expect(mockCrypto!.isCrossSigningReady).not.toHaveBeenCalled();
});
it("does nothing when crypto is not enabled", async () => {
mockClient!.isCryptoEnabled.mockReturnValue(false);
mockClient!.getCrypto.mockReturnValue(undefined);
await createAndStart();

expect(mockClient!.isCrossSigningReady).not.toHaveBeenCalled();
expect(mockCrypto!.isCrossSigningReady).not.toHaveBeenCalled();
});
it("does nothing when initial sync is not complete", async () => {
mockClient!.isInitialSyncComplete.mockReturnValue(false);
await createAndStart();

expect(mockClient!.isCrossSigningReady).not.toHaveBeenCalled();
expect(mockCrypto!.isCrossSigningReady).not.toHaveBeenCalled();
});

describe("set up encryption", () => {
const rooms = [{ roomId: "!room1" }, { roomId: "!room2" }] as unknown as Room[];

beforeEach(() => {
mockClient!.isCrossSigningReady.mockResolvedValue(false);
mockClient!.isSecretStorageReady.mockResolvedValue(false);
mockCrypto!.isCrossSigningReady.mockResolvedValue(false);
mockCrypto!.isSecretStorageReady.mockResolvedValue(false);
mockClient!.getRooms.mockReturnValue(rooms);
mockClient!.isRoomEncrypted.mockReturnValue(true);
});

it("hides setup encryption toast when cross signing and secret storage are ready", async () => {
mockClient!.isCrossSigningReady.mockResolvedValue(true);
mockClient!.isSecretStorageReady.mockResolvedValue(true);
mockCrypto!.isCrossSigningReady.mockResolvedValue(true);
mockCrypto!.isSecretStorageReady.mockResolvedValue(true);
await createAndStart();
expect(SetupEncryptionToast.hideToast).toHaveBeenCalled();
});
Expand All @@ -282,19 +282,17 @@ describe("DeviceListener", () => {
expect(SetupEncryptionToast.hideToast).toHaveBeenCalled();
});

it("does not do any checks or show any toasts when secret storage is being accessed", async () => {
it("does not show any toasts when secret storage is being accessed", async () => {
mocked(isSecretStorageBeingAccessed).mockReturnValue(true);
await createAndStart();

expect(mockCrypto!.getUserDeviceInfo).not.toHaveBeenCalled();
expect(SetupEncryptionToast.showToast).not.toHaveBeenCalled();
});

it("does not do any checks or show any toasts when no rooms are encrypted", async () => {
it("does not show any toasts when no rooms are encrypted", async () => {
mockClient!.isRoomEncrypted.mockReturnValue(false);
await createAndStart();

expect(mockCrypto!.getUserDeviceInfo).not.toHaveBeenCalled();
expect(SetupEncryptionToast.showToast).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -348,7 +346,7 @@ describe("DeviceListener", () => {
});

it("checks keybackup status when setup encryption toast has been dismissed", async () => {
mockClient!.isCrossSigningReady.mockResolvedValue(false);
mockCrypto!.isCrossSigningReady.mockResolvedValue(false);
const instance = await createAndStart();

instance.dismissEncryptionSetup();
Expand Down Expand Up @@ -400,7 +398,7 @@ describe("DeviceListener", () => {
const deviceTrustUnverified = new DeviceVerificationStatus({});

beforeEach(() => {
mockClient!.isCrossSigningReady.mockResolvedValue(true);
mockCrypto!.isCrossSigningReady.mockResolvedValue(true);
mockCrypto!.getUserDeviceInfo.mockResolvedValue(
new Map([[userId, new Map([currentDevice, device2, device3].map((d) => [d.deviceId, d]))]]),
);
Expand All @@ -413,7 +411,7 @@ describe("DeviceListener", () => {
});
describe("bulk unverified sessions toasts", () => {
it("hides toast when cross signing is not ready", async () => {
mockClient!.isCrossSigningReady.mockResolvedValue(false);
mockCrypto!.isCrossSigningReady.mockResolvedValue(false);
await createAndStart();
expect(BulkUnverifiedSessionsToast.hideToast).toHaveBeenCalled();
expect(BulkUnverifiedSessionsToast.showToast).not.toHaveBeenCalled();
Expand Down

0 comments on commit 3f48834

Please sign in to comment.