numberField.spec.jsx 1.3 KB

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