radioBooleanField.spec.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import {shallow, mount} from 'enzyme';
  3. import {RadioBooleanField} from 'app/components/forms';
  4. import NewRadioBooleanField from 'app/views/settings/components/forms/radioBooleanField';
  5. describe('RadioBooleanField', function() {
  6. describe('render()', function() {
  7. it('renders without form context', function() {
  8. let wrapper = shallow(
  9. <RadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  10. );
  11. expect(wrapper).toMatchSnapshot();
  12. });
  13. it('renders with form context', function() {
  14. let wrapper = shallow(
  15. <RadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />,
  16. {
  17. context: {
  18. form: {
  19. data: {
  20. fieldName: true,
  21. },
  22. errors: {},
  23. },
  24. },
  25. }
  26. );
  27. expect(wrapper).toMatchSnapshot();
  28. });
  29. it('renders new field without form context', function() {
  30. let wrapper = mount(
  31. <NewRadioBooleanField name="fieldName" yesLabel="Yes" noLabel="No" />
  32. );
  33. expect(wrapper).toMatchSnapshot();
  34. });
  35. it('can change values', function() {
  36. let mock = jest.fn();
  37. let wrapper = mount(
  38. <NewRadioBooleanField
  39. onChange={mock}
  40. name="fieldName"
  41. yesLabel="Yes"
  42. noLabel="No"
  43. />
  44. );
  45. wrapper.find('input[value="true"]').simulate('change');
  46. expect(mock).toHaveBeenCalledWith(true, expect.anything());
  47. wrapper.find('input[value="false"]').simulate('change');
  48. expect(mock).toHaveBeenCalledWith(false, expect.anything());
  49. });
  50. });
  51. });