@@ -32,14 +32,16 @@ describe('FeedbackRecordingManager', () => {
3232 config : {
3333 api_host : 'https://test.com' ,
3434 token : 'test-token' ,
35- } ,
35+ } as any ,
3636 capture : jest . fn ( ) ,
3737 startSessionRecording : jest . fn ( ) ,
38+ stopSessionRecording : jest . fn ( ) ,
39+ sessionRecordingStarted : jest . fn ( ) ,
3840 get_session_id : jest . fn ( ) . mockReturnValue ( 'mock-session-id' ) ,
3941 _send_request : jest . fn ( ) ,
4042 requestRouter : {
4143 endpointFor : jest . fn ( ) . mockReturnValue ( 'https://test.com/api/feedback/audio' ) ,
42- } ,
44+ } as any ,
4345 } )
4446
4547 audioRecorderMock = {
@@ -166,6 +168,8 @@ describe('FeedbackRecordingManager', () => {
166168 let onRecordingEnded : jest . Mock
167169
168170 beforeEach ( async ( ) => {
171+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( false )
172+
169173 onRecordingEnded = jest . fn ( )
170174 await manager . launchFeedbackRecordingUI ( onRecordingEnded )
171175
@@ -214,6 +218,22 @@ describe('FeedbackRecordingManager', () => {
214218 $feedback_recording_id : feedbackId ,
215219 } )
216220 } )
221+
222+ it ( 'starts session recording if not already active' , async ( ) => {
223+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( false )
224+
225+ feedbackId = await handleStartRecording ( )
226+
227+ expect ( instance . startSessionRecording ) . toHaveBeenCalledWith ( true )
228+ } )
229+
230+ it ( 'does not start session recording if already active' , async ( ) => {
231+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( true )
232+
233+ feedbackId = await handleStartRecording ( )
234+
235+ expect ( instance . startSessionRecording ) . not . toHaveBeenCalled ( )
236+ } )
217237 } )
218238
219239 describe ( 'stop' , ( ) => {
@@ -334,6 +354,24 @@ describe('FeedbackRecordingManager', () => {
334354 expect ( instance . _send_request ) . not . toHaveBeenCalled ( )
335355 expect ( onRecordingEnded ) . toHaveBeenCalledTimes ( 1 )
336356 } )
357+
358+ it ( 'stops session recording when stopping if we started it' , async ( ) => {
359+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( false )
360+
361+ feedbackId = await handleStartRecording ( )
362+ await stopCallback ( feedbackId )
363+
364+ expect ( instance . stopSessionRecording ) . toHaveBeenCalled ( )
365+ } )
366+
367+ it ( 'does not stop session recording if we did not start it' , async ( ) => {
368+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( true )
369+
370+ feedbackId = await handleStartRecording ( )
371+ await stopCallback ( feedbackId )
372+
373+ expect ( instance . stopSessionRecording ) . not . toHaveBeenCalled ( )
374+ } )
337375 } )
338376
339377 describe ( 'cleanup' , ( ) => {
@@ -357,6 +395,26 @@ describe('FeedbackRecordingManager', () => {
357395 expect ( manager . isFeedbackRecordingActive ( ) ) . toBe ( false )
358396 expect ( manager . getCurrentFeedbackRecordingId ( ) ) . toBeNull ( )
359397 } )
398+
399+ it ( 'stops session recording when stopping if we started it' , async ( ) => {
400+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( false )
401+
402+ feedbackId = await handleStartRecording ( )
403+
404+ manager . cleanup ( )
405+
406+ expect ( instance . stopSessionRecording ) . toHaveBeenCalled ( )
407+ } )
408+
409+ it ( 'does not stop session recording if we did not start it' , async ( ) => {
410+ jest . spyOn ( instance , 'sessionRecordingStarted' ) . mockReturnValue ( true )
411+
412+ feedbackId = await handleStartRecording ( )
413+
414+ manager . cleanup ( )
415+
416+ expect ( instance . stopSessionRecording ) . not . toHaveBeenCalled ( )
417+ } )
360418 } )
361419
362420 describe ( 'UI focus after completion' , ( ) => {
0 commit comments