convertFromSelect2Choices.spec.jsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import convertFromSelect2Choices from 'app/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(convertFromSelect2Choices([['a', 'A'], ['b', 'B'], ['c', 'C']])).toEqual([
  21. {
  22. label: 'A',
  23. value: 'a',
  24. },
  25. {
  26. label: 'B',
  27. value: 'b',
  28. },
  29. {
  30. label: 'C',
  31. value: 'c',
  32. },
  33. ]);
  34. });
  35. it('returns null on invalid values', function() {
  36. expect(convertFromSelect2Choices('test')).toEqual(null);
  37. expect(convertFromSelect2Choices(1)).toEqual(null);
  38. expect(convertFromSelect2Choices({})).toEqual(null);
  39. expect(convertFromSelect2Choices(undefined)).toEqual(null);
  40. });
  41. });