11import { vi } from 'vitest'
2- import { render , screen } from '@testing-library/react'
2+ import { render , screen , waitFor } from '@testing-library/react'
3+ import userEvent from '@testing-library/user-event'
34import Dashboard from '@/components/Dashboard'
45
56vi . mock ( '@tanstack/react-router' , ( ) => ( {
@@ -8,12 +9,24 @@ vi.mock('@tanstack/react-router', () => ({
89
910describe ( 'Dashboard' , ( ) => {
1011 test ( 'renders a heading with the correct text' , ( ) => {
11- const navigate = vi . fn ( )
12- const useNavigateMock = vi . fn ( ( ) => navigate )
13- vi . doMock ( '@tanstack/react-router' , ( ) => ( {
14- useNavigate : useNavigateMock ,
15- } ) )
1612 render ( < Dashboard /> )
1713 expect ( screen . getByText ( / E m p l o y e e I D / i) ) . toBeInTheDocument ( )
1814 } )
15+
16+ test ( 'opens and closes the row details modal' , async ( ) => {
17+ const user = userEvent . setup ( )
18+ render ( < Dashboard /> )
19+
20+ // Wait for the mocked user data to load and render the View Details button.
21+ const viewDetailsButton = await screen . findByRole ( 'button' , { name : / v i e w d e t a i l s / i } )
22+ await user . click ( viewDetailsButton )
23+
24+ expect ( screen . getByText ( / R o w D e t a i l s / i) ) . toBeInTheDocument ( )
25+
26+ const closeButtons = screen . getAllByRole ( 'button' , { name : 'Close' } )
27+ await user . click ( closeButtons . at ( - 1 ) ! )
28+ await waitFor ( ( ) => {
29+ expect ( screen . queryByText ( / R o w D e t a i l s / i) ) . not . toBeInTheDocument ( )
30+ } )
31+ } )
1932} )
0 commit comments