import React from 'react';
import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import 'jest-styled-components';
import 'jest-axe/extend-expect';
import 'regenerator-runtime/runtime';
import { Grommet } from '../../Grommet';
import { Box } from '../../Box';
import { RadioButton } from '..';
describe('RadioButton', () => {
test('should have no accessibility violations', async () => {
const { container } = render(
,
);
const results = await axe(container);
expect(results).toHaveNoViolations();
expect(container.firstChild).toMatchSnapshot();
});
test('basic', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('label', () => {
const { container } = render(
test label} name="test" value="2" />
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('checked', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('disabled', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('children', () => {
const child = ({ checked }: { checked: boolean }) => (
);
const { container } = render(
{child}
{child}
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('label themed', () => {
const customTheme = {
radioButton: {
font: {
weight: 500,
},
},
};
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('background-color themed', () => {
const customTheme = {
radioButton: {
check: {
background: {
color: 'red',
},
},
},
};
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('background-color themed symbolic', () => {
const customTheme = {
radioButton: {
check: {
background: {
color: 'brand',
},
},
},
};
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
test('renders custom circle icon', () => {
const CustomCircleIcon = ({ ...rest }) => (
);
const customTheme = {
radioButton: {
icons: {
circle: CustomCircleIcon,
},
},
};
const { container, getByTestId } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
expect(getByTestId('custom-radioButton-icon')).toBeDefined();
});
test('should apply a11yTitle or aria-label', () => {
const { container, getByLabelText } = render(
,
);
expect(getByLabelText('test')).toBeTruthy();
expect(getByLabelText('test-2')).toBeTruthy();
expect(container.firstChild).toMatchSnapshot();
});
});