selectOptions.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import { formatSelectOptions, formatSelectOptionsForRange } from '../../src';
  20. describe('formatSelectOptions', () => {
  21. it('formats an array of options', () => {
  22. expect(formatSelectOptions([1, 5, 10, 25, 50, 'unlimited'])).toEqual([
  23. [1, '1'],
  24. [5, '5'],
  25. [10, '10'],
  26. [25, '25'],
  27. [50, '50'],
  28. ['unlimited', 'unlimited'],
  29. ]);
  30. });
  31. it('formats a mix of values and already formated options', () => {
  32. expect(
  33. formatSelectOptions<number | string>([
  34. [0, 'all'],
  35. 1,
  36. 5,
  37. 10,
  38. 25,
  39. 50,
  40. 'unlimited',
  41. ]),
  42. ).toEqual([
  43. [0, 'all'],
  44. [1, '1'],
  45. [5, '5'],
  46. [10, '10'],
  47. [25, '25'],
  48. [50, '50'],
  49. ['unlimited', 'unlimited'],
  50. ]);
  51. });
  52. });
  53. describe('formatSelectOptionsForRange', () => {
  54. it('generates select options from a range', () => {
  55. expect(formatSelectOptionsForRange(1, 5)).toEqual([
  56. [1, '1'],
  57. [2, '2'],
  58. [3, '3'],
  59. [4, '4'],
  60. [5, '5'],
  61. ]);
  62. });
  63. });