2022-11-11 17:02:01 +01:00
|
|
|
/*
|
2023-02-02 11:22:19 +01:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2022-11-11 17:02:01 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2023-02-02 11:22:19 +01:00
|
|
|
import { getByTestId, render, waitFor } from "@testing-library/react";
|
|
|
|
import { mocked } from "jest-mock";
|
2023-08-09 09:18:41 +02:00
|
|
|
import { MatrixClient, PendingEventOrdering, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
2023-02-13 12:39:16 +01:00
|
|
|
import React, { ComponentProps } from "react";
|
2022-11-11 17:02:01 +01:00
|
|
|
|
|
|
|
import MemberAvatar from "../../../../src/components/views/avatars/MemberAvatar";
|
|
|
|
import RoomContext from "../../../../src/contexts/RoomContext";
|
2023-02-02 11:22:19 +01:00
|
|
|
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
2022-11-11 17:02:01 +01:00
|
|
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
|
|
|
import { getRoomContext } from "../../../test-utils/room";
|
|
|
|
import { stubClient } from "../../../test-utils/test-utils";
|
|
|
|
|
|
|
|
describe("MemberAvatar", () => {
|
|
|
|
const ROOM_ID = "roomId";
|
|
|
|
|
|
|
|
let mockClient: MatrixClient;
|
|
|
|
let room: Room;
|
|
|
|
let member: RoomMember;
|
|
|
|
|
2023-02-13 12:39:16 +01:00
|
|
|
function getComponent(props: Partial<ComponentProps<typeof MemberAvatar>>) {
|
2022-12-12 12:24:14 +01:00
|
|
|
return (
|
|
|
|
<RoomContext.Provider value={getRoomContext(room, {})}>
|
2023-08-24 05:48:35 +02:00
|
|
|
<MemberAvatar member={null} size="35px" {...props} />
|
2022-12-12 12:24:14 +01:00
|
|
|
</RoomContext.Provider>
|
|
|
|
);
|
2022-11-11 17:02:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-02-02 11:22:19 +01:00
|
|
|
jest.clearAllMocks();
|
|
|
|
|
|
|
|
stubClient();
|
2023-06-05 19:12:23 +02:00
|
|
|
mockClient = mocked(MatrixClientPeg.safeGet());
|
2022-11-11 17:02:01 +01: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 11:22:19 +01:00
|
|
|
it("shows an avatar for useOnlyCurrentProfiles", async () => {
|
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
|
|
|
|
return settingName === "useOnlyCurrentProfiles";
|
|
|
|
});
|
2022-11-11 17:02:01 +01:00
|
|
|
|
|
|
|
const { container } = render(getComponent({}));
|
|
|
|
|
2023-02-02 11:22:19 +01:00
|
|
|
let avatar: HTMLElement;
|
|
|
|
await waitFor(() => {
|
|
|
|
avatar = getByTestId(container, "avatar-img");
|
|
|
|
expect(avatar).toBeInTheDocument();
|
2022-11-11 17:02:01 +01:00
|
|
|
});
|
|
|
|
|
2023-02-02 11:22:19 +01:00
|
|
|
expect(avatar!.getAttribute("src")).not.toBe("");
|
2022-11-11 17:02:01 +01:00
|
|
|
});
|
|
|
|
});
|