@@ -522,20 +522,27 @@ describe('UsersPage', () => {
522522 const user = userEvent . setup ( )
523523 expect ( await screen . findByText ( 'Invite User' ) ) . toBeInTheDocument ( )
524524 await user . click ( screen . getByRole ( 'button' , { name : / I n v i t e U s e r / i } ) )
525+ expect ( await screen . findByPlaceholderText ( 'user@example.com' ) ) . toBeInTheDocument ( )
525526
526- const emailInput = screen . getByPlaceholderText ( 'user@example.com' )
527- await user . type ( emailInput , 'test@example.com' )
527+ vi . useFakeTimers ( )
528+
529+ try {
530+ const emailInput = screen . getByPlaceholderText ( 'user@example.com' )
531+ fireEvent . change ( emailInput , { target : { value : 'test@example.com' } } )
532+
533+ await act ( async ( ) => {
534+ await vi . advanceTimersByTimeAsync ( 550 )
535+ } )
528536
529- await waitFor ( ( ) => {
530537 expect ( client . post ) . toHaveBeenCalledWith ( '/users/preview-invite-url' , { email : 'test@example.com' } )
531- } , { timeout : 2000 } )
532538
533- await waitFor ( ( ) => {
534539 const preview = screen . getByText ( 'https://example.com/accept-invite?token=...' )
535-
536540 expect ( preview . textContent ) . toContain ( '...' )
537541 expect ( preview . textContent ) . not . toContain ( 'SAMPLE_TOKEN_PREVIEW' )
538- } , { timeout : 2000 } )
542+ }
543+ finally {
544+ vi . useRealTimers ( )
545+ }
539546 } )
540547
541548 it ( 'shows warning when not configured' , async ( ) => {
@@ -556,18 +563,24 @@ describe('UsersPage', () => {
556563 expect ( await screen . findByText ( 'Invite User' ) ) . toBeInTheDocument ( )
557564 await user . click ( screen . getByRole ( 'button' , { name : / I n v i t e U s e r / i } ) )
558565
559- const emailInput = screen . getByPlaceholderText ( 'user@example.com' )
560- await user . type ( emailInput , 'test@example.com' )
566+ vi . useFakeTimers ( )
567+
568+ try {
569+ const emailInput = screen . getByPlaceholderText ( 'user@example.com' )
570+ fireEvent . change ( emailInput , { target : { value : 'test@example.com' } } )
571+
572+ await act ( async ( ) => {
573+ await vi . advanceTimersByTimeAsync ( 550 )
574+ } )
561575
562- await waitFor ( ( ) => {
563576 expect ( client . post ) . toHaveBeenCalledWith ( '/users/preview-invite-url' , { email : 'test@example.com' } )
564- } , { timeout : 2000 } )
565577
566- await waitFor ( ( ) => {
567578 // Look for link to system settings
568579 const link = screen . getByRole ( 'link' )
569580 expect ( link . getAttribute ( 'href' ) ) . toContain ( '/settings/system' )
570- } , { timeout : 2000 } )
581+ } finally {
582+ vi . useRealTimers ( )
583+ }
571584 } )
572585
573586 it ( 'does not show preview when email is invalid' , async ( ) => {
@@ -599,17 +612,27 @@ describe('UsersPage', () => {
599612 const user = userEvent . setup ( )
600613 expect ( await screen . findByText ( 'Invite User' ) ) . toBeInTheDocument ( )
601614 await user . click ( screen . getByRole ( 'button' , { name : / I n v i t e U s e r / i } ) )
615+ expect ( await screen . findByPlaceholderText ( 'user@example.com' ) ) . toBeInTheDocument ( )
602616
603- const emailInput = screen . getByPlaceholderText ( 'user@example.com' )
604- await user . type ( emailInput , 'test@example.com' )
617+ vi . useFakeTimers ( )
618+
619+ try {
620+ const emailInput = screen . getByPlaceholderText ( 'user@example.com' )
621+ fireEvent . change ( emailInput , { target : { value : 'test@example.com' } } )
622+
623+ await act ( async ( ) => {
624+ await vi . advanceTimersByTimeAsync ( 550 )
625+ } )
605626
606- await waitFor ( ( ) => {
607627 expect ( client . post ) . toHaveBeenCalledWith ( '/users/preview-invite-url' , { email : 'test@example.com' } )
608- } , { timeout : 2000 } )
609628
610- // Verify preview is not displayed after error
611- const previewQuery = screen . queryByText ( / a c c e p t - i n v i t e / )
612- expect ( previewQuery ) . toBeNull ( )
629+ // Verify preview is not displayed after error
630+ const previewQuery = screen . queryByText ( / a c c e p t - i n v i t e / )
631+ expect ( previewQuery ) . toBeNull ( )
632+ }
633+ finally {
634+ vi . useRealTimers ( )
635+ }
613636 } )
614637 } )
615638
0 commit comments