@@ -31,7 +31,7 @@ import {
31
31
VoiceBroadcastPlaybackState ,
32
32
VoiceBroadcastRecording ,
33
33
} from "../../../src/voice-broadcast" ;
34
- import { flushPromises , stubClient } from "../../test-utils" ;
34
+ import { filterConsole , flushPromises , stubClient } from "../../test-utils" ;
35
35
import { createTestPlayback } from "../../test-utils/audio" ;
36
36
import { mkVoiceBroadcastChunkEvent , mkVoiceBroadcastInfoStateEvent } from "../utils/test-utils" ;
37
37
@@ -64,6 +64,8 @@ describe("VoiceBroadcastPlayback", () => {
64
64
let chunk1Playback : Playback ;
65
65
let chunk2Playback : Playback ;
66
66
let chunk3Playback : Playback ;
67
+ let middleOfSecondChunk ! : number ;
68
+ let middleOfThirdChunk ! : number ;
67
69
68
70
const queryConfirmListeningDialog = ( ) => {
69
71
return screen . queryByText (
@@ -164,6 +166,9 @@ describe("VoiceBroadcastPlayback", () => {
164
166
chunk2Playback = createTestPlayback ( ) ;
165
167
chunk3Playback = createTestPlayback ( ) ;
166
168
169
+ middleOfSecondChunk = ( chunk1Length + chunk2Length / 2 ) / 1000 ;
170
+ middleOfThirdChunk = ( chunk1Length + chunk2Length + chunk3Length / 2 ) / 1000 ;
171
+
167
172
jest . spyOn ( PlaybackManager . instance , "createPlaybackInstance" ) . mockImplementation (
168
173
( buffer : ArrayBuffer , _waveForm ?: number [ ] ) => {
169
174
if ( buffer === chunk1Data ) return chunk1Playback ;
@@ -181,10 +186,11 @@ describe("VoiceBroadcastPlayback", () => {
181
186
} ) ;
182
187
} ;
183
188
189
+ filterConsole ( "Starting load of AsyncWrapper for modal" ) ;
190
+
184
191
beforeEach ( ( ) => {
185
192
client = stubClient ( ) ;
186
193
deviceId = client . getDeviceId ( ) || "" ;
187
- jest . clearAllMocks ( ) ;
188
194
room = new Room ( roomId , client , client . getSafeUserId ( ) ) ;
189
195
mocked ( client . getRoom ) . mockImplementation ( ( roomId : string ) : Room | null => {
190
196
if ( roomId === room . roomId ) return room ;
@@ -425,8 +431,8 @@ describe("VoiceBroadcastPlayback", () => {
425
431
beforeEach ( async ( ) => {
426
432
infoEvent = mkInfoEvent ( VoiceBroadcastInfoState . Stopped ) ;
427
433
createChunkEvents ( ) ;
428
- setUpChunkEvents ( [ chunk2Event , chunk1Event ] ) ;
429
- room . addLiveEvents ( [ infoEvent , chunk1Event , chunk2Event ] ) ;
434
+ setUpChunkEvents ( [ chunk2Event , chunk1Event , chunk3Event ] ) ;
435
+ room . addLiveEvents ( [ infoEvent , chunk1Event , chunk2Event , chunk3Event ] ) ;
430
436
playback = await mkPlayback ( ) ;
431
437
} ) ;
432
438
@@ -472,6 +478,7 @@ describe("VoiceBroadcastPlayback", () => {
472
478
473
479
it ( "should play the second chunk" , ( ) => {
474
480
expect ( chunk1Playback . stop ) . toHaveBeenCalled ( ) ;
481
+ expect ( chunk1Playback . destroy ) . toHaveBeenCalled ( ) ;
475
482
expect ( chunk2Playback . play ) . toHaveBeenCalled ( ) ;
476
483
} ) ;
477
484
@@ -484,9 +491,10 @@ describe("VoiceBroadcastPlayback", () => {
484
491
await playback . skipTo ( 0 ) ;
485
492
} ) ;
486
493
487
- it ( "should play the second chunk" , ( ) => {
488
- expect ( chunk1Playback . play ) . toHaveBeenCalled ( ) ;
494
+ it ( "should play the first chunk" , ( ) => {
489
495
expect ( chunk2Playback . stop ) . toHaveBeenCalled ( ) ;
496
+ expect ( chunk2Playback . destroy ) . toHaveBeenCalled ( ) ;
497
+ expect ( chunk1Playback . play ) . toHaveBeenCalled ( ) ;
490
498
} ) ;
491
499
492
500
it ( "should update the time" , ( ) => {
@@ -495,6 +503,28 @@ describe("VoiceBroadcastPlayback", () => {
495
503
} ) ;
496
504
} ) ;
497
505
506
+ describe ( "and skipping multiple times" , ( ) => {
507
+ beforeEach ( async ( ) => {
508
+ return Promise . all ( [
509
+ playback . skipTo ( middleOfSecondChunk ) ,
510
+ playback . skipTo ( middleOfThirdChunk ) ,
511
+ playback . skipTo ( 0 ) ,
512
+ ] ) ;
513
+ } ) ;
514
+
515
+ it ( "should only skip to the first and last position" , ( ) => {
516
+ expect ( chunk1Playback . stop ) . toHaveBeenCalled ( ) ;
517
+ expect ( chunk1Playback . destroy ) . toHaveBeenCalled ( ) ;
518
+ expect ( chunk2Playback . play ) . toHaveBeenCalled ( ) ;
519
+
520
+ expect ( chunk3Playback . play ) . not . toHaveBeenCalled ( ) ;
521
+
522
+ expect ( chunk2Playback . stop ) . toHaveBeenCalled ( ) ;
523
+ expect ( chunk2Playback . destroy ) . toHaveBeenCalled ( ) ;
524
+ expect ( chunk1Playback . play ) . toHaveBeenCalled ( ) ;
525
+ } ) ;
526
+ } ) ;
527
+
498
528
describe ( "and the first chunk ends" , ( ) => {
499
529
beforeEach ( ( ) => {
500
530
chunk1Playback . emit ( PlaybackState . Stopped ) ;
@@ -507,8 +537,9 @@ describe("VoiceBroadcastPlayback", () => {
507
537
// assert that the second chunk is being played
508
538
expect ( chunk2Playback . play ) . toHaveBeenCalled ( ) ;
509
539
510
- // simulate end of second chunk
540
+ // simulate end of second and third chunk
511
541
chunk2Playback . emit ( PlaybackState . Stopped ) ;
542
+ chunk3Playback . emit ( PlaybackState . Stopped ) ;
512
543
513
544
// assert that the entire playback is now in stopped state
514
545
expect ( playback . getState ( ) ) . toBe ( VoiceBroadcastPlaybackState . Stopped ) ;
0 commit comments