@@ -11,23 +11,33 @@ import { type MatrixClient, type Room } from "matrix-js-sdk/src/matrix";
11
11
12
12
import { mkStubRoom , stubClient , withClientContextRenderOptions } from "../../../../test-utils" ;
13
13
import { useRoomListItemMenuViewModel } from "../../../../../src/components/viewmodels/roomlist/RoomListItemMenuViewModel" ;
14
- import { hasAccessToOptionsMenu } from "../../../../../src/components/viewmodels/roomlist/utils" ;
14
+ import {
15
+ hasAccessToNotificationMenu ,
16
+ hasAccessToOptionsMenu ,
17
+ } from "../../../../../src/components/viewmodels/roomlist/utils" ;
15
18
import DMRoomMap from "../../../../../src/utils/DMRoomMap" ;
16
19
import { DefaultTagID } from "../../../../../src/stores/room-list/models" ;
17
20
import { useUnreadNotifications } from "../../../../../src/hooks/useUnreadNotifications" ;
18
21
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel" ;
19
22
import { clearRoomNotification , setMarkedUnreadState } from "../../../../../src/utils/notifications" ;
20
23
import { tagRoom } from "../../../../../src/utils/room/tagRoom" ;
21
24
import dispatcher from "../../../../../src/dispatcher/dispatcher" ;
25
+ import { useNotificationState } from "../../../../../src/hooks/useRoomNotificationState" ;
26
+ import { RoomNotifState } from "../../../../../src/RoomNotifs" ;
22
27
23
28
jest . mock ( "../../../../../src/components/viewmodels/roomlist/utils" , ( ) => ( {
24
29
hasAccessToOptionsMenu : jest . fn ( ) . mockReturnValue ( false ) ,
30
+ hasAccessToNotificationMenu : jest . fn ( ) . mockReturnValue ( false ) ,
25
31
} ) ) ;
26
32
27
33
jest . mock ( "../../../../../src/hooks/useUnreadNotifications" , ( ) => ( {
28
34
useUnreadNotifications : jest . fn ( ) ,
29
35
} ) ) ;
30
36
37
+ jest . mock ( "../../../../../src/hooks/useRoomNotificationState" , ( ) => ( {
38
+ useNotificationState : jest . fn ( ) ,
39
+ } ) ) ;
40
+
31
41
jest . mock ( "../../../../../src/utils/notifications" , ( ) => ( {
32
42
clearRoomNotification : jest . fn ( ) ,
33
43
setMarkedUnreadState : jest . fn ( ) ,
@@ -49,6 +59,7 @@ describe("RoomListItemMenuViewModel", () => {
49
59
jest . spyOn ( DMRoomMap . shared ( ) , "getUserIdForRoomId" ) . mockReturnValue ( null ) ;
50
60
51
61
mocked ( useUnreadNotifications ) . mockReturnValue ( { symbol : null , count : 0 , level : NotificationLevel . None } ) ;
62
+ mocked ( useNotificationState ) . mockReturnValue ( [ RoomNotifState . AllMessages , jest . fn ( ) ] ) ;
52
63
jest . spyOn ( dispatcher , "dispatch" ) ;
53
64
} ) ;
54
65
@@ -76,6 +87,12 @@ describe("RoomListItemMenuViewModel", () => {
76
87
expect ( result . current . showMoreOptionsMenu ) . toBe ( true ) ;
77
88
} ) ;
78
89
90
+ it ( "should has showNotificationMenu to be true" , ( ) => {
91
+ mocked ( hasAccessToNotificationMenu ) . mockReturnValue ( true ) ;
92
+ const { result } = render ( ) ;
93
+ expect ( result . current . showNotificationMenu ) . toBe ( true ) ;
94
+ } ) ;
95
+
79
96
it ( "should be able to invite" , ( ) => {
80
97
jest . spyOn ( room , "canInvite" ) . mockReturnValue ( true ) ;
81
98
const { result } = render ( ) ;
@@ -106,6 +123,29 @@ describe("RoomListItemMenuViewModel", () => {
106
123
expect ( result . current . canMarkAsUnread ) . toBe ( false ) ;
107
124
} ) ;
108
125
126
+ it ( "should has isNotificationAllMessage to be true" , ( ) => {
127
+ const { result } = render ( ) ;
128
+ expect ( result . current . isNotificationAllMessage ) . toBe ( true ) ;
129
+ } ) ;
130
+
131
+ it ( "should has isNotificationAllMessageLoud to be true" , ( ) => {
132
+ mocked ( useNotificationState ) . mockReturnValue ( [ RoomNotifState . AllMessagesLoud , jest . fn ( ) ] ) ;
133
+ const { result } = render ( ) ;
134
+ expect ( result . current . isNotificationAllMessageLoud ) . toBe ( true ) ;
135
+ } ) ;
136
+
137
+ it ( "should has isNotificationMentionOnly to be true" , ( ) => {
138
+ mocked ( useNotificationState ) . mockReturnValue ( [ RoomNotifState . MentionsOnly , jest . fn ( ) ] ) ;
139
+ const { result } = render ( ) ;
140
+ expect ( result . current . isNotificationMentionOnly ) . toBe ( true ) ;
141
+ } ) ;
142
+
143
+ it ( "should has isNotificationMute to be true" , ( ) => {
144
+ mocked ( useNotificationState ) . mockReturnValue ( [ RoomNotifState . Mute , jest . fn ( ) ] ) ;
145
+ const { result } = render ( ) ;
146
+ expect ( result . current . isNotificationMute ) . toBe ( true ) ;
147
+ } ) ;
148
+
109
149
// Actions
110
150
111
151
it ( "should mark as read" , ( ) => {
@@ -170,4 +210,12 @@ describe("RoomListItemMenuViewModel", () => {
170
210
room_id : room . roomId ,
171
211
} ) ;
172
212
} ) ;
213
+
214
+ it ( "should call setRoomNotifState" , ( ) => {
215
+ const setRoomNotifState = jest . fn ( ) ;
216
+ mocked ( useNotificationState ) . mockReturnValue ( [ RoomNotifState . AllMessages , setRoomNotifState ] ) ;
217
+ const { result } = render ( ) ;
218
+ result . current . setRoomNotifState ( RoomNotifState . Mute ) ;
219
+ expect ( setRoomNotifState ) . toHaveBeenCalledWith ( RoomNotifState . Mute ) ;
220
+ } ) ;
173
221
} ) ;
0 commit comments