import { fireEvent } from '@testing-library/react' import * as React from 'react' import renderWithTheme from '../../tests/helpers/renderWithTheme' import RadioButton from './RadioButton' describe('component: RadioButton', () => { test('should support margin space props', () => { const { container } = renderWithTheme( ) const radioBtn = container.querySelector('[id="SPACE PROPS YEAH"]')?.parentElement const styles = window.getComputedStyle(radioBtn as Element) expect(styles.margin).toBe('16px') }) test('should support ref prop', () => { const ref = React.createRef() const { getByTestId } = renderWithTheme( ) expect(getByTestId('inreffable')).toBe(ref.current) expect(ref.current).toBeChecked() }) test('should trigger onChange event', () => { const onChange = jest.fn() const { getByLabelText } = renderWithTheme( ) fireEvent.click(getByLabelText('will-change')) expect(onChange).toHaveBeenCalled() }) test('should trigger onFocus event', () => { const onFocus = jest.fn() const { getByLabelText } = renderWithTheme( ) fireEvent.focus(getByLabelText('will-focus')) expect(onFocus).toHaveBeenCalled() }) test('should trigger onFocus event', () => { const onBlur = jest.fn() const { getByLabelText } = renderWithTheme( ) fireEvent.blur(getByLabelText('will-blur')) expect(onBlur).toHaveBeenCalled() }) /* TODO: fireEvent.click and userEvent.click on a disabled radio button fall victim to the same problem that affects the checkboxes; it's a bug in @testing-library/react and/or user-event. If/when that issue is fixed, we should add tests to ensure that no events are triggered when the radio button is disabled. */ describe('with theme customization', () => { test('should not have box shadows on focus', () => { const { container } = renderWithTheme(, { boxShadows: false, }) const radioBtn = container.querySelector('[id="themability"]')?.parentElement const styles = window.getComputedStyle(radioBtn as Element) expect(styles.boxShadow).toBe('') }) }) })