@@ -377,40 +377,50 @@ describe('Reverification', () => {
377377 ) ,
378378 ) ;
379379
380- const user = await startVerification ( ) ;
381-
382- // The error card stays on screen without the server's message
383- expect ( await screen . findByText ( GENERIC_ERROR_TITLE ) ) . toBeVisible ( ) ;
384- expect ( screen . getByText ( 'Please try again.' ) ) . toBeVisible ( ) ;
385- expect ( screen . queryByText ( NO_FACTORS_TITLE ) ) . toBeNull ( ) ;
386- expect ( screen . queryByText ( 'Nope' ) ) . toBeNull ( ) ;
387- await settle ( ) ;
388- expect ( screen . getByText ( GENERIC_ERROR_TITLE ) ) . toBeVisible ( ) ;
389- expect ( outcome ( ) ) . toBe ( '' ) ;
380+ vi . useFakeTimers ( { shouldAdvanceTime : true } ) ;
381+ try {
382+ const user = await startVerification ( ) ;
390383
391- // Closing it rejects the action as cancelled
392- await user . click ( screen . getByRole ( 'button' , { name : 'Close' } ) ) ;
393- await waitFor ( ( ) => expect ( outcome ( ) ) . toBe ( 'rejected: reverification_cancelled' ) ) ;
394- await untilClosed ( ) ;
395- expect ( screen . queryByText ( GENERIC_ERROR_TITLE ) ) . toBeNull ( ) ;
384+ // The error card stays on screen without the server's message
385+ expect ( await screen . findByText ( GENERIC_ERROR_TITLE ) ) . toBeVisible ( ) ;
386+ expect ( screen . getByText ( 'Please try again.' ) ) . toBeVisible ( ) ;
387+ expect ( screen . queryByText ( NO_FACTORS_TITLE ) ) . toBeNull ( ) ;
388+ expect ( screen . queryByText ( 'Nope' ) ) . toBeNull ( ) ;
389+ await act ( ( ) => vi . advanceTimersByTimeAsync ( 60_000 ) ) ;
390+ expect ( screen . getByText ( GENERIC_ERROR_TITLE ) ) . toBeVisible ( ) ;
391+ expect ( outcome ( ) ) . toBe ( '' ) ;
392+
393+ // Closing it rejects the action as cancelled
394+ await user . click ( screen . getByRole ( 'button' , { name : 'Close' } ) ) ;
395+ await waitFor ( ( ) => expect ( outcome ( ) ) . toBe ( 'rejected: reverification_cancelled' ) ) ;
396+ await untilClosed ( ) ;
397+ expect ( screen . queryByText ( GENERIC_ERROR_TITLE ) ) . toBeNull ( ) ;
398+ } finally {
399+ vi . useRealTimers ( ) ;
400+ }
396401 } ) ;
397402
398403 it ( 'keeps showing the no factors card until it is dismissed when none of the factors are supported' , async ( ) => {
399404 await renderReverification ( guardedAction ( ) , verificationSeed ( { firstFactors : [ enterpriseSsoFactor ] } ) ) ;
400405
401- const user = await startVerification ( ) ;
402-
403- expect ( await screen . findByText ( NO_FACTORS_TITLE ) ) . toBeVisible ( ) ;
404- expect ( screen . getByText ( / N o s u i t a b l e a u t h e n t i c a t i o n f a c t o r i s c o n f i g u r e d / ) ) . toBeVisible ( ) ;
405- expect ( screen . queryByText ( GENERIC_ERROR_TITLE ) ) . toBeNull ( ) ;
406- await settle ( ) ;
407- expect ( screen . getByText ( NO_FACTORS_TITLE ) ) . toBeVisible ( ) ;
408- expect ( outcome ( ) ) . toBe ( '' ) ;
406+ vi . useFakeTimers ( { shouldAdvanceTime : true } ) ;
407+ try {
408+ const user = await startVerification ( ) ;
409409
410- await user . click ( screen . getByRole ( 'button' , { name : 'Close' } ) ) ;
411- await waitFor ( ( ) => expect ( outcome ( ) ) . toBe ( 'rejected: reverification_cancelled' ) ) ;
412- await untilClosed ( ) ;
413- expect ( screen . queryByText ( NO_FACTORS_TITLE ) ) . toBeNull ( ) ;
410+ expect ( await screen . findByText ( NO_FACTORS_TITLE ) ) . toBeVisible ( ) ;
411+ expect ( screen . getByText ( / N o s u i t a b l e a u t h e n t i c a t i o n f a c t o r i s c o n f i g u r e d / ) ) . toBeVisible ( ) ;
412+ expect ( screen . queryByText ( GENERIC_ERROR_TITLE ) ) . toBeNull ( ) ;
413+ await act ( ( ) => vi . advanceTimersByTimeAsync ( 60_000 ) ) ;
414+ expect ( screen . getByText ( NO_FACTORS_TITLE ) ) . toBeVisible ( ) ;
415+ expect ( outcome ( ) ) . toBe ( '' ) ;
416+
417+ await user . click ( screen . getByRole ( 'button' , { name : 'Close' } ) ) ;
418+ await waitFor ( ( ) => expect ( outcome ( ) ) . toBe ( 'rejected: reverification_cancelled' ) ) ;
419+ await untilClosed ( ) ;
420+ expect ( screen . queryByText ( NO_FACTORS_TITLE ) ) . toBeNull ( ) ;
421+ } finally {
422+ vi . useRealTimers ( ) ;
423+ }
414424 } ) ;
415425 } ) ;
416426
@@ -565,11 +575,12 @@ describe('Reverification', () => {
565575
566576 expect ( screen . getByRole ( 'button' , { name : 'Continue' } ) ) . toBeDisabled ( ) ;
567577 await user . type ( passwordField ( ) , '{Enter}' ) ;
568- await settle ( ) ;
569- expect ( attempt . requests ) . toHaveLength ( 0 ) ;
570578
571579 await user . type ( passwordField ( ) , PASSWORD ) ;
572580 expect ( screen . getByRole ( 'button' , { name : 'Continue' } ) ) . toBeEnabled ( ) ;
581+ await user . keyboard ( '{Enter}' ) ;
582+ await waitFor ( ( ) => expect ( attempt . requests ) . toHaveLength ( 1 ) ) ;
583+ expect ( new URLSearchParams ( await attempt . requests [ 0 ] ?. text ( ) ) . get ( 'password' ) ) . toBe ( PASSWORD ) ;
573584 attempt . release ( ) ;
574585 } ) ;
575586 } ) ;
@@ -639,8 +650,10 @@ describe('Reverification', () => {
639650 await pasteCode ( user , CODE . slice ( 0 , 3 ) ) ;
640651 expect ( screen . getByRole ( 'button' , { name : 'Continue' } ) ) . toBeDisabled ( ) ;
641652 await user . keyboard ( '{Enter}' ) ;
642- await settle ( ) ;
643- expect ( attempt . requests ) . toHaveLength ( 0 ) ;
653+
654+ await user . keyboard ( CODE . slice ( 3 ) ) ;
655+ await waitFor ( ( ) => expect ( attempt . requests ) . toHaveLength ( 1 ) ) ;
656+ expect ( new URLSearchParams ( await attempt . requests [ 0 ] ?. text ( ) ) . get ( 'code' ) ) . toBe ( CODE ) ;
644657 attempt . release ( ) ;
645658 } ) ;
646659
@@ -686,20 +699,21 @@ describe('Reverification', () => {
686699
687700 it ( 'resends a code once the cooldown has passed' , async ( ) => {
688701 const { fapi } = await renderReverification ( guardedAction ( ) , verificationSeed ( { firstFactors : [ emailFactor ] } ) ) ;
689- vi . useFakeTimers ( { toFake : [ 'Date' ] } ) ;
702+ vi . useFakeTimers ( { toFake : [ 'Date' , 'setInterval' , 'clearInterval' ] } ) ;
690703
691704 try {
692705 const user = await startVerification ( ) ;
693706 expect ( await screen . findByText ( STEP . emailCode ) ) . toBeVisible ( ) ;
694- await waitFor ( ( ) => expect ( fapi . verification . firstFactorVerification ?. strategy ) . toBe ( 'email_code' ) ) ;
707+ await vi . waitFor ( ( ) => expect ( fapi . verification . firstFactorVerification ?. strategy ) . toBe ( 'email_code' ) ) ;
695708
696709 // Resend is disabled and shows the countdown while the cooldown runs
697710 const resend = await screen . findByRole ( 'button' , { name : / R e s e n d \( \d + \) / } ) ;
698711 expect ( resend ) . toBeDisabled ( ) ;
699712
700713 // Resend is enabled again after the cooldown
701714 vi . setSystemTime ( Date . now ( ) + 30_000 ) ;
702- await waitFor ( ( ) => expect ( screen . getByRole ( 'button' , { name : / R e s e n d / } ) ) . toBeEnabled ( ) , { timeout : 3000 } ) ;
715+ await act ( ( ) => vi . advanceTimersByTimeAsync ( 1000 ) ) ;
716+ expect ( screen . getByRole ( 'button' , { name : / R e s e n d / } ) ) . toBeEnabled ( ) ;
703717 expect ( screen . getByRole ( 'button' , { name : / R e s e n d / } ) . textContent ) . not . toMatch ( / \( \d + \) / ) ;
704718
705719 // Resending sends a new code and clears the typed value
@@ -708,7 +722,7 @@ describe('Reverification', () => {
708722 expect ( slotValues ( ) ) . toEqual ( [ '1' , '2' , '3' , '' , '' , '' ] ) ;
709723 const prepare = holdRequests ( 'post' , PREPARE_FIRST ) ;
710724 await user . click ( screen . getByRole ( 'button' , { name : / R e s e n d / } ) ) ;
711- await waitFor ( ( ) => expect ( prepare . requests ) . toHaveLength ( 1 ) ) ;
725+ await vi . waitFor ( ( ) => expect ( prepare . requests ) . toHaveLength ( 1 ) ) ;
712726 expect ( slotValues ( ) ) . toEqual ( [ '' , '' , '' , '' , '' , '' ] ) ;
713727 expect ( screen . getByRole ( 'button' , { name : / R e s e n d \( \d + \) / } ) ) . toBeDisabled ( ) ;
714728
@@ -718,7 +732,7 @@ describe('Reverification', () => {
718732 await settle ( ) ;
719733 expect ( attempt . requests ) . toHaveLength ( 0 ) ;
720734 prepare . release ( ) ;
721- await waitFor ( ( ) => expect ( attempt . requests ) . toHaveLength ( 1 ) ) ;
735+ await vi . waitFor ( ( ) => expect ( attempt . requests ) . toHaveLength ( 1 ) ) ;
722736 attempt . release ( ) ;
723737 await untilResolved ( ) ;
724738 } finally {
@@ -817,11 +831,12 @@ describe('Reverification', () => {
817831
818832 expect ( screen . getByRole ( 'button' , { name : 'Continue' } ) ) . toBeDisabled ( ) ;
819833 await user . type ( screen . getByLabelText ( 'Backup code' ) , '{Enter}' ) ;
820- await settle ( ) ;
821- expect ( attempt . requests ) . toHaveLength ( 0 ) ;
822834
823835 await user . type ( screen . getByLabelText ( 'Backup code' ) , BACKUP_CODE ) ;
824836 expect ( screen . getByRole ( 'button' , { name : 'Continue' } ) ) . toBeEnabled ( ) ;
837+ await user . keyboard ( '{Enter}' ) ;
838+ await waitFor ( ( ) => expect ( attempt . requests ) . toHaveLength ( 1 ) ) ;
839+ expect ( new URLSearchParams ( await attempt . requests [ 0 ] ?. text ( ) ) . get ( 'code' ) ) . toBe ( BACKUP_CODE ) ;
825840 attempt . release ( ) ;
826841 } ) ;
827842 } ) ;
0 commit comments