multiSelectField.spec.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {MultiSelectField} from 'sentry/components/deprecatedforms';
  3. import Form from 'sentry/components/deprecatedforms/form';
  4. describe('MultiSelectField', function () {
  5. it('renders without form context', function () {
  6. const wrapper = render(
  7. <MultiSelectField
  8. options={[
  9. {label: 'a', value: 'a'},
  10. {label: 'b', value: 'b'},
  11. ]}
  12. name="fieldName"
  13. />
  14. );
  15. expect(wrapper.container).toSnapshot();
  16. });
  17. it('has the right value from props', function () {
  18. render(
  19. <form aria-label="Test Form">
  20. <MultiSelectField
  21. options={[
  22. {label: 'a', value: 'a'},
  23. {label: 'b', value: 'b'},
  24. ]}
  25. name="fieldName"
  26. value={['a']}
  27. />
  28. </form>
  29. );
  30. expect(screen.getByRole('form')).toHaveFormValues({fieldName: 'a'});
  31. });
  32. it('renders with form context', function () {
  33. render(
  34. <Form initialData={{fieldName: ['a', 'b']}} aria-label="Multi Form">
  35. <MultiSelectField
  36. options={[
  37. {label: 'a', value: 'a'},
  38. {label: 'b', value: 'b'},
  39. ]}
  40. name="fieldName"
  41. />
  42. </Form>
  43. );
  44. expect(screen.getByRole('form')).toHaveFormValues({fieldName: ['a', 'b']});
  45. });
  46. });