From 65bfc920a2504abbf7bd47018c481406196a877e Mon Sep 17 00:00:00 2001 From: Kim Brose <2803622+HarHarLinks@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:01:00 +0100 Subject: [PATCH 1/2] fix automatic DM avatar with functional members (#12157) * fix automatic DM avatar with functional members * add tests for functional members * add snapshot for functional members avatar test * update snapshot for functional members avatar test * restore mocks after each functional members avatar test * refactor DecoratedRoomAvatar-test --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: R Midhun Suresh --- .../views/avatars/DecoratedRoomAvatar.tsx | 3 +- .../avatars/DecoratedRoomAvatar-test.tsx | 53 ++++++++++++++++--- .../DecoratedRoomAvatar-test.tsx.snap | 25 +++++++++ 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/components/views/avatars/DecoratedRoomAvatar.tsx b/src/components/views/avatars/DecoratedRoomAvatar.tsx index 5bdc90a1f7cd..ed8afe7b61a6 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 aa5af564dc5a..8884283be8f4 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 + +
+
+ +`; From c3e0535be93a8c7a3652e76b0318363357249b26 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:39:09 +0000 Subject: [PATCH 2/2] Update dependency sanitize-html to v2.12.1 [SECURITY] (#12302) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4c61a577ed71..bbbddceb3703 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "react-transition-group": "^4.4.1", "rfc4648": "^1.4.0", "sanitize-filename": "^1.6.3", - "sanitize-html": "2.11.0", + "sanitize-html": "2.12.1", "tar-js": "^0.3.0", "ua-parser-js": "^1.0.2", "uuid": "^9.0.0", diff --git a/yarn.lock b/yarn.lock index 256fbd4ff6a0..46ac9bc1e33f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8247,10 +8247,10 @@ sanitize-filename@^1.6.3: dependencies: truncate-utf8-bytes "^1.0.0" -sanitize-html@2.11.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/sanitize-html/-/sanitize-html-2.11.0.tgz#9a6434ee8fcaeddc740d8ae7cd5dd71d3981f8f6" - integrity sha512-BG68EDHRaGKqlsNjJ2xUB7gpInPA8gVx/mvjO743hZaeMCZ2DwzW7xvsqZ+KNU4QKwj86HJ3uu2liISf2qBBUA== +sanitize-html@2.12.1: + version "2.12.1" + resolved "https://registry.yarnpkg.com/sanitize-html/-/sanitize-html-2.12.1.tgz#280a0f5c37305222921f6f9d605be1f6558914c7" + integrity sha512-Plh+JAn0UVDpBRP/xEjsk+xDCoOvMBwQUf/K+/cBAVuTbtX8bj2VB7S1sL1dssVpykqp0/KPSesHrqXtokVBpA== dependencies: deepmerge "^4.2.2" escape-string-regexp "^4.0.0"