import {useState} from 'react';
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
import Checkbox from 'sentry/components/checkbox';
describe('Checkbox', function () {
const defaultProps = {
checked: false,
onChange: jest.fn(),
};
describe('snapshots', function () {
it('unchecked state', async function () {
const {container} = render();
expect(await screen.findByRole('checkbox')).toBeInTheDocument();
expect(container).toSnapshot();
});
it('checked state', async function () {
const {container} = render();
expect(await screen.findByRole('checkbox')).toBeInTheDocument();
expect(container).toSnapshot();
});
it('indeterminate state', async function () {
const {container} = render();
expect(await screen.findByRole('checkbox')).toBeInTheDocument();
expect(container).toSnapshot();
});
});
describe('behavior', function () {
function CheckboxWithLabel() {
const [checked, setChecked] = useState(false);
return (
);
}
it('toggles on click', function () {
render();
expect(screen.getByRole('checkbox')).not.toBeChecked();
userEvent.click(screen.getByLabelText('Label text'));
expect(screen.getByRole('checkbox')).toBeChecked();
});
});
});