diff --git a/src/components/views/rooms/MemberTile.tsx b/src/components/views/rooms/MemberTile.tsx index 300cc15e85..03aa186281 100644 --- a/src/components/views/rooms/MemberTile.tsx +++ b/src/components/views/rooms/MemberTile.tsx @@ -117,10 +117,10 @@ export default class MemberTile extends React.Component { const cli = MatrixClientPeg.safeGet(); const { userId } = this.props.member; const isMe = userId === cli.getUserId(); - const userTrust = cli.checkUserTrust(userId); - if (!userTrust.isCrossSigningVerified()) { + const userTrust = await cli.getCrypto()?.getUserVerificationStatus(userId); + if (!userTrust?.isCrossSigningVerified()) { this.setState({ - e2eStatus: userTrust.wasCrossSigningVerified() ? E2EState.Warning : E2EState.Normal, + e2eStatus: userTrust?.wasCrossSigningVerified() ? E2EState.Warning : E2EState.Normal, }); return; } diff --git a/test/components/views/rooms/MemberTile-test.tsx b/test/components/views/rooms/MemberTile-test.tsx new file mode 100644 index 0000000000..58e910aabf --- /dev/null +++ b/test/components/views/rooms/MemberTile-test.tsx @@ -0,0 +1,79 @@ +/* + * Copyright 2023 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +import React from "react"; +import { render, screen, waitFor } from "@testing-library/react"; +import { MatrixClient, RoomMember, Device } from "matrix-js-sdk/src/matrix"; +import { UserVerificationStatus, DeviceVerificationStatus } from "matrix-js-sdk/src/crypto-api"; +import { mocked } from "jest-mock"; + +import * as TestUtils from "../../../test-utils"; +import MemberTile from "../../../../src/components/views/rooms/MemberTile"; + +describe("MemberTile", () => { + let matrixClient: MatrixClient; + let member: RoomMember; + + beforeEach(() => { + matrixClient = TestUtils.stubClient(); + mocked(matrixClient.isRoomEncrypted).mockReturnValue(true); + member = new RoomMember("roomId", matrixClient.getUserId()!); + }); + + it("should not display an E2EIcon when the e2E status = normal", () => { + const { container } = render(); + + expect(container).toMatchSnapshot(); + }); + + it("should display an warning E2EIcon when the e2E status = Warning", async () => { + mocked(matrixClient.getCrypto()!.getUserVerificationStatus).mockResolvedValue({ + isCrossSigningVerified: jest.fn().mockReturnValue(false), + wasCrossSigningVerified: jest.fn().mockReturnValue(true), + } as unknown as UserVerificationStatus); + + const { container } = render(); + + await waitFor(() => + expect(screen.getByLabelText("This user has not verified all of their sessions.")).toBeInTheDocument(), + ); + expect(container).toMatchSnapshot(); + }); + + it("should display an verified E2EIcon when the e2E status = Verified", async () => { + // Mock all the required crypto methods + const deviceMap = new Map>(); + deviceMap.set(member.userId, new Map([["deviceId", {} as Device]])); + // Return a DeviceMap = Map> + mocked(matrixClient.getCrypto()!.getUserDeviceInfo).mockResolvedValue(deviceMap); + mocked(matrixClient.getCrypto()!.getUserVerificationStatus).mockResolvedValue({ + isCrossSigningVerified: jest.fn().mockReturnValue(true), + } as unknown as UserVerificationStatus); + mocked(matrixClient.getCrypto()!.getDeviceVerificationStatus).mockResolvedValue({ + crossSigningVerified: true, + } as DeviceVerificationStatus); + + const { container } = render(); + + await waitFor(() => + expect( + screen.getByLabelText("You have verified this user. This user has verified all of their sessions."), + ).toBeInTheDocument(), + ); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/test/components/views/rooms/__snapshots__/MemberTile-test.tsx.snap b/test/components/views/rooms/__snapshots__/MemberTile-test.tsx.snap new file mode 100644 index 0000000000..96c1df7d6f --- /dev/null +++ b/test/components/views/rooms/__snapshots__/MemberTile-test.tsx.snap @@ -0,0 +1,168 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MemberTile should display an verified E2EIcon when the e2E status = Verified 1`] = ` +
+
+
+
+ +
+
+
+
+
+ + @userId:matrix.org + +
+
+
+ Offline +
+
+
+
+
+`; + +exports[`MemberTile should display an warning E2EIcon when the e2E status = Warning 1`] = ` +
+
+
+
+ +
+
+
+
+
+ + @userId:matrix.org + +
+
+
+ Offline +
+
+
+
+
+`; + +exports[`MemberTile should not display an E2EIcon when the e2E status = normal 1`] = ` +
+
+
+
+ +
+
+
+
+ + @userId:matrix.org + +
+
+
+ Offline +
+
+
+
+
+`; diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 8cca6e05f3..f8605a08c3 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -122,7 +122,11 @@ export function createTestClient(): MatrixClient { downloadKeys: jest.fn(), }, }, - getCrypto: jest.fn().mockReturnValue({ getUserDeviceInfo: jest.fn() }), + getCrypto: jest.fn().mockReturnValue({ + getUserDeviceInfo: jest.fn(), + getUserVerificationStatus: jest.fn(), + getDeviceVerificationStatus: jest.fn(), + }), getPushActionsForEvent: jest.fn(), getRoom: jest.fn().mockImplementation((roomId) => mkStubRoom(roomId, "My room", client)),