mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:15:11 +00:00
Merge branch 'main' into next
This commit is contained in:
commit
ec20b74157
@ -144,127 +144,127 @@ describe('getDateRanges: fieldOperator is $dateBetween', () => {
|
|||||||
const dateRanges = getDateRanges();
|
const dateRanges = getDateRanges();
|
||||||
|
|
||||||
it('today', () => {
|
it('today', () => {
|
||||||
const [start, end] = dateRanges.today({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.today({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('day').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('day').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('day').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('yesterday', () => {
|
test('yesterday', () => {
|
||||||
const [start, end] = dateRanges.yesterday({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.yesterday({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(dayjs(start).isSame(dayjs().subtract(1, 'day'), 'day')).toBe(true);
|
expect(dayjs(start).isSame(dayjs().subtract(1, 'day'), 'day')).toBe(true);
|
||||||
expect(dayjs(end).isSame(dayjs().subtract(1, 'day'), 'day')).toBe(true);
|
expect(dayjs(end).isSame(dayjs().subtract(1, 'day'), 'day')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tomorrow', () => {
|
test('tomorrow', () => {
|
||||||
const [start, end] = dateRanges.tomorrow({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.tomorrow({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(dayjs(start).isSame(dayjs().add(1, 'day'), 'day')).toBe(true);
|
expect(dayjs(start).isSame(dayjs().add(1, 'day'), 'day')).toBe(true);
|
||||||
expect(dayjs(end).isSame(dayjs().add(1, 'day'), 'day')).toBe(true);
|
expect(dayjs(end).isSame(dayjs().add(1, 'day'), 'day')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastWeek', () => {
|
it('lastWeek', () => {
|
||||||
const [start, end] = dateRanges.lastWeek({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.lastWeek({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'week').startOf('isoWeek').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'week').startOf('isoWeek').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(-1, 'week').endOf('isoWeek').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(-1, 'week').endOf('isoWeek').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisWeek', () => {
|
it('thisWeek', () => {
|
||||||
const [start, end] = dateRanges.thisWeek({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.thisWeek({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('isoWeek').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('isoWeek').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('isoWeek').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('isoWeek').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextWeek', () => {
|
it('nextWeek', () => {
|
||||||
const [start, end] = dateRanges.nextWeek({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.nextWeek({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'week').startOf('isoWeek').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'week').startOf('isoWeek').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(1, 'week').endOf('isoWeek').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(1, 'week').endOf('isoWeek').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastMonth', () => {
|
it('lastMonth', () => {
|
||||||
const [start, end] = dateRanges.lastMonth({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.lastMonth({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'month').startOf('month').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'month').startOf('month').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(-1, 'month').endOf('month').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(-1, 'month').endOf('month').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisMonth', () => {
|
it('thisMonth', () => {
|
||||||
const [start, end] = dateRanges.thisMonth({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.thisMonth({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('month').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('month').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('month').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('month').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextMonth', () => {
|
it('nextMonth', () => {
|
||||||
const [start, end] = dateRanges.nextMonth({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.nextMonth({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'month').startOf('month').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'month').startOf('month').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(1, 'month').endOf('month').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(1, 'month').endOf('month').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastQuarter', () => {
|
it('lastQuarter', () => {
|
||||||
const [start, end] = dateRanges.lastQuarter({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.lastQuarter({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'quarter').startOf('quarter').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'quarter').startOf('quarter').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(-1, 'quarter').endOf('quarter').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(-1, 'quarter').endOf('quarter').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisQuarter', () => {
|
it('thisQuarter', () => {
|
||||||
const [start, end] = dateRanges.thisQuarter({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.thisQuarter({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('quarter').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('quarter').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('quarter').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('quarter').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextQuarter', () => {
|
it('nextQuarter', () => {
|
||||||
const [start, end] = dateRanges.nextQuarter({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.nextQuarter({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'quarter').startOf('quarter').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'quarter').startOf('quarter').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(1, 'quarter').endOf('quarter').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(1, 'quarter').endOf('quarter').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastYear', () => {
|
it('lastYear', () => {
|
||||||
const [start, end] = dateRanges.lastYear({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.lastYear({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'year').startOf('year').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'year').startOf('year').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(-1, 'year').endOf('year').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(-1, 'year').endOf('year').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisYear', () => {
|
it('thisYear', () => {
|
||||||
const [start, end] = dateRanges.thisYear({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.thisYear({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('year').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('year').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('year').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('year').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextYear', () => {
|
it('nextYear', () => {
|
||||||
const [start, end] = dateRanges.nextYear({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.nextYear({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'year').startOf('year').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'year').startOf('year').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(1, 'year').endOf('year').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(1, 'year').endOf('year').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('last7Days', () => {
|
it('last7Days', () => {
|
||||||
const [start, end] = dateRanges.last7Days({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.last7Days({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-6, 'days').startOf('days').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-6, 'days').startOf('days').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('days').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('next7Days', () => {
|
it('next7Days', () => {
|
||||||
const [start, end] = dateRanges.next7Days({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.next7Days({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(7, 'days').endOf('days').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(7, 'days').endOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('last30Days', () => {
|
it('last30Days', () => {
|
||||||
const [start, end] = dateRanges.last30Days({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.last30Days({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-29, 'days').startOf('days').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-29, 'days').startOf('days').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('days').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('next30Days', () => {
|
it('next30Days', () => {
|
||||||
const [start, end] = dateRanges.next30Days({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.next30Days({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(30, 'days').endOf('days').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(30, 'days').endOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('last90Days', () => {
|
it('last90Days', () => {
|
||||||
const [start, end] = dateRanges.last90Days({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.last90Days({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-89, 'days').startOf('days').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-89, 'days').startOf('days').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().endOf('days').toISOString());
|
expect(end.toISOString()).toBe(dayjs().endOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('next90Days', () => {
|
it('next90Days', () => {
|
||||||
const [start, end] = dateRanges.next90Days({ fieldOperator: '$dateBetween' });
|
const [start, end] = dateRanges.next90Days({ fieldOperator: '$dateBetween', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
||||||
expect(end.toISOString()).toBe(dayjs().add(90, 'days').endOf('days').toISOString());
|
expect(end.toISOString()).toBe(dayjs().add(90, 'days').endOf('days').toISOString());
|
||||||
});
|
});
|
||||||
@ -274,107 +274,107 @@ describe('getDateRanges: fieldOperator is not $dateBetween', () => {
|
|||||||
const dateRanges = getDateRanges();
|
const dateRanges = getDateRanges();
|
||||||
|
|
||||||
it('today', () => {
|
it('today', () => {
|
||||||
const start = dateRanges.today({ fieldOperator: '$dateOn' });
|
const start = dateRanges.today({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('day').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('yesterday', () => {
|
test('yesterday', () => {
|
||||||
const start = dateRanges.yesterday({ fieldOperator: '$dateOn' });
|
const start = dateRanges.yesterday({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(dayjs(start).isSame(dayjs().subtract(1, 'day'), 'day')).toBe(true);
|
expect(dayjs(start).isSame(dayjs().subtract(1, 'day'), 'day')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tomorrow', () => {
|
test('tomorrow', () => {
|
||||||
const start = dateRanges.tomorrow({ fieldOperator: '$dateOn' });
|
const start = dateRanges.tomorrow({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(dayjs(start).isSame(dayjs().add(1, 'day'), 'day')).toBe(true);
|
expect(dayjs(start).isSame(dayjs().add(1, 'day'), 'day')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastWeek', () => {
|
it('lastWeek', () => {
|
||||||
const start = dateRanges.lastWeek({ fieldOperator: '$dateOn' });
|
const start = dateRanges.lastWeek({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'week').startOf('isoWeek').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'week').startOf('isoWeek').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisWeek', () => {
|
it('thisWeek', () => {
|
||||||
const start = dateRanges.thisWeek({ fieldOperator: '$dateOn' });
|
const start = dateRanges.thisWeek({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('isoWeek').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('isoWeek').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextWeek', () => {
|
it('nextWeek', () => {
|
||||||
const start = dateRanges.nextWeek({ fieldOperator: '$dateOn' });
|
const start = dateRanges.nextWeek({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'week').startOf('isoWeek').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'week').startOf('isoWeek').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastMonth', () => {
|
it('lastMonth', () => {
|
||||||
const start = dateRanges.lastMonth({ fieldOperator: '$dateOn' });
|
const start = dateRanges.lastMonth({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'month').startOf('month').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'month').startOf('month').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisMonth', () => {
|
it('thisMonth', () => {
|
||||||
const start = dateRanges.thisMonth({ fieldOperator: '$dateOn' });
|
const start = dateRanges.thisMonth({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('month').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('month').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextMonth', () => {
|
it('nextMonth', () => {
|
||||||
const start = dateRanges.nextMonth({ fieldOperator: '$dateOn' });
|
const start = dateRanges.nextMonth({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'month').startOf('month').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'month').startOf('month').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastQuarter', () => {
|
it('lastQuarter', () => {
|
||||||
const start = dateRanges.lastQuarter({ fieldOperator: '$dateOn' });
|
const start = dateRanges.lastQuarter({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'quarter').startOf('quarter').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'quarter').startOf('quarter').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisQuarter', () => {
|
it('thisQuarter', () => {
|
||||||
const start = dateRanges.thisQuarter({ fieldOperator: '$dateOn' });
|
const start = dateRanges.thisQuarter({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('quarter').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('quarter').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextQuarter', () => {
|
it('nextQuarter', () => {
|
||||||
const start = dateRanges.nextQuarter({ fieldOperator: '$dateOn' });
|
const start = dateRanges.nextQuarter({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'quarter').startOf('quarter').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'quarter').startOf('quarter').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lastYear', () => {
|
it('lastYear', () => {
|
||||||
const start = dateRanges.lastYear({ fieldOperator: '$dateOn' });
|
const start = dateRanges.lastYear({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-1, 'year').startOf('year').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-1, 'year').startOf('year').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('thisYear', () => {
|
it('thisYear', () => {
|
||||||
const start = dateRanges.thisYear({ fieldOperator: '$dateOn' });
|
const start = dateRanges.thisYear({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().startOf('year').toISOString());
|
expect(start.toISOString()).toBe(dayjs().startOf('year').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nextYear', () => {
|
it('nextYear', () => {
|
||||||
const start = dateRanges.nextYear({ fieldOperator: '$dateOn' });
|
const start = dateRanges.nextYear({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'year').startOf('year').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'year').startOf('year').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('last7Days', () => {
|
it('last7Days', () => {
|
||||||
const start = dateRanges.last7Days({ fieldOperator: '$dateOn' });
|
const start = dateRanges.last7Days({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-6, 'days').startOf('days').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-6, 'days').startOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('next7Days', () => {
|
it('next7Days', () => {
|
||||||
const start = dateRanges.next7Days({ fieldOperator: '$dateOn' });
|
const start = dateRanges.next7Days({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('last30Days', () => {
|
it('last30Days', () => {
|
||||||
const start = dateRanges.last30Days({ fieldOperator: '$dateOn' });
|
const start = dateRanges.last30Days({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-29, 'days').startOf('days').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-29, 'days').startOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('next30Days', () => {
|
it('next30Days', () => {
|
||||||
const start = dateRanges.next30Days({ fieldOperator: '$dateOn' });
|
const start = dateRanges.next30Days({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('last90Days', () => {
|
it('last90Days', () => {
|
||||||
const start = dateRanges.last90Days({ fieldOperator: '$dateOn' });
|
const start = dateRanges.last90Days({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(-89, 'days').startOf('days').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(-89, 'days').startOf('days').toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('next90Days', () => {
|
it('next90Days', () => {
|
||||||
const start = dateRanges.next90Days({ fieldOperator: '$dateOn' });
|
const start = dateRanges.next90Days({ fieldOperator: '$dateOn', isParsingVariable: true });
|
||||||
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
expect(start.toISOString()).toBe(dayjs().add(1, 'day').startOf('day').toISOString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -254,12 +254,12 @@ export const getDateRanges = (props?: {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function withParams(value: any[], params: { fieldOperator?: string }) {
|
function withParams(value: any[], params: { fieldOperator?: string; isParsingVariable?: boolean }) {
|
||||||
if (params?.fieldOperator && params.fieldOperator !== '$dateBetween') {
|
if (params?.fieldOperator === '$dateBetween' || !params?.isParsingVariable) {
|
||||||
return value[0];
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function inferPickerType(dateString: string): 'year' | 'month' | 'quarter' | 'date' {
|
export function inferPickerType(dateString: string): 'year' | 'month' | 'quarter' | 'date' {
|
||||||
|
@ -75,7 +75,7 @@ export const useVariableOptions = ({
|
|||||||
targetFieldSchema,
|
targetFieldSchema,
|
||||||
});
|
});
|
||||||
const { apiTokenSettings } = useAPITokenVariable({ noDisabled });
|
const { apiTokenSettings } = useAPITokenVariable({ noDisabled });
|
||||||
const { datetimeSettings } = useDatetimeVariable({ operator, schema: uiSchema, noDisabled, targetFieldSchema });
|
const { datetimeSettings } = useDatetimeVariable({ operator, schema: uiSchema, noDisabled: true, targetFieldSchema });
|
||||||
const { currentFormSettings, shouldDisplayCurrentForm } = useCurrentFormVariable({
|
const { currentFormSettings, shouldDisplayCurrentForm } = useCurrentFormVariable({
|
||||||
schema: uiSchema,
|
schema: uiSchema,
|
||||||
collectionField,
|
collectionField,
|
||||||
|
@ -185,7 +185,9 @@ const VariablesProvider = ({ children, filterVariables }: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const _value = compile(_.isFunction(current) ? current({ fieldOperator: options?.fieldOperator }) : current);
|
const _value = compile(
|
||||||
|
_.isFunction(current) ? current({ fieldOperator: options?.fieldOperator, isParsingVariable: true }) : current,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
value: _value === undefined ? variableOption.defaultValue : _value,
|
value: _value === undefined ? variableOption.defaultValue : _value,
|
||||||
dataSource,
|
dataSource,
|
||||||
|
@ -298,7 +298,7 @@ describe('useVariables', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(async () => {
|
await waitFor(async () => {
|
||||||
expect(await result.current.parseVariable('{{ $date.today }}').then(({ value }) => value)).toHaveLength(2);
|
expect(await result.current.parseVariable('{{ $date.today }}').then(({ value }) => typeof value)).toBe('string');
|
||||||
expect(
|
expect(
|
||||||
Array.isArray(
|
Array.isArray(
|
||||||
await result.current
|
await result.current
|
||||||
|
Loading…
Reference in New Issue
Block a user