@@ -563,15 +563,93 @@ describe('ChatComponent', () => {
563563
564564 describe ( 'when bidi streaming is restarted' , ( ) => {
565565 beforeEach ( ( ) => {
566- component . sessionHasUsedBidi . add ( component . sessionId ) ;
566+ component . startAudioRecording ( ) ;
567+ component . stopAudioRecording ( ) ;
567568 component . startAudioRecording ( ) ;
568569 } ) ;
569- it ( 'should show snackbar' , ( ) => {
570- expect ( mockSnackBar . open )
571- . toHaveBeenCalledWith (
572- 'Restarting bidirectional streaming is not currently supported. Please refresh the page or start a new session.' ,
573- OK_BUTTON_TEXT ,
574- ) ;
570+ it ( 'should allow restart without error' , ( ) => {
571+ expect ( component . isAudioRecording ) . toBe ( true ) ;
572+ expect ( mockStreamChatService . startAudioChat ) . toHaveBeenCalledTimes ( 2 ) ;
573+ } ) ;
574+ } ) ;
575+
576+ describe ( 'when audio recording is stopped and restarted' , ( ) => {
577+ beforeEach ( ( ) => {
578+ component . startAudioRecording ( ) ;
579+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( true ) ;
580+ component . stopAudioRecording ( ) ;
581+ } ) ;
582+
583+ it ( 'should remove session from sessionHasUsedBidi set' , ( ) => {
584+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( false ) ;
585+ } ) ;
586+
587+ it ( 'should allow restarting audio recording' , ( ) => {
588+ component . startAudioRecording ( ) ;
589+ expect ( mockSnackBar . open ) . not . toHaveBeenCalled ( ) ;
590+ expect ( component . isAudioRecording ) . toBe ( true ) ;
591+ } ) ;
592+ } ) ;
593+
594+ describe ( 'when video recording is stopped and restarted' , ( ) => {
595+ beforeEach ( ( ) => {
596+ component . startVideoRecording ( ) ;
597+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( true ) ;
598+ component . stopVideoRecording ( ) ;
599+ } ) ;
600+
601+ it ( 'should remove session from sessionHasUsedBidi set' , ( ) => {
602+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( false ) ;
603+ } ) ;
604+
605+ it ( 'should allow restarting video recording' , ( ) => {
606+ component . startVideoRecording ( ) ;
607+ expect ( mockSnackBar . open ) . not . toHaveBeenCalled ( ) ;
608+ expect ( component . isVideoRecording ) . toBe ( true ) ;
609+ } ) ;
610+ } ) ;
611+
612+ describe ( 'when trying to start concurrent bidi streams' , ( ) => {
613+ it ( 'should prevent starting audio while already recording' , ( ) => {
614+ component . startAudioRecording ( ) ;
615+ expect ( component . isAudioRecording ) . toBe ( true ) ;
616+
617+ component . startAudioRecording ( ) ;
618+
619+ expect ( mockSnackBar . open ) . toHaveBeenCalledWith (
620+ 'Another streaming request is already in progress. Please stop it before starting a new one.' ,
621+ 'OK'
622+ ) ;
623+ expect ( mockStreamChatService . startAudioChat ) . toHaveBeenCalledTimes ( 1 ) ;
624+ } ) ;
625+
626+ it ( 'should prevent starting video while already recording' , ( ) => {
627+ component . startVideoRecording ( ) ;
628+ expect ( component . isVideoRecording ) . toBe ( true ) ;
629+
630+ component . startVideoRecording ( ) ;
631+
632+ expect ( mockSnackBar . open ) . toHaveBeenCalledWith (
633+ 'Another streaming request is already in progress. Please stop it before starting a new one.' ,
634+ 'OK'
635+ ) ;
636+ expect ( mockStreamChatService . startVideoChat ) . toHaveBeenCalledTimes ( 1 ) ;
637+ } ) ;
638+ } ) ;
639+
640+ describe ( 'when stopping video recording without videoContainer' , ( ) => {
641+ it ( 'should still cleanup sessionHasUsedBidi' , ( ) => {
642+ component . startVideoRecording ( ) ;
643+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( true ) ;
644+
645+ spyOn ( component , 'chatPanel' ) . and . returnValue ( {
646+ videoContainer : undefined
647+ } as any ) ;
648+
649+ component . stopVideoRecording ( ) ;
650+
651+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( false ) ;
652+ expect ( component . isVideoRecording ) . toBe ( false ) ;
575653 } ) ;
576654 } ) ;
577655 } ) ;
0 commit comments