radioBooleanField.spec.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {Form, RadioBooleanField} from 'app/components/forms';
  3. import NewRadioBooleanField from 'app/views/settings/components/forms/radioBooleanField';
  4. describe('RadioBooleanField', function () {
  5. describe('render()', function () {
  6. it('renders without form context', function () {
  7. const wrapper = mountWithTheme(
  8. <RadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  9. );
  10. expect(wrapper).toSnapshot();
  11. });
  12. it('renders with form context', function () {
  13. const wrapper = mountWithTheme(
  14. <Form initialData={{fieldName: true}}>
  15. <RadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  16. </Form>
  17. );
  18. expect(wrapper).toSnapshot();
  19. });
  20. it('renders new field without form context', function () {
  21. const wrapper = mountWithTheme(
  22. <NewRadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  23. );
  24. expect(wrapper).toSnapshot();
  25. });
  26. it('can change values', function () {
  27. const mock = jest.fn();
  28. const wrapper = mountWithTheme(
  29. <NewRadioBooleanField
  30. onChange={mock}
  31. name="fieldName"
  32. yesLabel="Yes"
  33. noLabel="No"
  34. />
  35. );
  36. wrapper.find('input[value="true"]').simulate('change');
  37. expect(mock).toHaveBeenCalledWith(true, expect.anything());
  38. wrapper.find('input[value="false"]').simulate('change');
  39. expect(mock).toHaveBeenCalledWith(false, expect.anything());
  40. });
  41. });
  42. });