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 a3bf5f7 commit 99cca6c
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();

Check warning on line 102 in test/components/views/avatars/DecoratedRoomAvatar-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

RETRY 1: DecoratedRoomAvatar › shows the presence indicator in a DM room that also has functional members

expect(received).toMatchSnapshot() Snapshot name: `DecoratedRoomAvatar shows the presence indicator in a DM room that also has functional members 1` New snapshot was not written. The update flag must be explicitly passed to write a new snapshot. This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default. Received: <DocumentFragment> <div class="mx_DecoratedRoomAvatar mx_DecoratedRoomAvatar_cutout" > <span class="_avatar_k41ul_17 mx_BaseAvatar _avatar-imageless_k41ul_60" data-color="5" data-testid="avatar-img" data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" > r </span> <div aria-describedby="radix-1" class="mx_DecoratedRoomAvatar_icon mx_DecoratedRoomAvatar_icon_online" data-state="delayed-open" tabindex="0" /> </div> </DocumentFragment> at Object.toMatchSnapshot (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:102:30)

Check warning on line 102 in test/components/views/avatars/DecoratedRoomAvatar-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

RETRY 2: DecoratedRoomAvatar › shows the presence indicator in a DM room that also has functional members

expect(received).toMatchSnapshot() Snapshot name: `DecoratedRoomAvatar shows the presence indicator in a DM room that also has functional members 1` New snapshot was not written. The update flag must be explicitly passed to write a new snapshot. This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default. Received: <DocumentFragment> <div class="mx_DecoratedRoomAvatar mx_DecoratedRoomAvatar_cutout" > <span class="_avatar_k41ul_17 mx_BaseAvatar _avatar-imageless_k41ul_60" data-color="5" data-testid="avatar-img" data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" > r </span> <div aria-describedby="radix-2" class="mx_DecoratedRoomAvatar_icon mx_DecoratedRoomAvatar_icon_online" data-state="delayed-open" tabindex="0" /> </div> </DocumentFragment> at Object.toMatchSnapshot (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:102:30)

Check failure on line 102 in test/components/views/avatars/DecoratedRoomAvatar-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

DecoratedRoomAvatar › shows the presence indicator in a DM room that also has functional members

expect(received).toMatchSnapshot() Snapshot name: `DecoratedRoomAvatar shows the presence indicator in a DM room that also has functional members 1` New snapshot was not written. The update flag must be explicitly passed to write a new snapshot. This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default. Received: <DocumentFragment> <div class="mx_DecoratedRoomAvatar mx_DecoratedRoomAvatar_cutout" > <span class="_avatar_k41ul_17 mx_BaseAvatar _avatar-imageless_k41ul_60" data-color="5" data-testid="avatar-img" data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" > r </span> <div aria-describedby="radix-3" class="mx_DecoratedRoomAvatar_icon mx_DecoratedRoomAvatar_icon_online" data-state="delayed-open" tabindex="0" /> </div> </DocumentFragment> at Object.toMatchSnapshot (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:102:30)
});
});

0 comments on commit 99cca6c

Please sign in to comment.