|
@@ -1,5 +1,5 @@
|
|
|
import { describe, test, it, expect } from 'vitest'
|
|
import { describe, test, it, expect } from 'vitest'
|
|
|
-import DateUtils from "~/services/utils/dateUtils";
|
|
|
|
|
|
|
+import DateUtils, {supportedLocales} from "~/services/utils/dateUtils";
|
|
|
|
|
|
|
|
describe('format', () => {
|
|
describe('format', () => {
|
|
|
test('simple formatting', () => {
|
|
test('simple formatting', () => {
|
|
@@ -49,6 +49,61 @@ describe('formatDatesAndConcat', () => {
|
|
|
|
|
|
|
|
describe('sortDate', () => {
|
|
describe('sortDate', () => {
|
|
|
test('sort', () => {
|
|
test('sort', () => {
|
|
|
- // TODO: should assert that ArrayUtils.sort is called
|
|
|
|
|
|
|
+ test('simple array', () => {
|
|
|
|
|
+ const date1 = new Date(2023, 0, 10)
|
|
|
|
|
+ const date2 = new Date(2023, 0, 14)
|
|
|
|
|
+ const date3 = new Date(2023, 0, 12)
|
|
|
|
|
+
|
|
|
|
|
+ const input = [date1, date2, date3]
|
|
|
|
|
+
|
|
|
|
|
+ const result = DateUtils.sort(input)
|
|
|
|
|
+
|
|
|
|
|
+ expect(result).toEqual([date1, date3, date2])
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('simple array reverse', () => {
|
|
|
|
|
+ const date1 = new Date(2023, 0, 10)
|
|
|
|
|
+ const date2 = new Date(2023, 0, 14)
|
|
|
|
|
+ const date3 = new Date(2023, 0, 12)
|
|
|
|
|
+
|
|
|
|
|
+ const input = [date1, date2, date3]
|
|
|
|
|
+
|
|
|
|
|
+ const result = DateUtils.sort(input)
|
|
|
|
|
+
|
|
|
|
|
+ expect(result).toEqual([date2, date3, date1])
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+describe('getFnsLocale', () => {
|
|
|
|
|
+ test('standard call', () => {
|
|
|
|
|
+ expect(DateUtils.getFnsLocale(supportedLocales.FR).code).toEqual('fr')
|
|
|
|
|
+ expect(DateUtils.getFnsLocale(supportedLocales.EN).code).toEqual('en-US')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('unsupported locale', () => {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(DateUtils.getFnsLocale('xx').code).toEqual('fr')
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+describe('getShortFormatPattern', () => {
|
|
|
|
|
+ test('standard call', () => {
|
|
|
|
|
+ expect(DateUtils.getShortFormatPattern(supportedLocales.FR)).toEqual('dd/MM/yyyy')
|
|
|
|
|
+ expect(DateUtils.getShortFormatPattern(supportedLocales.EN)).toEqual('MM/dd/yyyy')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('unsupported locale', () => {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(DateUtils.getShortFormatPattern('xx')).toEqual('dd/MM/yyyy')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+describe('formatIsoShortDate', () => {
|
|
|
|
|
+ test('standard call', () => {
|
|
|
|
|
+ expect(DateUtils.formatIsoShortDate(new Date(2023, 0, 10))).toEqual('2023-01-10')
|
|
|
|
|
+ expect(DateUtils.formatIsoShortDate(new Date(2023, 11, 20))).toEqual('2023-12-20')
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+
|