import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Radio } from '../Radio';
const props = {
onChange: jest.fn()
};
describe('Radio', () => {
test('controlled', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('uncontrolled', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('isDisabled', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('isLabelBeforeButton', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
test('isLabelWrapped', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
test('label is string', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('label is function', () => {
const functionLabel = () =>
Header
;
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
test('label is node', () => {
const { asFragment } = render(
Header} id="check" isChecked aria-label="check" name="check" />
);
expect(asFragment()).toMatchSnapshot();
});
test('passing class', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
test('passing HTML attribute', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
test('Radio passes value and event to onChange handler', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('radio'));
expect(props.onChange).toHaveBeenCalledWith(expect.any(Object), true);
});
test('Radio description', () => {
render();
expect(screen.getByText('Text description...')).toBeInTheDocument();
});
test('Radio body', () => {
render();
expect(screen.getByText('Text body...')).toBeInTheDocument();
});
test('should throw console error when no id is given', () => {
const myMock = jest.fn();
global.console = { ...global.console, error: myMock };
render();
expect(myMock).toHaveBeenCalled();
});
});