2023-01-10 05:06:12 -08:00
|
|
|
/**
|
|
|
|
* @jest-environment jsdom
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { extend } from '@/Extensions';
|
|
|
|
import { dateExtensions } from '@/Extensions/DateExtensions';
|
2023-01-12 07:06:34 -08:00
|
|
|
import { evaluate, getLocalISOString } from './Helpers';
|
2023-01-10 05:06:12 -08:00
|
|
|
|
|
|
|
describe('Data Transformation Functions', () => {
|
|
|
|
describe('Date Data Transformation Functions', () => {
|
|
|
|
test('.isWeekend() should work correctly on a date', () => {
|
|
|
|
expect(evaluate('={{DateTime.now().isWeekend()}}')).toEqual(
|
|
|
|
extend(new Date(), 'isWeekend', []),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('.toTimeFromNow() should work correctly on a date', () => {
|
|
|
|
const JUST_NOW_STRING_RESULT = 'just now';
|
|
|
|
expect(evaluate('={{DateTime.now().toTimeFromNow()}}')).toEqual(JUST_NOW_STRING_RESULT);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('.beginningOf("week") should work correctly on a date', () => {
|
|
|
|
expect(evaluate('={{(new Date).beginningOf("week")}}')).toEqual(
|
|
|
|
dateExtensions.functions.beginningOf(new Date(), ['week']),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('.endOfMonth() should work correctly on a date', () => {
|
|
|
|
expect(evaluate('={{ DateTime.now().endOfMonth() }}')).toEqual(
|
|
|
|
dateExtensions.functions.endOfMonth(new Date()),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('.extract("day") should work correctly on a date', () => {
|
|
|
|
expect(evaluate('={{ DateTime.now().extract("day") }}')).toEqual(
|
|
|
|
dateExtensions.functions.extract(new Date(), ['day']),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('.format("yyyy LLL dd") should work correctly on a date', () => {
|
|
|
|
expect(evaluate('={{ DateTime.now().format("yyyy LLL dd") }}')).toEqual(
|
|
|
|
dateExtensions.functions.format(new Date(), ['yyyy LLL dd']),
|
|
|
|
);
|
|
|
|
expect(evaluate('={{ DateTime.now().format("yyyy LLL dd") }}')).not.toEqual(
|
|
|
|
dateExtensions.functions.format(new Date(), ["HH 'hours and' mm 'minutes'"]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('.toDate() should work on a string', () => {
|
2023-01-12 07:06:34 -08:00
|
|
|
const date = new Date(2022, 0, 3);
|
|
|
|
expect(evaluate(`={{ "${getLocalISOString(date)}".toDate() }}`)).toEqual(date);
|
2023-01-10 05:06:12 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|