rangeField.spec.jsx 1.7 KB

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