forked from element-hq/element-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomListItemNotificationMenu.test.tsx
More file actions
164 lines (127 loc) · 6.3 KB
/
RoomListItemNotificationMenu.test.tsx
File metadata and controls
164 lines (127 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import React, { type JSX } from "react";
import { render, screen } from "@test-utils";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi } from "vitest";
import { RoomListItemNotificationMenu } from "./RoomListItemNotificationMenu";
import { RoomNotifState } from "./RoomNotifs";
import { useMockedViewModel } from "../../../../core/viewmodel";
import type { RoomListItemViewSnapshot } from "./RoomListItemView";
import { defaultSnapshot } from "./default-snapshot";
describe("<RoomListItemNotificationMenu />", () => {
const mockCallbacks = {
onOpenRoom: vi.fn(),
onMarkAsRead: vi.fn(),
onMarkAsUnread: vi.fn(),
onToggleFavorite: vi.fn(),
onToggleLowPriority: vi.fn(),
onInvite: vi.fn(),
onCopyRoomLink: vi.fn(),
onLeaveRoom: vi.fn(),
onSetRoomNotifState: vi.fn(),
};
const renderMenu = (roomNotifState: RoomNotifState = RoomNotifState.AllMessages): ReturnType<typeof render> => {
const TestComponent = (): JSX.Element => {
const vm = useMockedViewModel(
{
...defaultSnapshot,
showMoreOptionsMenu: false,
showNotificationMenu: true,
roomNotifState,
} as RoomListItemViewSnapshot,
mockCallbacks,
);
return <RoomListItemNotificationMenu vm={vm} />;
};
return render(<TestComponent />);
};
it("should render the notification menu button", () => {
renderMenu();
expect(screen.getByRole("button", { name: "Notification options" })).toBeInTheDocument();
});
it("should show muted icon when notifications are muted", () => {
renderMenu(RoomNotifState.Mute);
const button = screen.getByRole("button", { name: "Notification options" });
expect(button.querySelector("svg")).toBeInTheDocument();
});
it("should open menu when clicked", async () => {
const user = userEvent.setup();
renderMenu();
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
expect(screen.getByRole("menu")).toBeInTheDocument();
});
it("should call onSetRoomNotifState with AllMessages when default settings selected", async () => {
const user = userEvent.setup();
renderMenu();
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const defaultOption = screen.getByRole("menuitem", { name: "Match default settings" });
await user.click(defaultOption);
expect(mockCallbacks.onSetRoomNotifState).toHaveBeenCalledWith(RoomNotifState.AllMessages);
});
it("should call onSetRoomNotifState with AllMessagesLoud when all messages selected", async () => {
const user = userEvent.setup();
renderMenu();
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const allMessagesOption = screen.getByRole("menuitem", { name: "All messages" });
await user.click(allMessagesOption);
expect(mockCallbacks.onSetRoomNotifState).toHaveBeenCalledWith(RoomNotifState.AllMessagesLoud);
});
it("should call onSetRoomNotifState with MentionsOnly when mentions and keywords selected", async () => {
const user = userEvent.setup();
renderMenu();
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const mentionsOption = screen.getByRole("menuitem", { name: "Mentions and keywords" });
await user.click(mentionsOption);
expect(mockCallbacks.onSetRoomNotifState).toHaveBeenCalledWith(RoomNotifState.MentionsOnly);
});
it("should call onSetRoomNotifState with Mute when mute selected", async () => {
const user = userEvent.setup();
renderMenu();
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const muteOption = screen.getByRole("menuitem", { name: "Mute room" });
await user.click(muteOption);
expect(mockCallbacks.onSetRoomNotifState).toHaveBeenCalledWith(RoomNotifState.Mute);
});
it("should show check mark next to selected option - AllMessage", async () => {
const user = userEvent.setup();
renderMenu(RoomNotifState.AllMessages);
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const defaultOption = screen.getByRole("menuitem", { name: "Match default settings" });
expect(defaultOption).toHaveAttribute("aria-selected", "true");
});
it("should show check mark next to selected option - AllMessagesLoud", async () => {
const user = userEvent.setup();
renderMenu(RoomNotifState.AllMessagesLoud);
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const allMessagesOption = screen.getByRole("menuitem", { name: "All messages" });
expect(allMessagesOption).toHaveAttribute("aria-selected", "true");
});
it("should show check mark next to selected option - MentionsOnly", async () => {
const user = userEvent.setup();
renderMenu(RoomNotifState.MentionsOnly);
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const mentionsOption = screen.getByRole("menuitem", { name: "Mentions and keywords" });
expect(mentionsOption).toHaveAttribute("aria-selected", "true");
});
it("should show check mark next to selected option - Mute", async () => {
const user = userEvent.setup();
renderMenu(RoomNotifState.Mute);
const button = screen.getByRole("button", { name: "Notification options" });
await user.click(button);
const muteOption = screen.getByRole("menuitem", { name: "Mute room" });
expect(muteOption).toHaveAttribute("aria-selected", "true");
});
});