@@ -114,31 +114,51 @@ describe("notifications", () => {
114114 let sendReadReceiptSpy : jest . SpyInstance ;
115115 const ROOM_ID = "123" ;
116116 const USER_ID = "@bob:example.org" ;
117+ let message : MatrixEvent ;
118+ let sendReceiptsSetting = true ;
117119
118120 beforeEach ( ( ) => {
119121 stubClient ( ) ;
120122 client = mocked ( MatrixClientPeg . get ( ) ) ;
121123 room = new Room ( ROOM_ID , client , USER_ID ) ;
124+ message = mkMessage ( {
125+ event : true ,
126+ room : ROOM_ID ,
127+ user : USER_ID ,
128+ msg : "Hello" ,
129+ } ) ;
130+ room . addLiveEvents ( [ message ] ) ;
122131 sendReadReceiptSpy = jest . spyOn ( client , "sendReadReceipt" ) . mockResolvedValue ( { } ) ;
123132 jest . spyOn ( client , "getRooms" ) . mockReturnValue ( [ room ] ) ;
124133 jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation ( ( name ) => {
125- return name === "sendReadReceipts" ;
134+ return name === "sendReadReceipts" && sendReceiptsSetting ;
126135 } ) ;
127136 } ) ;
128137
129138 it ( "sends a request even if everything has been read" , ( ) => {
130139 clearRoomNotification ( room , client ) ;
131- expect ( sendReadReceiptSpy ) . not . toHaveBeenCalled ( ) ;
140+ expect ( sendReadReceiptSpy ) . toHaveBeenCalledWith ( message , ReceiptType . Read , true ) ;
132141 } ) ;
133142
134143 it ( "marks the room as read even if the receipt failed" , async ( ) => {
135144 room . setUnreadNotificationCount ( NotificationCountType . Total , 5 ) ;
136- sendReadReceiptSpy = jest . spyOn ( client , "sendReadReceipt" ) . mockReset ( ) . mockRejectedValue ( { } ) ;
137- try {
145+ sendReadReceiptSpy = jest . spyOn ( client , "sendReadReceipt" ) . mockReset ( ) . mockRejectedValue ( { error : 42 } ) ;
146+
147+ await expect ( async ( ) => {
138148 await clearRoomNotification ( room , client ) ;
139- } finally {
140- expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 0 ) ;
141- }
149+ } ) . rejects . toEqual ( { error : 42 } ) ;
150+ expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 0 ) ;
151+ } ) ;
152+
153+ describe ( "when sendReadReceipts setting is disabled" , ( ) => {
154+ beforeEach ( ( ) => {
155+ sendReceiptsSetting = false ;
156+ } ) ;
157+
158+ it ( "should send a private read receipt" , ( ) => {
159+ clearRoomNotification ( room , client ) ;
160+ expect ( sendReadReceiptSpy ) . toHaveBeenCalledWith ( message , ReceiptType . ReadPrivate , true ) ;
161+ } ) ;
142162 } ) ;
143163 } ) ;
144164
0 commit comments