convertFromSelect2Choices.spec.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import convertFromSelect2Choices from 'sentry/utils/convertFromSelect2Choices';
  2. describe('convertFromSelect2Choices', function () {
  3. it('changes a flat array of strings into array of {label, value}', function () {
  4. expect(convertFromSelect2Choices(['a', 'b', 'c'])).toEqual([
  5. {
  6. label: 'a',
  7. value: 'a',
  8. },
  9. {
  10. label: 'b',
  11. value: 'b',
  12. },
  13. {
  14. label: 'c',
  15. value: 'c',
  16. },
  17. ]);
  18. });
  19. it('changes a paired array of strings into array of {label, value}', function () {
  20. expect(
  21. convertFromSelect2Choices([
  22. ['a', 'A'],
  23. ['b', 'B'],
  24. ['c', 'C'],
  25. ])
  26. ).toEqual([
  27. {
  28. label: 'A',
  29. value: 'a',
  30. },
  31. {
  32. label: 'B',
  33. value: 'b',
  34. },
  35. {
  36. label: 'C',
  37. value: 'c',
  38. },
  39. ]);
  40. });
  41. it('returns null on invalid values', function () {
  42. expect(convertFromSelect2Choices('test')).toBeUndefined();
  43. expect(convertFromSelect2Choices(1)).toBeUndefined();
  44. expect(convertFromSelect2Choices({})).toBeUndefined();
  45. expect(convertFromSelect2Choices(undefined)).toBeUndefined();
  46. });
  47. });