numberField.spec.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {NumberField} from 'sentry/components/deprecatedforms';
  3. import Form from 'sentry/components/deprecatedforms/form';
  4. describe('NumberField', function () {
  5. describe('render()', function () {
  6. it('renders', function () {
  7. const wrapper = render(<NumberField name="fieldName" />);
  8. expect(wrapper.container).toSnapshot();
  9. });
  10. it('renders with optional attributes', function () {
  11. const wrapper = render(<NumberField name="fieldName" min={0} max={100} />);
  12. expect(wrapper.container).toSnapshot();
  13. });
  14. it('renders with value', function () {
  15. render(<NumberField name="fieldName" value={5} />);
  16. expect(screen.getByRole('spinbutton')).toHaveValue(5);
  17. });
  18. it('renders with form context', function () {
  19. render(
  20. <Form initialData={{fieldName: 5}}>
  21. <NumberField name="fieldName" />
  22. </Form>
  23. );
  24. expect(screen.getByRole('spinbutton')).toHaveValue(5);
  25. });
  26. it('doesnt save `NaN` when new value is empty string', function () {
  27. render(
  28. <Form initialData={{fieldName: 5}}>
  29. <NumberField name="fieldName" defaultValue="5" />
  30. </Form>
  31. );
  32. expect(screen.getByRole('spinbutton')).toHaveValue(5);
  33. userEvent.clear(screen.getByRole('spinbutton'));
  34. expect(screen.getByRole('spinbutton')).toHaveValue(null);
  35. });
  36. });
  37. });