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 Radio from './index'
import { act } from 'react-dom/test-utils'
const Container = ({
validate,
initiallySelected: initialySelected,
}: {
validate?: any
initiallySelected: number
}) => {
return (
{}}>
value 1
value 2
value 3
)
}
test.skip('should select initial value', async () => {
const { findByTestId, debug } = render()
const radio = await findByTestId('radio2')
console.log(radio)
expect(await findByTestId('radio2')).toBeChecked()
expect(await findByTestId('radio1')).not.toBeChecked()
expect(await findByTestId('radio3')).not.toBeChecked()
})
test.skip('should change', async () => {
const { findByTestId } = render()
const radio1 = await findByTestId('radio1')
const radio2 = await findByTestId('radio2')
expect(radio1).toBeChecked()
expect(radio2).not.toBeChecked()
await act(async () => {
fireEvent.click(radio2, { checked: true })
await waitFor(() => {
expect(radio2).toBeChecked()
expect(radio1).not.toBeChecked()
})
})
})
test.skip('should change', async () => {
const { findByTestId } = render()
const radio1 = await findByTestId('radio1')
const radio2 = await findByTestId('radio2')
expect(radio1).toBeChecked()
expect(radio2).not.toBeChecked()
await act(async () => {
fireEvent.click(radio2, { checked: true })
await waitFor(() => {
expect(radio2).toBeChecked()
expect(radio1).not.toBeChecked()
})
})
})
test.skip('should validate once per click', async () => {
const validate = jest.fn()
const { findByTestId } = render(
,
)
const radio2 = await findByTestId('radio2')
await act(async () => {
fireEvent.click(radio2, { checked: true })
await waitFor(() => expect(validate).toBeCalledTimes(1))
})
})