@@ -17,6 +17,7 @@ import {
17
17
import type { MatrixClient , Room } from "matrix-js-sdk/src/matrix" ;
18
18
import { mkRoom , stubClient } from "../../../../../test-utils" ;
19
19
import { RoomListItemMenuView } from "../../../../../../src/components/views/rooms/RoomListPanel/RoomListItemMenuView" ;
20
+ import { RoomNotifState } from "../../../../../../src/RoomNotifs" ;
20
21
21
22
jest . mock ( "../../../../../../src/components/viewmodels/roomlist/RoomListItemMenuViewModel" , ( ) => ( {
22
23
useRoomListItemMenuViewModel : jest . fn ( ) ,
@@ -25,18 +26,24 @@ jest.mock("../../../../../../src/components/viewmodels/roomlist/RoomListItemMenu
25
26
describe ( "<RoomListItemMenuView />" , ( ) => {
26
27
const defaultValue : RoomListItemMenuViewState = {
27
28
showMoreOptionsMenu : true ,
29
+ showNotificationMenu : true ,
28
30
isFavourite : true ,
29
31
canInvite : true ,
30
32
canMarkAsUnread : true ,
31
33
canMarkAsRead : true ,
32
34
canCopyRoomLink : true ,
35
+ isNotificationAllMessage : true ,
36
+ isNotificationMentionOnly : true ,
37
+ isNotificationAllMessageLoud : true ,
38
+ isNotificationMute : true ,
33
39
copyRoomLink : jest . fn ( ) ,
34
40
markAsUnread : jest . fn ( ) ,
35
41
markAsRead : jest . fn ( ) ,
36
42
leaveRoom : jest . fn ( ) ,
37
43
toggleLowPriority : jest . fn ( ) ,
38
44
toggleFavorite : jest . fn ( ) ,
39
45
invite : jest . fn ( ) ,
46
+ setRoomNotifState : jest . fn ( ) ,
40
47
} ;
41
48
42
49
let matrixClient : MatrixClient ;
@@ -58,22 +65,37 @@ describe("<RoomListItemMenuView />", () => {
58
65
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
59
66
} ) ;
60
67
68
+ it ( "should render the notification options menu" , ( ) => {
69
+ const { asFragment } = renderMenu ( ) ;
70
+ expect ( screen . getByRole ( "button" , { name : "Notification options" } ) ) . toBeInTheDocument ( ) ;
71
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
72
+ } ) ;
73
+
61
74
it ( "should not render the more options menu when showMoreOptionsMenu is false" , ( ) => {
62
75
mocked ( useRoomListItemMenuViewModel ) . mockReturnValue ( { ...defaultValue , showMoreOptionsMenu : false } ) ;
63
76
renderMenu ( ) ;
64
77
expect ( screen . queryByRole ( "button" , { name : "More Options" } ) ) . toBeNull ( ) ;
65
78
} ) ;
66
79
67
- it ( "should call setMenuOpen when the menu is opened" , async ( ) => {
68
- const user = userEvent . setup ( ) ;
69
- const setMenuOpen = jest . fn ( ) ;
70
- renderMenu ( setMenuOpen ) ;
71
-
72
- await user . click ( screen . getByRole ( "button" , { name : "More Options" } ) ) ;
73
- expect ( setMenuOpen ) . toHaveBeenCalledWith ( true ) ;
80
+ it ( "should not render the notification options menu when showNotificationMenu is false" , ( ) => {
81
+ mocked ( useRoomListItemMenuViewModel ) . mockReturnValue ( { ...defaultValue , showNotificationMenu : false } ) ;
82
+ renderMenu ( ) ;
83
+ expect ( screen . queryByRole ( "button" , { name : "Notification options" } ) ) . toBeNull ( ) ;
74
84
} ) ;
75
85
76
- it ( "should display all the buttons and have the actions linked" , async ( ) => {
86
+ it . each ( [ [ "More Options" ] , [ "Notification options" ] ] ) (
87
+ "should call setMenuOpen when the menu is opened for %s menu" ,
88
+ async ( label ) => {
89
+ const user = userEvent . setup ( ) ;
90
+ const setMenuOpen = jest . fn ( ) ;
91
+ renderMenu ( setMenuOpen ) ;
92
+
93
+ await user . click ( screen . getByRole ( "button" , { name : label } ) ) ;
94
+ expect ( setMenuOpen ) . toHaveBeenCalledWith ( true ) ;
95
+ } ,
96
+ ) ;
97
+
98
+ it ( "should display all the buttons and have the actions linked for the more options menu" , async ( ) => {
77
99
const user = userEvent . setup ( ) ;
78
100
renderMenu ( ) ;
79
101
@@ -107,4 +129,27 @@ describe("<RoomListItemMenuView />", () => {
107
129
await user . click ( screen . getByRole ( "menuitem" , { name : "Leave room" } ) ) ;
108
130
expect ( defaultValue . leaveRoom ) . toHaveBeenCalled ( ) ;
109
131
} ) ;
132
+
133
+ it ( "should display all the buttons and have the actions linked for the notification options menu" , async ( ) => {
134
+ const user = userEvent . setup ( ) ;
135
+ renderMenu ( ) ;
136
+
137
+ const openMenu = screen . getByRole ( "button" , { name : "Notification options" } ) ;
138
+ await user . click ( openMenu ) ;
139
+
140
+ await user . click ( screen . getByRole ( "menuitem" , { name : "Match default settings" } ) ) ;
141
+ expect ( defaultValue . setRoomNotifState ) . toHaveBeenCalledWith ( RoomNotifState . AllMessages ) ;
142
+
143
+ await user . click ( openMenu ) ;
144
+ await user . click ( screen . getByRole ( "menuitem" , { name : "All messages" } ) ) ;
145
+ expect ( defaultValue . setRoomNotifState ) . toHaveBeenCalledWith ( RoomNotifState . AllMessagesLoud ) ;
146
+
147
+ await user . click ( openMenu ) ;
148
+ await user . click ( screen . getByRole ( "menuitem" , { name : "Mentions and keywords" } ) ) ;
149
+ expect ( defaultValue . setRoomNotifState ) . toHaveBeenCalledWith ( RoomNotifState . MentionsOnly ) ;
150
+
151
+ await user . click ( openMenu ) ;
152
+ await user . click ( screen . getByRole ( "menuitem" , { name : "Mute room" } ) ) ;
153
+ expect ( defaultValue . setRoomNotifState ) . toHaveBeenCalledWith ( RoomNotifState . Mute ) ;
154
+ } ) ;
110
155
} ) ;
0 commit comments