Newer
Older
import { act, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { mockSgeState } from 'tests/__mocks__/forms.mock'
import StepIdentityAndPdl from './StepIdentityAndPdl'
describe('StepIdentityAndPdl component', () => {
it('should be rendered correctly', () => {
<StepIdentityAndPdl sgeState={mockSgeState} onChange={mockHandleChange} />
it('should be able to change fields', async () => {
render(
<StepIdentityAndPdl sgeState={mockSgeState} onChange={mockHandleChange} />
)
const firstNameInput = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.firstName',
await act(async () => {
await userEvent.type(firstNameInput, 'n')
})
expect(mockHandleChange).toHaveBeenCalledWith('firstName', 'n')
const lastNameInput = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.lastName',
await act(async () => {
await userEvent.type(lastNameInput, 'n')
})
expect(mockHandleChange).toHaveBeenCalledWith('lastName', 'n')
const pdlInput = screen.getByRole('spinbutton', {
name: 'auth.enedissgegrandlyon.pdlLabel',
await act(async () => {
await userEvent.type(pdlInput, '0')
})
expect(mockHandleChange).toHaveBeenCalledWith('pdl', '0', 14)
it('should open hint modal', async () => {
<StepIdentityAndPdl sgeState={mockSgeState} onChange={mockHandleChange} />
await userEvent.click(
screen.getByText('auth.enedissgegrandlyon.pdlModal.title')
)
expect(screen.getByRole('dialog')).toBeInTheDocument()
})
it('should be rendered with values in fields', () => {
render(
<StepIdentityAndPdl
sgeState={{
pdl: 11111111111111,
firstName: 'Zack',
lastName: 'Ichan',
zipCode: 69003,
}}
onChange={mockHandleChange}
/>
)
expect(screen.getByDisplayValue(11111111111111)).toBeInTheDocument()
expect(screen.getByDisplayValue('Zack')).toBeInTheDocument()
expect(screen.getByDisplayValue('Ichan')).toBeInTheDocument()