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 6, 2024
1 parent 52da061 commit 625760a
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/components/views/avatars/DecoratedRoomAvatar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import { render, waitFor } from "@testing-library/react";
import { mocked } from "jest-mock";
import { JoinRule, MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
import { JoinRule, MatrixClient, PendingEventOrdering, Room, RoomMember } from "matrix-js-sdk/src/matrix";
import React from "react";
import userEvent from "@testing-library/user-event";
import { TooltipProvider } from "@vector-im/compound-web";
Expand All @@ -25,9 +25,13 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import { stubClient } from "../../../test-utils";
import DecoratedRoomAvatar from "../../../../src/components/views/avatars/DecoratedRoomAvatar";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { isPresenceEnabled } from "../../../../src/utils/presence";
import { getJoinedNonFunctionalMembers } from "../../../../src/utils/room/getJoinedNonFunctionalMembers";

describe("DecoratedRoomAvatar", () => {
const ROOM_ID = "roomId";
const MY_USER_ID = "@alice:foo.bar";
const DM_USER_ID = "@bob:foo.bar";

let mockClient: MatrixClient;
let room: Room;
Expand All @@ -40,8 +44,16 @@ describe("DecoratedRoomAvatar", () => {
pendingEventOrdering: PendingEventOrdering.Detached,
});

jest.fn(isPresenceEnabled).mockReturnValue(true);
jest.fn(getJoinedNonFunctionalMembers).mockReturnValue([
new RoomMember(ROOM_ID, MY_USER_ID),
new RoomMember(ROOM_ID, DM_USER_ID),
]);

const dmRoomMap = {
getUserIdForRoomId: jest.fn(),
getUserIdForRoomId: () => {
return DM_USER_ID;
},
} as unknown as DMRoomMap;
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
});
Expand All @@ -66,4 +78,24 @@ describe("DecoratedRoomAvatar", () => {

expect(asFragment()).toMatchSnapshot();

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

View workflow job for this annotation

GitHub Actions / Jest (1)

RETRY 1: DecoratedRoomAvatar › shows an avatar with globe icon and tooltip for public room

expect(received).toMatchSnapshot() Snapshot name: `DecoratedRoomAvatar shows an avatar with globe icon and tooltip for public room 1` - Snapshot - 1 + Received + 1 @@ -2,11 +2,11 @@ <div class="mx_DecoratedRoomAvatar mx_DecoratedRoomAvatar_cutout" > <span class="_avatar_1o69u_17 mx_BaseAvatar _avatar-imageless_1o69u_60" - data-color="3" + data-color="5" data-testid="avatar-img" data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" > at Object.toMatchSnapshot (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:79:30)

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

View workflow job for this annotation

GitHub Actions / Jest (1)

RETRY 2: DecoratedRoomAvatar › shows an avatar with globe icon and tooltip for public room

expect(received).toMatchSnapshot() Snapshot name: `DecoratedRoomAvatar shows an avatar with globe icon and tooltip for public room 1` - Snapshot - 2 + Received + 2 @@ -2,20 +2,20 @@ <div class="mx_DecoratedRoomAvatar mx_DecoratedRoomAvatar_cutout" > <span class="_avatar_1o69u_17 mx_BaseAvatar _avatar-imageless_1o69u_60" - data-color="3" + data-color="5" data-testid="avatar-img" data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" > r </span> <div - aria-describedby="radix-0" + aria-describedby="radix-1" class="mx_DecoratedRoomAvatar_icon mx_DecoratedRoomAvatar_icon_globe" data-state="delayed-open" tabindex="0" /> </div> at Object.toMatchSnapshot (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:79:30)

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

View workflow job for this annotation

GitHub Actions / Jest (1)

DecoratedRoomAvatar › shows an avatar with globe icon and tooltip for public room

expect(received).toMatchSnapshot() Snapshot name: `DecoratedRoomAvatar shows an avatar with globe icon and tooltip for public room 1` - Snapshot - 2 + Received + 2 @@ -2,20 +2,20 @@ <div class="mx_DecoratedRoomAvatar mx_DecoratedRoomAvatar_cutout" > <span class="_avatar_1o69u_17 mx_BaseAvatar _avatar-imageless_1o69u_60" - data-color="3" + data-color="5" data-testid="avatar-img" data-type="round" role="presentation" style="--cpd-avatar-size: 32px;" > r </span> <div - aria-describedby="radix-0" + aria-describedby="radix-2" class="mx_DecoratedRoomAvatar_icon mx_DecoratedRoomAvatar_icon_globe" data-state="delayed-open" tabindex="0" /> </div> at Object.toMatchSnapshot (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:79:30)
});

it("shows the presence indicator in a DM room with functional members", async () => {
const { container, asFragment } = render(<DecoratedRoomAvatar room={room} size="32px" />, {
wrapper: TooltipProvider,
});

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

Check warning on line 88 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 with functional members

expect(received).toBeVisible() received value must be an HTMLElement or an SVGElement. Received has value: null at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:325:30) at Object.throwingMatcher [as toBeVisible] (node_modules/expect/build/index.js:326:15) at Object.toBeVisible (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:88:26)

Check warning on line 88 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 with functional members

expect(received).toBeVisible() received value must be an HTMLElement or an SVGElement. Received has value: null at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:325:30) at Object.throwingMatcher [as toBeVisible] (node_modules/expect/build/index.js:326:15) at Object.toBeVisible (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:88:26)

Check failure on line 88 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 with functional members

expect(received).toBeVisible() received value must be an HTMLElement or an SVGElement. Received has value: null at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:325:30) at Object.throwingMatcher [as toBeVisible] (node_modules/expect/build/index.js:326:15) at Object.toBeVisible (test/components/views/avatars/DecoratedRoomAvatar-test.tsx:88:26)
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("Offline");

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

0 comments on commit 625760a

Please sign in to comment.