Newer
Older
import { act, render, screen } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import { mockSgeState } from 'tests/__mocks__/forms.mock'
describe('StepAddress component', () => {
it('should be rendered correctly', () => {
<StepAddress sgeState={mockSgeState} onChange={mockHandleChange} />
describe('should change inputs', () => {
beforeEach(() => {
render(
<StepAddress sgeState={mockSgeState} onChange={mockHandleChange} />
)
})
it('should change address value', async () => {
const input = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.address',
})
await act(async () => {
await userEvent.type(input, 't')
})
expect(mockHandleChange).toHaveBeenCalledWith('address', 't')
})
it('should change zipCode value', async () => {
const input = screen.getByRole('spinbutton', {
name: 'auth.enedissgegrandlyon.zipCode',
})
expect(mockHandleChange).toHaveBeenCalledWith('zipCode', '1', 5)
})
it('should change city value', async () => {
const input = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.city',
})
await act(async () => {
await userEvent.type(input, 'c')
})
expect(mockHandleChange).toHaveBeenCalledWith('city', 'c')
})
})
it('should have an existing zipCode value', () => {
sgeState={{ ...mockSgeState, zipCode: 69200 }}
const input = screen.getByRole('spinbutton', {
name: 'auth.enedissgegrandlyon.zipCode',
})
expect(input).toHaveValue(69200)