radioBooleanField.spec.jsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Form, RadioBooleanField} from 'sentry/components/deprecatedforms';
  3. import NewRadioBooleanField from 'sentry/components/forms/radioBooleanField';
  4. describe('RadioBooleanField', function () {
  5. it('renders without form context', function () {
  6. const wrapper = render(
  7. <RadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  8. );
  9. expect(wrapper.container).toSnapshot();
  10. });
  11. it('renders with form context', function () {
  12. const wrapper = render(
  13. <Form initialData={{fieldName: true}}>
  14. <RadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  15. </Form>
  16. );
  17. expect(wrapper.container).toSnapshot();
  18. });
  19. it('renders new field without form context', function () {
  20. const wrapper = render(
  21. <NewRadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  22. );
  23. expect(wrapper.container).toSnapshot();
  24. });
  25. it('can change values', function () {
  26. const changeMock = jest.fn();
  27. const blurMock = jest.fn();
  28. render(
  29. <NewRadioBooleanField
  30. onChange={changeMock}
  31. onBlur={blurMock}
  32. name="fieldName"
  33. yesLabel="Yes"
  34. noLabel="No"
  35. />
  36. );
  37. userEvent.click(screen.getByRole('radio', {name: 'Yes'}));
  38. expect(changeMock).toHaveBeenCalledWith(true, expect.anything());
  39. userEvent.click(screen.getByRole('radio', {name: 'No'}));
  40. expect(changeMock).toHaveBeenCalledWith(false, expect.anything());
  41. expect(blurMock).toHaveBeenCalledTimes(2);
  42. });
  43. });