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

Commit 99cca6c

Browse files
committed
add tests for functional members
1 parent a3bf5f7 commit 99cca6c

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

test/components/views/avatars/DecoratedRoomAvatar-test.tsx

+37-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ import { stubClient } from "../../../test-utils";
2626
import DecoratedRoomAvatar from "../../../../src/components/views/avatars/DecoratedRoomAvatar";
2727
import DMRoomMap from "../../../../src/utils/DMRoomMap";
2828

29+
jest.mock("../../../../src/utils/presence", () => ({ isPresenceEnabled: jest.fn().mockReturnValue(true) }));
30+
31+
jest.mock("../../../../src/utils/room/getJoinedNonFunctionalMembers", () => ({
32+
getJoinedNonFunctionalMembers: jest.fn().mockReturnValue([0, 1]),
33+
}));
34+
35+
jest.spyOn(DecoratedRoomAvatar.prototype as any, "getPresenceIcon").mockImplementation(() => "ONLINE");
36+
2937
describe("DecoratedRoomAvatar", () => {
3038
const ROOM_ID = "roomId";
3139

@@ -39,14 +47,14 @@ describe("DecoratedRoomAvatar", () => {
3947
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
4048
pendingEventOrdering: PendingEventOrdering.Detached,
4149
});
50+
});
4251

52+
it("shows an avatar with globe icon and tooltip for public room", async () => {
4353
const dmRoomMap = {
4454
getUserIdForRoomId: jest.fn(),
4555
} as unknown as DMRoomMap;
4656
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
47-
});
4857

49-
it("shows an avatar with globe icon and tooltip for public room", async () => {
5058
room.getJoinRule = jest.fn().mockReturnValue(JoinRule.Public);
5159
const { container, asFragment } = render(<DecoratedRoomAvatar room={room} size="32px" />, {
5260
wrapper: TooltipProvider,
@@ -66,4 +74,31 @@ describe("DecoratedRoomAvatar", () => {
6674

6775
expect(asFragment()).toMatchSnapshot();
6876
});
77+
78+
it("shows the presence indicator in a DM room that also has functional members", async () => {
79+
const DM_USER_ID = "@bob:foo.bar";
80+
const dmRoomMap = {
81+
getUserIdForRoomId: () => {
82+
return DM_USER_ID;
83+
},
84+
} as unknown as DMRoomMap;
85+
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
86+
const { container, asFragment } = render(<DecoratedRoomAvatar room={room} size="32px" />, {
87+
wrapper: TooltipProvider,
88+
});
89+
90+
const presence = container.querySelector(".mx_DecoratedRoomAvatar_icon")!;
91+
expect(presence).toBeVisible();
92+
await userEvent.hover(presence!);
93+
94+
// wait for the tooltip to open
95+
const tooltip = await waitFor(() => {
96+
const tooltip = document.getElementById(presence.getAttribute("aria-describedby")!);
97+
expect(tooltip).toBeVisible();
98+
return tooltip;
99+
});
100+
expect(tooltip).toHaveTextContent("Online");
101+
102+
expect(asFragment()).toMatchSnapshot();
103+
});
69104
});

0 commit comments

Comments
 (0)