diff --git a/src/components/views/avatars/DecoratedRoomAvatar.tsx b/src/components/views/avatars/DecoratedRoomAvatar.tsx index 5bdc90a1f7..ed8afe7b61 100644 --- a/src/components/views/avatars/DecoratedRoomAvatar.tsx +++ b/src/components/views/avatars/DecoratedRoomAvatar.tsx @@ -29,6 +29,7 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg"; import { _t } from "../../../languageHandler"; import DMRoomMap from "../../../utils/DMRoomMap"; import { IOOBData } from "../../../stores/ThreepidInviteStore"; +import { getJoinedNonFunctionalMembers } from "../../../utils/room/getJoinedNonFunctionalMembers"; interface IProps { room: Room; @@ -158,7 +159,7 @@ export default class DecoratedRoomAvatar extends React.PureComponent ({ isPresenceEnabled: jest.fn().mockReturnValue(true) })); + +jest.mock("../../../../src/utils/room/getJoinedNonFunctionalMembers", () => ({ + getJoinedNonFunctionalMembers: jest.fn().mockReturnValue([0, 1]), +})); + describe("DecoratedRoomAvatar", () => { const ROOM_ID = "roomId"; let mockClient: MatrixClient; let room: Room; + function renderComponent() { + return render(, { + wrapper: TooltipProvider, + }); + } + beforeEach(() => { stubClient(); mockClient = mocked(MatrixClientPeg.safeGet()); @@ -39,18 +51,20 @@ describe("DecoratedRoomAvatar", () => { room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", { pendingEventOrdering: PendingEventOrdering.Detached, }); + }); + afterEach(() => { + jest.restoreAllMocks(); + }); + + 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(, { - wrapper: TooltipProvider, - }); + + const { container, asFragment } = renderComponent(); const globe = container.querySelector(".mx_DecoratedRoomAvatar_icon_globe")!; expect(globe).toBeVisible(); @@ -66,4 +80,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); + jest.spyOn(DecoratedRoomAvatar.prototype as any, "getPresenceIcon").mockImplementation(() => "ONLINE"); + + const { container, asFragment } = renderComponent(); + + 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(); + }); }); diff --git a/test/components/views/avatars/__snapshots__/DecoratedRoomAvatar-test.tsx.snap b/test/components/views/avatars/__snapshots__/DecoratedRoomAvatar-test.tsx.snap index aa5af564dc..8884283be8 100644 --- a/test/components/views/avatars/__snapshots__/DecoratedRoomAvatar-test.tsx.snap +++ b/test/components/views/avatars/__snapshots__/DecoratedRoomAvatar-test.tsx.snap @@ -24,3 +24,28 @@ exports[`DecoratedRoomAvatar shows an avatar with globe icon and tooltip for pub `; + +exports[`DecoratedRoomAvatar shows the presence indicator in a DM room that also has functional members 1`] = ` + +
+ + r + +
+
+ +`;