@@ -412,4 +412,184 @@ describe("FollowUpSuggest", () => {
412412 // onSuggestionClick should NOT have been called (component doesn't auto-select)
413413 expect ( mockOnSuggestionClick ) . not . toHaveBeenCalled ( )
414414 } )
415+
416+ describe ( "isFollowUpAutoApprovalPaused prop" , ( ) => {
417+ it ( "should not display countdown timer when isFollowUpAutoApprovalPaused is true" , ( ) => {
418+ renderWithTestProviders (
419+ < FollowUpSuggest
420+ suggestions = { mockSuggestions }
421+ onSuggestionClick = { mockOnSuggestionClick }
422+ ts = { 123 }
423+ onCancelAutoApproval = { mockOnCancelAutoApproval }
424+ isFollowUpAutoApprovalPaused = { true }
425+ /> ,
426+ defaultTestState ,
427+ )
428+
429+ // Should not show countdown when user is typing
430+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
431+ } )
432+
433+ it ( "should stop countdown when user starts typing (isFollowUpAutoApprovalPaused becomes true)" , ( ) => {
434+ const { rerender } = renderWithTestProviders (
435+ < FollowUpSuggest
436+ suggestions = { mockSuggestions }
437+ onSuggestionClick = { mockOnSuggestionClick }
438+ ts = { 123 }
439+ onCancelAutoApproval = { mockOnCancelAutoApproval }
440+ isFollowUpAutoApprovalPaused = { false }
441+ /> ,
442+ defaultTestState ,
443+ )
444+
445+ // Initially should show countdown
446+ expect ( screen . getByText ( / 3 s / ) ) . toBeInTheDocument ( )
447+
448+ // Simulate user starting to type by setting isFollowUpAutoApprovalPaused to true
449+ rerender (
450+ < TestExtensionStateProvider value = { defaultTestState } >
451+ < TooltipProvider >
452+ < FollowUpSuggest
453+ suggestions = { mockSuggestions }
454+ onSuggestionClick = { mockOnSuggestionClick }
455+ ts = { 123 }
456+ onCancelAutoApproval = { mockOnCancelAutoApproval }
457+ isFollowUpAutoApprovalPaused = { true }
458+ />
459+ </ TooltipProvider >
460+ </ TestExtensionStateProvider > ,
461+ )
462+
463+ // Countdown should be hidden immediately when user starts typing
464+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
465+
466+ // Advance timer to ensure countdown doesn't continue
467+ vi . advanceTimersByTime ( 5000 )
468+
469+ // onSuggestionClick should not have been called
470+ expect ( mockOnSuggestionClick ) . not . toHaveBeenCalled ( )
471+
472+ // Countdown should still not be visible
473+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
474+ } )
475+
476+ it ( "should resume countdown when user clears input (isFollowUpAutoApprovalPaused becomes false)" , async ( ) => {
477+ const { rerender } = renderWithTestProviders (
478+ < FollowUpSuggest
479+ suggestions = { mockSuggestions }
480+ onSuggestionClick = { mockOnSuggestionClick }
481+ ts = { 123 }
482+ onCancelAutoApproval = { mockOnCancelAutoApproval }
483+ isFollowUpAutoApprovalPaused = { true }
484+ /> ,
485+ defaultTestState ,
486+ )
487+
488+ // Should not show countdown when paused
489+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
490+
491+ // Simulate user clearing input by setting isFollowUpAutoApprovalPaused to false
492+ rerender (
493+ < TestExtensionStateProvider value = { defaultTestState } >
494+ < TooltipProvider >
495+ < FollowUpSuggest
496+ suggestions = { mockSuggestions }
497+ onSuggestionClick = { mockOnSuggestionClick }
498+ ts = { 123 }
499+ onCancelAutoApproval = { mockOnCancelAutoApproval }
500+ isFollowUpAutoApprovalPaused = { false }
501+ />
502+ </ TooltipProvider >
503+ </ TestExtensionStateProvider > ,
504+ )
505+
506+ // Countdown should resume from the full timeout
507+ expect ( screen . getByText ( / 3 s / ) ) . toBeInTheDocument ( )
508+ } )
509+
510+ it ( "should not show countdown when both isAnswered and isFollowUpAutoApprovalPaused are true" , ( ) => {
511+ renderWithTestProviders (
512+ < FollowUpSuggest
513+ suggestions = { mockSuggestions }
514+ onSuggestionClick = { mockOnSuggestionClick }
515+ ts = { 123 }
516+ onCancelAutoApproval = { mockOnCancelAutoApproval }
517+ isAnswered = { true }
518+ isFollowUpAutoApprovalPaused = { true }
519+ /> ,
520+ defaultTestState ,
521+ )
522+
523+ // Should not show countdown
524+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
525+ } )
526+
527+ it ( "should handle pause during countdown progress" , async ( ) => {
528+ const { rerender } = renderWithTestProviders (
529+ < FollowUpSuggest
530+ suggestions = { mockSuggestions }
531+ onSuggestionClick = { mockOnSuggestionClick }
532+ ts = { 123 }
533+ onCancelAutoApproval = { mockOnCancelAutoApproval }
534+ isFollowUpAutoApprovalPaused = { false }
535+ /> ,
536+ defaultTestState ,
537+ )
538+
539+ // Initially should show 3s
540+ expect ( screen . getByText ( / 3 s / ) ) . toBeInTheDocument ( )
541+
542+ // Advance timer by 1 second
543+ await act ( async ( ) => {
544+ vi . advanceTimersByTime ( 1000 )
545+ } )
546+
547+ // Should show 2s
548+ expect ( screen . getByText ( / 2 s / ) ) . toBeInTheDocument ( )
549+
550+ // User starts typing (pause)
551+ rerender (
552+ < TestExtensionStateProvider value = { defaultTestState } >
553+ < TooltipProvider >
554+ < FollowUpSuggest
555+ suggestions = { mockSuggestions }
556+ onSuggestionClick = { mockOnSuggestionClick }
557+ ts = { 123 }
558+ onCancelAutoApproval = { mockOnCancelAutoApproval }
559+ isFollowUpAutoApprovalPaused = { true }
560+ />
561+ </ TooltipProvider >
562+ </ TestExtensionStateProvider > ,
563+ )
564+
565+ // Countdown should be hidden
566+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
567+
568+ // Advance timer while paused
569+ await act ( async ( ) => {
570+ vi . advanceTimersByTime ( 2000 )
571+ } )
572+
573+ // Countdown should still be hidden
574+ expect ( screen . queryByText ( / \d + s / ) ) . not . toBeInTheDocument ( )
575+
576+ // User clears input (unpause) - countdown should restart from full duration
577+ rerender (
578+ < TestExtensionStateProvider value = { defaultTestState } >
579+ < TooltipProvider >
580+ < FollowUpSuggest
581+ suggestions = { mockSuggestions }
582+ onSuggestionClick = { mockOnSuggestionClick }
583+ ts = { 123 }
584+ onCancelAutoApproval = { mockOnCancelAutoApproval }
585+ isFollowUpAutoApprovalPaused = { false }
586+ />
587+ </ TooltipProvider >
588+ </ TestExtensionStateProvider > ,
589+ )
590+
591+ // Countdown should restart from full timeout (3s)
592+ expect ( screen . getByText ( / 3 s / ) ) . toBeInTheDocument ( )
593+ } )
594+ } )
415595} )
0 commit comments