import React, { useState } from 'react' import { fireEvent, render, screen } from '@testing-library/react' import { ItemRadio } from '../itemRadio' import { ItemRadioStatus } from '../itemRadio/ItemRadio' import { ItemRadioGroup, ItemRadioGroupProps } from './index' const defaultProps: ItemRadioGroupProps = { name: 'name', value: 2, onChange() {}, onClick() {}, status: ItemRadioStatus.DEFAULT, children: [ , , , ], } function createProps(props: Partial = {}): ItemRadioGroupProps { return { ...defaultProps, ...props } } describe('ItemRadioGroup', () => { it('Should render the 3 ItemRadio', () => { const props = createProps() render() expect(screen.getByRole('radiogroup')).toBeInTheDocument() expect(screen.getAllByRole('radio')).toHaveLength(3) }) it('Should change the checked radio when clicking on it', () => { const props = createProps() const Component = () => { const [radioValue, setRadioValue] = useState('2') return ( setRadioValue(value as string)} /> ) } render() const inputRadio3 = screen.getByRole('radio', { name: '3' }) expect(inputRadio3).not.toBeChecked() fireEvent.click(inputRadio3) expect(inputRadio3).toBeChecked() }) })