Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f8c809b

Browse files
committed
Fix missing metaspace notification badges
1 parent 69c785c commit f8c809b

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

src/components/views/spaces/SpaceTreeLevel.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import SpaceContextMenu from "../context_menus/SpaceContextMenu";
4747
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
4848
import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
4949
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
50+
import { XOR } from "../../../@types/common";
5051

5152
interface IButtonProps extends Omit<ComponentProps<typeof AccessibleTooltipButton>, "title" | "onClick"> {
5253
space?: Room;
@@ -55,15 +56,23 @@ interface IButtonProps extends Omit<ComponentProps<typeof AccessibleTooltipButto
5556
selected?: boolean;
5657
label: string;
5758
contextMenuTooltip?: string;
58-
notificationState?: NotificationState;
5959
isNarrow?: boolean;
6060
avatarSize?: number;
6161
innerRef?: RefObject<HTMLElement>;
6262
ContextMenuComponent?: ComponentType<ComponentProps<typeof SpaceContextMenu>>;
6363
onClick?(ev?: ButtonEvent): void;
6464
}
6565

66-
export const SpaceButton: React.FC<IButtonProps> = ({
66+
type ButtonPropsWithNotification = IButtonProps & { notificationState: NotificationState } & XOR<
67+
{
68+
space: Room;
69+
},
70+
{
71+
spaceKey: SpaceKey;
72+
}
73+
>;
74+
75+
export const SpaceButton: React.FC<XOR<ButtonPropsWithNotification, IButtonProps>> = ({
6776
space,
6877
spaceKey,
6978
className,
@@ -92,9 +101,9 @@ export const SpaceButton: React.FC<IButtonProps> = ({
92101
}
93102

94103
let notifBadge;
95-
if (space && notificationState) {
104+
if (notificationState) {
96105
let ariaLabel = _t("Jump to first unread room.");
97-
if (space.getMyMembership() === "invite") {
106+
if (space?.getMyMembership() === "invite") {
98107
ariaLabel = _t("Jump to first invite.");
99108
}
100109

test/components/views/spaces/SpaceTreeLevel-test.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ limitations under the License.
1717
import React from "react";
1818
import { fireEvent, getByTestId, render } from "@testing-library/react";
1919

20-
import { stubClient, mkRoom } from "../../../test-utils";
20+
import { mkRoom, stubClient } from "../../../test-utils";
2121
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
2222
import DMRoomMap from "../../../../src/utils/DMRoomMap";
2323
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
2424
import { Action } from "../../../../src/dispatcher/actions";
2525
import { SpaceButton } from "../../../../src/components/views/spaces/SpaceTreeLevel";
2626
import { MetaSpace, SpaceKey } from "../../../../src/stores/spaces";
2727
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
28+
import { StaticNotificationState } from "../../../../src/stores/notifications/StaticNotificationState";
29+
import { NotificationColor } from "../../../../src/stores/notifications/NotificationColor";
2830

2931
jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
3032
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -99,5 +101,22 @@ describe("SpaceButton", () => {
99101
// Re-activating the metaspace is a no-op
100102
expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith(MetaSpace.People);
101103
});
104+
105+
it("should render notificationState if one is provided", () => {
106+
const notificationState = new StaticNotificationState(null, 8, NotificationColor.Grey);
107+
108+
const { container, asFragment } = render(
109+
<SpaceButton
110+
spaceKey={MetaSpace.People}
111+
selected={true}
112+
label="People"
113+
data-testid="create-space-button"
114+
notificationState={notificationState}
115+
/>,
116+
);
117+
118+
expect(container.querySelector(".mx_NotificationBadge_count")).toHaveTextContent("8");
119+
expect(asFragment()).toMatchSnapshot();
120+
});
102121
});
103122
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`SpaceButton metaspace should render notificationState if one is provided 1`] = `
4+
<DocumentFragment>
5+
<div
6+
aria-label="People"
7+
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_active"
8+
data-testid="create-space-button"
9+
role="button"
10+
tabindex="-1"
11+
>
12+
<div
13+
class="mx_SpaceButton_selectionWrapper"
14+
>
15+
<div
16+
class="mx_SpaceButton_avatarWrapper"
17+
>
18+
<div
19+
class="mx_SpaceButton_avatarPlaceholder"
20+
>
21+
<div
22+
class="mx_SpaceButton_icon"
23+
/>
24+
</div>
25+
<div
26+
class="mx_SpacePanel_badgeContainer"
27+
>
28+
<div
29+
class="mx_AccessibleButton mx_NotificationBadge mx_NotificationBadge_visible mx_NotificationBadge_2char"
30+
role="button"
31+
tabindex="-1"
32+
>
33+
<span
34+
class="mx_NotificationBadge_count"
35+
>
36+
8
37+
</span>
38+
</div>
39+
</div>
40+
</div>
41+
<span
42+
class="mx_SpaceButton_name"
43+
>
44+
People
45+
</span>
46+
</div>
47+
</div>
48+
</DocumentFragment>
49+
`;

0 commit comments

Comments
 (0)