import { render, screen } from '@testing-library/react';
import { Checkbox } from '../../src';
import { renderWithEvents } from '../__helpers__/setUpTest';
describe('', () => {
it.each([['foo'], ['bar'], ['baz']])('includes extra class names when provided', (className) => {
const { container } = render();
expect(container.firstChild).toHaveAttribute('class', `form-check form-checkbox ${className}`);
});
it.each([[true], [false]])('marks input as checked if defined', (checked) => {
render(Foo);
if (checked) {
expect(screen.getByLabelText('Foo')).toBeChecked();
} else {
expect(screen.getByLabelText('Foo')).not.toBeChecked();
}
});
it.each([['foo'], ['bar'], ['baz']])('renders provided children inside the label', (children) => {
render({children});
expect(screen.getByText(children)).toHaveAttribute('class', 'form-check-label');
});
it.each([[true], [false]])('changes checked status on input change', async (checked) => {
const onChange = vi.fn();
const { user } = renderWithEvents(Foo);
expect(onChange).not.toHaveBeenCalled();
await user.click(screen.getByLabelText('Foo'));
expect(onChange).toHaveBeenCalledWith(!checked, expect.anything());
});
it.each([[true], [false]])('allows setting inline rendering', (inline) => {
const { container } = render();
if (inline) {
expect(container.firstChild).toHaveAttribute('style', 'display: inline-block;');
} else {
expect(container.firstChild).not.toHaveAttribute('style');
}
});
});