import '@testing-library/jest-dom/extend-expect'
import React from 'react'
import { Formik } from 'formik'
import { render, fireEvent, waitFor } from '@testing-library/react'
import Form from '../form/form'
import Input from './index'
import { act } from 'react-dom/test-utils'
const InputContainer = ({ fast }: { fast: boolean }) => {
const ref = React.useRef() as any
React.useEffect(() => {
ref.current.focus()
}, [ref.current])
return (
{}}>
)
}
const TextAreaContainer = () => {
return (
{}}>
)
}
const PasswordContainer = () => {
return (
{}}>
)
}
describe('test initial value', () => {
it.each`
fast
${true}
${false}
`('should display initial value (fast=$fast)', async (fast: boolean) => {
const { findByTestId } = render()
expect(await findByTestId('uat')).toHaveValue('initial value')
})
})
describe('should change', () => {
it.each`
fast
${true}
${false}
`('should change (fast=$fast)', async (fast: boolean) => {
const { findByTestId } = render()
const uat = await findByTestId('uat')
await act(async () => {
fireEvent.change(uat, { target: { value: 'new value' } })
await waitFor(async () =>
expect(await findByTestId('uat')).toHaveValue('new value'),
)
})
})
})
test('should have focus', async () => {
const { findByTestId } = render()
expect(await findByTestId('uat')).toHaveFocus()
})
test('TextArea should display default value', async () => {
const { findByTestId } = render()
const uat = await findByTestId('uat')
await act(async () => {
fireEvent.change(uat, { target: { value: 'defaultvalue' } })
await waitFor(async () =>
expect(await findByTestId('uat')).toHaveValue('defaultvalue'),
)
})
})
test('Password should display default value', async () => {
const { findByTestId } = render()
const uat = await findByTestId('uat')
await act(async () => {
fireEvent.change(uat, { target: { value: 'defaultvalue' } })
await waitFor(async () =>
expect(await findByTestId('uat')).toHaveValue('defaultvalue'),
)
})
})