Created now function and refactored intervalToDateRange

This commit is contained in:
Alejandro Celaya
2022-12-05 17:18:00 +01:00
parent 7d83e434e6
commit 1654784471
10 changed files with 38 additions and 50 deletions

View File

@@ -8,11 +8,10 @@ import {
rangeOrIntervalToString,
toDateRange,
} from '../../../src/utils/helpers/dateIntervals';
import { parseDate } from '../../../src/utils/helpers/date';
import { parseDate, now } from '../../../src/utils/helpers/date';
describe('date-types', () => {
const now = () => new Date();
const daysBack = (days: number) => subDays(new Date(), days);
const daysBack = (days: number) => subDays(now(), days);
describe('dateRangeIsEmpty', () => {
it.each([
@@ -26,9 +25,9 @@ describe('date-types', () => {
[{ startDate: undefined, endDate: undefined }, true],
[{ startDate: undefined, endDate: null }, true],
[{ startDate: null, endDate: undefined }, true],
[{ startDate: new Date() }, false],
[{ endDate: new Date() }, false],
[{ startDate: new Date(), endDate: new Date() }, false],
[{ startDate: now() }, false],
[{ endDate: now() }, false],
[{ startDate: now(), endDate: now() }, false],
])('returns proper result', (dateRange, expectedResult) => {
expect(dateRangeIsEmpty(dateRange)).toEqual(expectedResult);
});

View File

@@ -197,12 +197,12 @@ describe('domainVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 20)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 20)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last30Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 100)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 100)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last180Days' },
3,
],

View File

@@ -177,12 +177,12 @@ describe('nonOrphanVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 5)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last7Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 200)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last365Days' },
3,
],

View File

@@ -175,12 +175,12 @@ describe('orphanVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 5)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last7Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 200)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last365Days' },
3,
],

View File

@@ -219,12 +219,12 @@ describe('shortUrlVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 5)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last7Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 200)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last365Days' },
3,
],

View File

@@ -193,12 +193,12 @@ describe('tagVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 20)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 20)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last30Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 100)) })],
[Mock.of<Visit>({ date: formatISO(subDays(now, 100)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last180Days' },
3,
],