multiSelectField.spec.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import {shallow} from 'enzyme';
  3. import {MultiSelectField} from 'app/components/forms';
  4. describe('MultiSelectField', function() {
  5. describe('render()', function() {
  6. it('renders without form context', function() {
  7. const wrapper = shallow(
  8. <MultiSelectField
  9. options={[{label: 'a', value: 'a'}, {label: 'b', value: 'b'}]}
  10. name="fieldName"
  11. />
  12. );
  13. expect(wrapper).toMatchSnapshot();
  14. });
  15. it('has the right value from props', function() {
  16. const wrapper = shallow(
  17. <MultiSelectField
  18. options={[{label: 'a', value: 'a'}, {label: 'b', value: 'b'}]}
  19. name="fieldName"
  20. value={['a']}
  21. />
  22. );
  23. expect(wrapper.find('StyledSelectControl').prop('value')).toEqual(['a']);
  24. });
  25. it('renders with form context', function() {
  26. const wrapper = shallow(
  27. <MultiSelectField
  28. options={[{label: 'a', value: 'a'}, {label: 'b', value: 'b'}]}
  29. name="fieldName"
  30. />,
  31. {
  32. context: {
  33. form: {
  34. data: {
  35. fieldName: ['a', 'b'],
  36. },
  37. errors: {},
  38. },
  39. },
  40. }
  41. );
  42. expect(wrapper.find('StyledSelectControl').prop('value')).toEqual(['a', 'b']);
  43. });
  44. });
  45. });