@@ -806,15 +806,92 @@ describe('ChatComponent', () => {
806806
807807 describe ( 'when bidi streaming is restarted' , ( ) => {
808808 beforeEach ( ( ) => {
809- component . sessionHasUsedBidi . add ( component . sessionId ) ;
809+ component . startAudioRecording ( ) ;
810+ component . stopAudioRecording ( ) ;
810811 component . startAudioRecording ( ) ;
811812 } ) ;
812- it ( 'should show snackbar' , ( ) => {
813- expect ( mockSnackBar . open )
814- . toHaveBeenCalledWith (
815- 'Restarting bidirectional streaming is not currently supported. Please refresh the page or start a new session.' ,
816- OK_BUTTON_TEXT ,
817- ) ;
813+ it ( 'should allow restart without error' , ( ) => {
814+ expect ( component . isAudioRecording ) . toBe ( true ) ;
815+ expect ( mockStreamChatService . startAudioChat ) . toHaveBeenCalledTimes ( 2 ) ;
816+ } ) ;
817+ } ) ;
818+
819+ describe ( 'when audio recording is stopped and restarted' , ( ) => {
820+ beforeEach ( ( ) => {
821+ component . startAudioRecording ( ) ;
822+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( true ) ;
823+ component . stopAudioRecording ( ) ;
824+ } ) ;
825+ it ( 'should remove session from sessionHasUsedBidi set' , ( ) => {
826+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( false ) ;
827+ } ) ;
828+
829+ it ( 'should allow restarting audio recording' , ( ) => {
830+ component . startAudioRecording ( ) ;
831+ expect ( mockSnackBar . open ) . not . toHaveBeenCalled ( ) ;
832+ expect ( component . isAudioRecording ) . toBe ( true ) ;
833+ } ) ;
834+ } ) ;
835+
836+ describe ( 'when video recording is stopped and restarted' , ( ) => {
837+ beforeEach ( ( ) => {
838+ component . startVideoRecording ( ) ;
839+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( true ) ;
840+ component . stopVideoRecording ( ) ;
841+ } ) ;
842+
843+ it ( 'should remove session from sessionHasUsedBidi set' , ( ) => {
844+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( false ) ;
845+ } ) ;
846+
847+ it ( 'should allow restarting video recording' , ( ) => {
848+ component . startVideoRecording ( ) ;
849+ expect ( mockSnackBar . open ) . not . toHaveBeenCalled ( ) ;
850+ expect ( component . isVideoRecording ) . toBe ( true ) ;
851+ } ) ;
852+ } ) ;
853+
854+ describe ( 'when trying to start concurrent bidi streams' , ( ) => {
855+ it ( 'should prevent starting audio while already recording' , ( ) => {
856+ component . startAudioRecording ( ) ;
857+ expect ( component . isAudioRecording ) . toBe ( true ) ;
858+
859+ component . startAudioRecording ( ) ;
860+
861+ expect ( mockSnackBar . open ) . toHaveBeenCalledWith (
862+ 'Another streaming request is already in progress. Please stop it before starting a new one.' ,
863+ 'OK'
864+ ) ;
865+ expect ( mockStreamChatService . startAudioChat ) . toHaveBeenCalledTimes ( 1 ) ;
866+ } ) ;
867+
868+ it ( 'should prevent starting video while already recording' , ( ) => {
869+ component . startVideoRecording ( ) ;
870+ expect ( component . isVideoRecording ) . toBe ( true ) ;
871+
872+ component . startVideoRecording ( ) ;
873+
874+ expect ( mockSnackBar . open ) . toHaveBeenCalledWith (
875+ 'Another streaming request is already in progress. Please stop it before starting a new one.' ,
876+ 'OK'
877+ ) ;
878+ expect ( mockStreamChatService . startVideoChat ) . toHaveBeenCalledTimes ( 1 ) ;
879+ } ) ;
880+ } ) ;
881+
882+ describe ( 'when stopping video recording without videoContainer' , ( ) => {
883+ it ( 'should still cleanup sessionHasUsedBidi' , ( ) => {
884+ component . startVideoRecording ( ) ;
885+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( true ) ;
886+
887+ spyOn ( component , 'chatPanel' ) . and . returnValue ( {
888+ videoContainer : undefined
889+ } as any ) ;
890+
891+ component . stopVideoRecording ( ) ;
892+
893+ expect ( component . sessionHasUsedBidi . has ( component . sessionId ) ) . toBe ( false ) ;
894+ expect ( component . isVideoRecording ) . toBe ( false ) ;
818895 } ) ;
819896 } ) ;
820897 } ) ;
0 commit comments