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

Commit

Permalink
add tests for functional members
Browse files Browse the repository at this point in the history
  • Loading branch information
HarHarLinks committed Feb 16, 2024
1 parent 52da061 commit a88a576
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions test/components/views/avatars/DecoratedRoomAvatar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import { stubClient } from "../../../test-utils";
import DecoratedRoomAvatar from "../../../../src/components/views/avatars/DecoratedRoomAvatar";
import DMRoomMap from "../../../../src/utils/DMRoomMap";

jest.mock("../../../../src/utils/presence", () => ({ isPresenceEnabled: jest.fn().mockReturnValue(true) }));

jest.mock("../../../../src/utils/room/getJoinedNonFunctionalMembers", () => ({
getJoinedNonFunctionalMembers: jest.fn().mockReturnValue([0, 1]),
}));

jest.spyOn(DecoratedRoomAvatar.prototype as any, "getPresenceIcon").mockImplementation(() => "ONLINE");

describe("DecoratedRoomAvatar", () => {
const ROOM_ID = "roomId";

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

it("shows an avatar with globe icon and tooltip for public room", async () => {
const dmRoomMap = {
getUserIdForRoomId: jest.fn(),
} as unknown as DMRoomMap;
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
});

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

expect(asFragment()).toMatchSnapshot();
});

it("shows the presence indicator in a DM room that also has functional members", async () => {
const DM_USER_ID = "@bob:foo.bar";
const dmRoomMap = {
getUserIdForRoomId: () => {
return DM_USER_ID;
},
} as unknown as DMRoomMap;
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
const { container, asFragment } = render(<DecoratedRoomAvatar room={room} size="32px" />, {
wrapper: TooltipProvider,
});

const presence = container.querySelector(".mx_DecoratedRoomAvatar_icon")!;
expect(presence).toBeVisible();
await userEvent.hover(presence!);

// wait for the tooltip to open
const tooltip = await waitFor(() => {
const tooltip = document.getElementById(presence.getAttribute("aria-describedby")!);
expect(tooltip).toBeVisible();
return tooltip;
});
expect(tooltip).toHaveTextContent("Online");

expect(asFragment()).toMatchSnapshot();
});
});

0 comments on commit a88a576

Please sign in to comment.