Skip to content

Commit 8d01c23

Browse files
committed
Add tests when user verification change
1 parent ebe8b25 commit 8d01c23

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Diff for: test/unit-tests/components/structures/RoomView-test.tsx

+27-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
RoomStateEvent,
2323
SearchResult,
2424
} from "matrix-js-sdk/src/matrix";
25-
import { CryptoApi, UserVerificationStatus } from "matrix-js-sdk/src/crypto-api";
25+
import { CryptoApi, UserVerificationStatus, CryptoEvent } from "matrix-js-sdk/src/crypto-api";
2626
import { KnownMembership } from "matrix-js-sdk/src/types";
2727
import {
2828
fireEvent,
@@ -307,6 +307,32 @@ describe("RoomView", () => {
307307
expect(roomViewInstance.state.liveTimeline).not.toEqual(oldTimeline);
308308
});
309309

310+
it("should update when the e2e status when the user verification changed", async () => {
311+
room.currentState.setStateEvents([
312+
mkRoomMemberJoinEvent(cli.getSafeUserId(), room.roomId),
313+
mkRoomMemberJoinEvent("[email protected]", room.roomId),
314+
]);
315+
room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
316+
// Not all the calls to cli.isRoomEncrypted are migrated, so we need to mock both.
317+
mocked(cli.isRoomEncrypted).mockReturnValue(true);
318+
jest.spyOn(cli, "getCrypto").mockReturnValue(crypto);
319+
jest.spyOn(cli.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
320+
jest.spyOn(cli.getCrypto()!, "getUserVerificationStatus").mockResolvedValue(
321+
new UserVerificationStatus(false, false, false),
322+
);
323+
jest.spyOn(cli.getCrypto()!, "getUserDeviceInfo").mockResolvedValue(
324+
new Map([["[email protected]", new Map<string, any>()]]),
325+
);
326+
327+
const { container } = await renderRoomView();
328+
await waitFor(() => expect(container.querySelector(".mx_E2EIcon_normal")).toBeInTheDocument());
329+
330+
const verificationStatus = new UserVerificationStatus(true, true, false);
331+
jest.spyOn(cli.getCrypto()!, "getUserVerificationStatus").mockResolvedValue(verificationStatus);
332+
cli.emit(CryptoEvent.UserTrustStatusChanged, cli.getSafeUserId(), verificationStatus);
333+
await waitFor(() => expect(container.querySelector(".mx_E2EIcon_verified")).toBeInTheDocument());
334+
});
335+
310336
describe("with virtual rooms", () => {
311337
it("checks for a virtual room on initial load", async () => {
312338
const { container } = await renderRoomView();

0 commit comments

Comments
 (0)