numberField.spec.jsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import {NumberField} from 'app/components/forms';
  3. import Form from 'app/components/forms/form';
  4. import {shallow, mount} from 'enzyme';
  5. jest.mock('jquery');
  6. describe('NumberField', function() {
  7. describe('render()', function() {
  8. it('renders', function() {
  9. const wrapper = shallow(<NumberField name="fieldName" />);
  10. expect(wrapper).toMatchSnapshot();
  11. });
  12. it('renders with optional attributes', function() {
  13. const wrapper = shallow(<NumberField name="fieldName" min={0} max={100} />);
  14. expect(wrapper).toMatchSnapshot();
  15. });
  16. it('renders with value', function() {
  17. const wrapper = shallow(<NumberField name="fieldName" value={5} />);
  18. expect(wrapper).toMatchSnapshot();
  19. });
  20. it('renders with form context', function() {
  21. const wrapper = shallow(<NumberField name="fieldName" />, {
  22. context: {
  23. form: {
  24. data: {
  25. fieldName: 5,
  26. },
  27. errors: {},
  28. },
  29. },
  30. });
  31. expect(wrapper).toMatchSnapshot();
  32. });
  33. it('doesnt save `NaN` when new value is empty string', function() {
  34. const wrapper = mount(
  35. <Form onSubmit={() => {}}>
  36. <NumberField name="fieldName" defaultValue="2" />
  37. </Form>
  38. );
  39. wrapper.find('input').simulate('change', {target: {value: ''}});
  40. expect(wrapper.state('data').fieldName).toBe('');
  41. });
  42. });
  43. });