dateUtils.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, test, it, expect } from 'vitest'
  2. import DateUtils from "~/services/utils/dateUtils";
  3. describe('format', () => {
  4. test('simple formatting', () => {
  5. const input = new Date(2020, 4, 12)
  6. expect(DateUtils.format(input, 'y-MM-dd')).toEqual('2020-05-12')
  7. })
  8. })
  9. describe('formatDatesAndConcat', () => {
  10. test('simple array and default sep', () => {
  11. const input = [
  12. new Date(2023, 0, 10),
  13. new Date(2023, 0, 11),
  14. new Date(2023, 0, 12)
  15. ]
  16. const result = DateUtils.formatAndConcat(input, 'dd/MM/y')
  17. expect(result).toEqual('10/01/2023 - 11/01/2023 - 12/01/2023')
  18. })
  19. test('single date and default sep', () => {
  20. const input = new Date(2023, 0, 10)
  21. const result = DateUtils.formatAndConcat(input, 'dd/MM/y')
  22. expect(result).toEqual('10/01/2023')
  23. })
  24. test('simple array with other format and custom sep', () => {
  25. const input = [
  26. new Date(2023, 0, 10),
  27. new Date(2023, 0, 11),
  28. new Date(2023, 0, 12)
  29. ]
  30. const result = DateUtils.formatAndConcat(input, 'yMMdd', '|')
  31. expect(result).toEqual('20230110|20230111|20230112')
  32. })
  33. test ('empty array', () => {
  34. expect(DateUtils.formatAndConcat([], 'dd-MM-y')).toEqual('')
  35. })
  36. })
  37. describe('sortDate', () => {
  38. test('sort', () => {
  39. // TODO: should assert that ArrayUtils.sort is called
  40. })
  41. })