rangeField.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import {shallow} from 'enzyme';
  3. import {RangeField} from 'app/components/forms';
  4. describe('RangeField', function() {
  5. describe('render()', function() {
  6. it('renders', function() {
  7. let wrapper = shallow(<RangeField name="fieldName" />);
  8. expect(wrapper).toMatchSnapshot();
  9. });
  10. it('renders with optional attributes', function() {
  11. let wrapper = shallow(
  12. <RangeField
  13. name="fieldName"
  14. min={0}
  15. max={3}
  16. step={1}
  17. snap={false}
  18. allowedValues={[1, 2, 3]}
  19. />
  20. );
  21. expect(wrapper).toMatchSnapshot();
  22. });
  23. it('renders with value', function() {
  24. let wrapper = shallow(<RangeField name="fieldName" value={2} />);
  25. expect(wrapper).toMatchSnapshot();
  26. });
  27. it('renders with form context', function() {
  28. let wrapper = shallow(<RangeField name="fieldName" />, {
  29. context: {
  30. form: {
  31. data: {
  32. fieldName: 2,
  33. },
  34. errors: {},
  35. },
  36. },
  37. });
  38. expect(wrapper).toMatchSnapshot();
  39. });
  40. it('renders with value=0 in form context', function() {
  41. let wrapper = shallow(<RangeField name="fieldName" />, {
  42. context: {
  43. form: {
  44. data: {
  45. fieldName: 0,
  46. },
  47. errors: {},
  48. },
  49. },
  50. });
  51. expect(wrapper.find('input').prop('value')).toBe(0);
  52. });
  53. });
  54. });