Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 6b7ec68

Browse files
committed
add jest tests
1 parent 9afdc75 commit 6b7ec68

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

test/components/views/messages/DecryptionFailureBody-test.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,32 @@ describe("DecryptionFailureBody", () => {
103103
// Then
104104
expect(container).toHaveTextContent("You don't have access to this message");
105105
});
106+
107+
it("should handle messages from users who change identities after verification", async () => {
108+
// When
109+
const event = await mkDecryptionFailureMatrixEvent({
110+
code: DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED,
111+
msg: "User previously verified",
112+
roomId: "fakeroom",
113+
sender: "fakesender",
114+
});
115+
const { container } = customRender(event);
116+
117+
// Then
118+
expect(container).toHaveTextContent("Verified identity has changed");
119+
});
120+
121+
it("should handle messages from unverified devices", async () => {
122+
// When
123+
const event = await mkDecryptionFailureMatrixEvent({
124+
code: DecryptionFailureCode.UNSIGNED_SENDER_DEVICE,
125+
msg: "Unsigned device",
126+
roomId: "fakeroom",
127+
sender: "fakesender",
128+
});
129+
const { container } = customRender(event);
130+
131+
// Then
132+
expect(container).toHaveTextContent("Encrypted by a device not verified by its owner");
133+
});
106134
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2024 New Vector Ltd.
3+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
4+
Please see LICENSE files in the repository root for full details.
5+
*/
6+
7+
import { CryptoApi, CryptoMode } from "matrix-js-sdk/src/crypto-api";
8+
9+
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
10+
import { stubClient } from "../../test-utils";
11+
import InvisibleCryptoController from "../../../src/settings/controllers/InvisibleCryptoController";
12+
import { SettingLevel } from "../../../src/settings/SettingLevel";
13+
14+
describe("InvisibleCryptoController", () => {
15+
afterEach(() => {
16+
jest.clearAllMocks();
17+
});
18+
19+
it("tracks enabling and disabling", () => {
20+
const cli = stubClient();
21+
const setCryptoModeMock = jest.fn();
22+
cli.getCrypto = jest.fn(() => {
23+
return {
24+
setCryptoMode: setCryptoModeMock,
25+
} as unknown as CryptoApi;
26+
});
27+
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue(cli);
28+
29+
const controller = new InvisibleCryptoController();
30+
31+
controller.onChange(SettingLevel.DEVICE, "", true);
32+
expect(setCryptoModeMock).toHaveBeenCalledWith(CryptoMode.Invisible);
33+
34+
controller.onChange(SettingLevel.DEVICE, "", false);
35+
expect(setCryptoModeMock).toHaveBeenCalledWith(CryptoMode.Legacy);
36+
});
37+
});

0 commit comments

Comments
 (0)