|
|
@@ -0,0 +1,82 @@
|
|
|
+import { describe, test, it, expect } from 'vitest'
|
|
|
+import DateUtils from "~/services/utils/dateUtils";
|
|
|
+
|
|
|
+describe('format', () => {
|
|
|
+ test('simple formatting', () => {
|
|
|
+ const input = new Date(2020, 4, 12)
|
|
|
+
|
|
|
+ expect(DateUtils.format(input, 'y-MM-dd')).toEqual('2020-05-12')
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('formatDatesAndConcat', () => {
|
|
|
+ test('simple array and default sep', () => {
|
|
|
+ const input = [
|
|
|
+ new Date(2023, 0, 10),
|
|
|
+ new Date(2023, 0, 11),
|
|
|
+ new Date(2023, 0, 12)
|
|
|
+ ]
|
|
|
+
|
|
|
+ const result = DateUtils.formatAndConcat(input, 'dd/MM/y')
|
|
|
+
|
|
|
+ expect(result).toEqual('10/01/2023 - 11/01/2023 - 12/01/2023')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('single date and default sep', () => {
|
|
|
+ const input = new Date(2023, 0, 10)
|
|
|
+
|
|
|
+ const result = DateUtils.formatAndConcat(input, 'dd/MM/y')
|
|
|
+
|
|
|
+ expect(result).toEqual('10/01/2023')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('simple array with other format and custom sep', () => {
|
|
|
+ const input = [
|
|
|
+ new Date(2023, 0, 10),
|
|
|
+ new Date(2023, 0, 11),
|
|
|
+ new Date(2023, 0, 12)
|
|
|
+ ]
|
|
|
+
|
|
|
+ const result = DateUtils.formatAndConcat(input, 'yMMdd', '|')
|
|
|
+
|
|
|
+ expect(result).toEqual('20230110|20230111|20230112')
|
|
|
+ })
|
|
|
+
|
|
|
+ test ('empty array', () => {
|
|
|
+ expect(DateUtils.formatAndConcat([], 'dd-MM-y')).toEqual('')
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('sortDate', () => {
|
|
|
+ test('simple sort', () => {
|
|
|
+ const input = [
|
|
|
+ new Date(2023, 0, 12),
|
|
|
+ new Date(2023, 0, 10),
|
|
|
+ new Date(2023, 0, 11)
|
|
|
+ ]
|
|
|
+
|
|
|
+ const expected = [
|
|
|
+ new Date(2023, 0, 10),
|
|
|
+ new Date(2023, 0, 11),
|
|
|
+ new Date(2023, 0, 12)
|
|
|
+ ]
|
|
|
+
|
|
|
+ expect(DateUtils.sort(input)).toEqual(expected)
|
|
|
+ })
|
|
|
+
|
|
|
+ test('reverse sort', () => {
|
|
|
+ const input = [
|
|
|
+ new Date(2023, 0, 12),
|
|
|
+ new Date(2023, 0, 10),
|
|
|
+ new Date(2023, 0, 11)
|
|
|
+ ]
|
|
|
+
|
|
|
+ const expected = [
|
|
|
+ new Date(2023, 0, 12),
|
|
|
+ new Date(2023, 0, 11),
|
|
|
+ new Date(2023, 0, 10)
|
|
|
+ ]
|
|
|
+
|
|
|
+ expect(DateUtils.sort(input, true)).toEqual(expected)
|
|
|
+ })
|
|
|
+})
|