import { render, fireEvent } from '@testing-library/react'; import { CustomRoundabout } from './CustomRoundabout'; import { describe, it, expect, vi, afterEach } from 'vitest'; import { LunaticError } from '../../use-lunatic/type'; import { ComponentErrors } from '../shared/ComponentErrors/ComponentErrors'; vi.mock('../shared/ComponentErrors/ComponentErrors', () => ({ ComponentErrors: vi.fn(), })); describe('Roundabout', () => { const mockGoToIteration = vi.fn(); afterEach(() => { mockGoToIteration.mockClear(); }); const items = [ { label: 'Step 1', progress: -1, }, { label: 'Step 2', progress: 0, }, { label: 'Step 3', progress: 1, }, ]; const label = 'My Roundabout'; const description = 'Roundabout description'; it('renders the roundabout correctly', () => { const { getByText } = render( ); expect(getByText('Step 1')).toBeInTheDocument(); expect(getByText('Step 2')).toBeInTheDocument(); expect(getByText('Step 3')).toBeInTheDocument(); expect(getByText('Complété')).toBeInTheDocument(); expect(getByText('Modifier')).toBeInTheDocument(); expect(getByText('Commencer')).toBeInTheDocument(); expect(getByText('Roundabout description')).toBeInTheDocument(); }); it('calls the goToIteration function when a button is clicked', () => { const { getByText } = render( ); const button = getByText('Modifier'); fireEvent.click(button); expect(mockGoToIteration).toHaveBeenCalledTimes(1); expect(mockGoToIteration).toHaveBeenCalledWith(1); }); it('it lock an iteration when finished and locked property is true', () => { const { getByText } = render( ); const completeButton = getByText('Complété'); expect(completeButton).toBeDisabled(); }); it('displays roundabout errors', () => { const errors: LunaticError[] = [ { id: 'error1', errorMessage: 'Error 1 message', criticality: 'ERROR', typeOfControl: 'CONSISTENCY', }, { id: 'error2', errorMessage: 'Error 2 message', criticality: 'WARN', typeOfControl: 'CONSISTENCY', }, ]; render( ); expect(ComponentErrors).toHaveBeenCalledWith( expect.objectContaining({ errors }), undefined ); }); });