2022-11-12 00:02:01 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-02-02 18:22:19 +08:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2022-11-12 00:02:01 +08:00
|
|
|
|
2024-09-09 21:57:16 +08:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-11-12 00:02:01 +08:00
|
|
|
*/
|
|
|
|
|
2024-10-15 00:11:58 +08:00
|
|
|
import { getByTestId, render, waitFor } from "jest-matrix-react";
|
2023-02-02 18:22:19 +08:00
|
|
|
import { mocked } from "jest-mock";
|
2023-08-09 15:18:41 +08:00
|
|
|
import { MatrixClient, PendingEventOrdering, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
2023-02-13 19:39:16 +08:00
|
|
|
import React, { ComponentProps } from "react";
|
2022-11-12 00:02:01 +08:00
|
|
|
|
2024-10-15 21:57:26 +08:00
|
|
|
import MemberAvatar from "../../../../../src/components/views/avatars/MemberAvatar";
|
|
|
|
import RoomContext from "../../../../../src/contexts/RoomContext";
|
|
|
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
|
|
|
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
|
|
|
import { getRoomContext } from "../../../../test-utils/room";
|
|
|
|
import { stubClient } from "../../../../test-utils/test-utils";
|
2022-11-12 00:02:01 +08:00
|
|
|
|
|
|
|
describe("MemberAvatar", () => {
|
|
|
|
const ROOM_ID = "roomId";
|
|
|
|
|
|
|
|
let mockClient: MatrixClient;
|
|
|
|
let room: Room;
|
|
|
|
let member: RoomMember;
|
|
|
|
|
2023-02-13 19:39:16 +08:00
|
|
|
function getComponent(props: Partial<ComponentProps<typeof MemberAvatar>>) {
|
2022-11-12 00:02:01 +08:00
|
|
|
return (
|
|
|
|
<RoomContext.Provider value={getRoomContext(room, {})}>
|
2023-08-24 11:48:35 +08:00
|
|
|
<MemberAvatar member={null} size="35px" {...props} />
|
2022-11-12 00:02:01 +08:00
|
|
|
</RoomContext.Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-02-02 18:22:19 +08:00
|
|
|
jest.clearAllMocks();
|
|
|
|
|
|
|
|
stubClient();
|
2023-06-06 01:12:23 +08:00
|
|
|
mockClient = mocked(MatrixClientPeg.safeGet());
|
2022-11-12 00:02:01 +08:00
|
|
|
|
|
|
|
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
|
|
|
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
|
|
|
});
|
|
|
|
|
|
|
|
member = new RoomMember(ROOM_ID, "@bob:example.org");
|
|
|
|
jest.spyOn(room, "getMember").mockReturnValue(member);
|
|
|
|
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("http://placekitten.com/400/400");
|
|
|
|
});
|
|
|
|
|
2023-02-02 18:22:19 +08:00
|
|
|
it("shows an avatar for useOnlyCurrentProfiles", async () => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
|
|
|
|
return settingName === "useOnlyCurrentProfiles";
|
|
|
|
});
|
2022-11-12 00:02:01 +08:00
|
|
|
|
|
|
|
const { container } = render(getComponent({}));
|
|
|
|
|
2023-02-02 18:22:19 +08:00
|
|
|
let avatar: HTMLElement;
|
|
|
|
await waitFor(() => {
|
|
|
|
avatar = getByTestId(container, "avatar-img");
|
|
|
|
expect(avatar).toBeInTheDocument();
|
2022-11-12 00:02:01 +08:00
|
|
|
});
|
|
|
|
|
2023-02-02 18:22:19 +08:00
|
|
|
expect(avatar!.getAttribute("src")).not.toBe("");
|
2022-11-12 00:02:01 +08:00
|
|
|
});
|
|
|
|
});
|