@@ -19,6 +19,7 @@ import {
1919 ClientEvent ,
2020 EventTimelineSet ,
2121 EventType ,
22+ LOCAL_NOTIFICATION_SETTINGS_PREFIX ,
2223 MatrixClient ,
2324 MatrixEvent ,
2425 MatrixEventEvent ,
@@ -89,6 +90,7 @@ describe("VoiceBroadcastRecording", () => {
8990 let voiceBroadcastRecording : VoiceBroadcastRecording ;
9091 let onStateChanged : ( state : VoiceBroadcastRecordingState ) => void ;
9192 let voiceBroadcastRecorder : VoiceBroadcastRecorder ;
93+ let audioElement : HTMLAudioElement ;
9294
9395 const mkVoiceBroadcastInfoEvent = ( content : VoiceBroadcastInfoEventContent ) => {
9496 return mkEvent ( {
@@ -251,6 +253,18 @@ describe("VoiceBroadcastRecording", () => {
251253 } ;
252254 } ,
253255 ) ;
256+
257+ audioElement = {
258+ play : jest . fn ( ) ,
259+ } as any as HTMLAudioElement ;
260+
261+ jest . spyOn ( document , "querySelector" ) . mockImplementation ( ( selector : string ) => {
262+ if ( selector === "audio#messageAudio" ) {
263+ return audioElement ;
264+ }
265+
266+ return null ;
267+ } ) ;
254268 } ) ;
255269
256270 afterEach ( ( ) => {
@@ -501,6 +515,33 @@ describe("VoiceBroadcastRecording", () => {
501515 } ) ;
502516 } ) ;
503517
518+ describe ( "and audible notifications are disabled" , ( ) => {
519+ beforeEach ( ( ) => {
520+ const notificationSettings = mkEvent ( {
521+ event : true ,
522+ type : `${ LOCAL_NOTIFICATION_SETTINGS_PREFIX . name } .${ client . getDeviceId ( ) } ` ,
523+ user : client . getSafeUserId ( ) ,
524+ content : {
525+ is_silenced : true ,
526+ } ,
527+ } ) ;
528+ mocked ( client . getAccountData ) . mockReturnValue ( notificationSettings ) ;
529+ } ) ;
530+
531+ describe ( "and a chunk has been recorded and sending the voice message fails" , ( ) => {
532+ beforeEach ( ( ) => {
533+ mocked ( client . sendMessage ) . mockRejectedValue ( "Error" ) ;
534+ emitFirsChunkRecorded ( ) ;
535+ } ) ;
536+
537+ itShouldBeInState ( "connection_error" ) ;
538+
539+ it ( "should not play a notification" , ( ) => {
540+ expect ( audioElement . play ) . not . toHaveBeenCalled ( ) ;
541+ } ) ;
542+ } ) ;
543+ } ) ;
544+
504545 describe ( "and a chunk has been recorded and sending the voice message fails" , ( ) => {
505546 beforeEach ( ( ) => {
506547 mocked ( client . sendMessage ) . mockRejectedValue ( "Error" ) ;
@@ -509,6 +550,10 @@ describe("VoiceBroadcastRecording", () => {
509550
510551 itShouldBeInState ( "connection_error" ) ;
511552
553+ it ( "should play a notification" , ( ) => {
554+ expect ( audioElement . play ) . toHaveBeenCalled ( ) ;
555+ } ) ;
556+
512557 describe ( "and the connection is back" , ( ) => {
513558 beforeEach ( ( ) => {
514559 mocked ( client . sendMessage ) . mockClear ( ) ;
0 commit comments