booleanField.spec.jsx 927 B

1234567891011121314151617181920212223242526272829
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {BooleanField, Form} from 'sentry/components/deprecatedforms';
  3. describe('BooleanField', function () {
  4. it('renders without form context', function () {
  5. const wrapper = render(<BooleanField name="fieldName" />);
  6. expect(wrapper.container).toSnapshot();
  7. });
  8. it('renders with form context', function () {
  9. const wrapper = render(
  10. <Form initialData={{fieldName: true}}>
  11. <BooleanField name="fieldName" />
  12. </Form>
  13. );
  14. expect(wrapper.container).toSnapshot();
  15. });
  16. it('toggles', function () {
  17. const onChange = jest.fn();
  18. render(<BooleanField name="fieldName" onChange={onChange} />);
  19. userEvent.click(screen.getByRole('checkbox'));
  20. expect(onChange).toHaveBeenCalledWith(true);
  21. userEvent.click(screen.getByRole('checkbox'));
  22. expect(onChange).toHaveBeenCalledWith(false);
  23. });
  24. });