From f8c809b2a959e8085edfd13c54881d10b2380328 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 14 Jul 2023 14:51:20 +0100 Subject: [PATCH] Fix missing metaspace notification badges --- .../views/spaces/SpaceTreeLevel.tsx | 17 +++++-- .../views/spaces/SpaceTreeLevel-test.tsx | 21 +++++++- .../SpaceTreeLevel-test.tsx.snap | 49 +++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 test/components/views/spaces/__snapshots__/SpaceTreeLevel-test.tsx.snap diff --git a/src/components/views/spaces/SpaceTreeLevel.tsx b/src/components/views/spaces/SpaceTreeLevel.tsx index 72ed355ffaaf..2b1f52371c7a 100644 --- a/src/components/views/spaces/SpaceTreeLevel.tsx +++ b/src/components/views/spaces/SpaceTreeLevel.tsx @@ -47,6 +47,7 @@ import SpaceContextMenu from "../context_menus/SpaceContextMenu"; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; +import { XOR } from "../../../@types/common"; interface IButtonProps extends Omit, "title" | "onClick"> { space?: Room; @@ -55,7 +56,6 @@ interface IButtonProps extends Omit; @@ -63,7 +63,16 @@ interface IButtonProps extends Omit = ({ +type ButtonPropsWithNotification = IButtonProps & { notificationState: NotificationState } & XOR< + { + space: Room; + }, + { + spaceKey: SpaceKey; + } + >; + +export const SpaceButton: React.FC> = ({ space, spaceKey, className, @@ -92,9 +101,9 @@ export const SpaceButton: React.FC = ({ } let notifBadge; - if (space && notificationState) { + if (notificationState) { let ariaLabel = _t("Jump to first unread room."); - if (space.getMyMembership() === "invite") { + if (space?.getMyMembership() === "invite") { ariaLabel = _t("Jump to first invite."); } diff --git a/test/components/views/spaces/SpaceTreeLevel-test.tsx b/test/components/views/spaces/SpaceTreeLevel-test.tsx index a44a09dfd4c1..f28cf18d4fe7 100644 --- a/test/components/views/spaces/SpaceTreeLevel-test.tsx +++ b/test/components/views/spaces/SpaceTreeLevel-test.tsx @@ -17,7 +17,7 @@ limitations under the License. import React from "react"; import { fireEvent, getByTestId, render } from "@testing-library/react"; -import { stubClient, mkRoom } from "../../../test-utils"; +import { mkRoom, stubClient } from "../../../test-utils"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import DMRoomMap from "../../../../src/utils/DMRoomMap"; import defaultDispatcher from "../../../../src/dispatcher/dispatcher"; @@ -25,6 +25,8 @@ import { Action } from "../../../../src/dispatcher/actions"; import { SpaceButton } from "../../../../src/components/views/spaces/SpaceTreeLevel"; import { MetaSpace, SpaceKey } from "../../../../src/stores/spaces"; import SpaceStore from "../../../../src/stores/spaces/SpaceStore"; +import { StaticNotificationState } from "../../../../src/stores/notifications/StaticNotificationState"; +import { NotificationColor } from "../../../../src/stores/notifications/NotificationColor"; jest.mock("../../../../src/stores/spaces/SpaceStore", () => { // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -99,5 +101,22 @@ describe("SpaceButton", () => { // Re-activating the metaspace is a no-op expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith(MetaSpace.People); }); + + it("should render notificationState if one is provided", () => { + const notificationState = new StaticNotificationState(null, 8, NotificationColor.Grey); + + const { container, asFragment } = render( + , + ); + + expect(container.querySelector(".mx_NotificationBadge_count")).toHaveTextContent("8"); + expect(asFragment()).toMatchSnapshot(); + }); }); }); diff --git a/test/components/views/spaces/__snapshots__/SpaceTreeLevel-test.tsx.snap b/test/components/views/spaces/__snapshots__/SpaceTreeLevel-test.tsx.snap new file mode 100644 index 000000000000..427ba7016b9a --- /dev/null +++ b/test/components/views/spaces/__snapshots__/SpaceTreeLevel-test.tsx.snap @@ -0,0 +1,49 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SpaceButton metaspace should render notificationState if one is provided 1`] = ` + +
+
+
+
+
+
+
+
+ + 8 + +
+
+
+ + People + +
+
+ +`;