Skip to content
Snippets Groups Projects
EcogestureSelectionRestart.spec.tsx 1.29 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render, screen } from '@testing-library/react'
    
    import userEvent from '@testing-library/user-event'
    
    import React from 'react'
    
    import EcogestureSelectionRestart from './EcogestureSelectionRestart'
    
    
    const mockedNavigate = jest.fn()
    
    jest.mock('react-router-dom', () => ({
      ...jest.requireActual('react-router-dom'),
    
      useNavigate: () => mockedNavigate,
    
    }))
    const mockRestart = jest.fn()
    
    describe('EcogestureSelectionRestart component', () => {
      it('should be rendered correctly', () => {
    
        const { container } = render(
    
          <EcogestureSelectionRestart listLength={10} restart={mockRestart} />
        )
    
        expect(container).toMatchSnapshot()
    
      it('should call go to the ecogesture view when user click on the button', async () => {
        render(<EcogestureSelectionRestart listLength={10} restart={mockRestart} />)
    
        await userEvent.click(
          screen.getByText('ecogesture_selection.button_go_to_ecogesture')
        )
    
        expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures?tab=0')
    
      it('should call the restart when user click on the button', async () => {
        render(<EcogestureSelectionRestart listLength={10} restart={mockRestart} />)
    
        await userEvent.click(
          screen.getByText('ecogesture_selection.button_continue')
        )
    
        expect(mockRestart).toHaveBeenCalledTimes(1)
      })
    })