Merge pull request #783 from acelaya-forks/feature/visits-async-thunk

Feature/visits async thunk
This commit is contained in:
Alejandro Celaya 2022-12-31 10:47:30 +01:00 committed by GitHub
commit d34b9b1233
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 72 deletions

View file

@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed
* [#753](https://github.com/shlinkio/shlink-web-client/issues/753) Migrated from react-scripts/webpack to vite.
* [#770](https://github.com/shlinkio/shlink-web-client/issues/770) Updated to latest dependencies.
* [#741](https://github.com/shlinkio/shlink-web-client/issues/741) Improved `visitsAsyncThunk`, making it wrap pending/fulfilled/rejected actions, as well as custom ones, in a type-safe way.
### Deprecated
* *Nothing*

View file

@ -29,11 +29,11 @@ interface VisitsAsyncThunkOptions<T extends LoadVisits = LoadVisits, R extends V
export const createVisitsAsyncThunk = <T extends LoadVisits = LoadVisits, R extends VisitsLoaded = VisitsLoaded>(
{ typePrefix, createLoaders, getExtraFulfilledPayload, shouldCancel }: VisitsAsyncThunkOptions<T, R>,
) => {
const progressChangedAction = createAction<number>(`${typePrefix}/progressChanged`);
const largeAction = createAction<void>(`${typePrefix}/large`);
const fallbackToIntervalAction = createAction<DateInterval>(`${typePrefix}/fallbackToInterval`);
const progressChanged = createAction<number>(`${typePrefix}/progressChanged`);
const large = createAction<void>(`${typePrefix}/large`);
const fallbackToInterval = createAction<DateInterval>(`${typePrefix}/fallbackToInterval`);
const asyncThunk = createAsyncThunk(typePrefix, async (params: T, { getState, dispatch }): Promise<R> => {
const asyncThunk = createAsyncThunk(typePrefix, async (params: T, { getState, dispatch }): Promise<Partial<R>> => {
const [visitsLoader, lastVisitLoader] = createLoaders(params, getState);
const loadVisitsInParallel = async (pages: number[]): Promise<Visit[]> =>
@ -46,7 +46,7 @@ export const createVisitsAsyncThunk = <T extends LoadVisits = LoadVisits, R exte
const data = await loadVisitsInParallel(pagesBlocks[index]);
dispatch(progressChangedAction(calcProgress(pagesBlocks.length, index + PARALLEL_STARTING_PAGE)));
dispatch(progressChanged(calcProgress(pagesBlocks.length, index + PARALLEL_STARTING_PAGE)));
if (index < pagesBlocks.length - 1) {
return data.concat(await loadPagesBlocks(pagesBlocks, index + 1));
@ -68,7 +68,7 @@ export const createVisitsAsyncThunk = <T extends LoadVisits = LoadVisits, R exte
const pagesBlocks = splitEvery(PARALLEL_REQUESTS_COUNT, pagesRange);
if (pagination.pagesCount - 1 > PARALLEL_REQUESTS_COUNT) {
dispatch(largeAction());
dispatch(large());
}
return data.concat(await loadPagesBlocks(pagesBlocks));
@ -77,13 +77,14 @@ export const createVisitsAsyncThunk = <T extends LoadVisits = LoadVisits, R exte
const [visits, lastVisit] = await Promise.all([loadVisits(), lastVisitLoader()]);
if (!visits.length && lastVisit) {
dispatch(fallbackToIntervalAction(dateToMatchingInterval(lastVisit.date)));
dispatch(fallbackToInterval(dateToMatchingInterval(lastVisit.date)));
}
return { ...getExtraFulfilledPayload(params), visits } as any; // TODO Get rid of this casting
return { ...getExtraFulfilledPayload(params), visits };
});
return { asyncThunk, progressChangedAction, largeAction, fallbackToIntervalAction };
// Enhance the async thunk with extra actions
return Object.assign(asyncThunk, { progressChanged, large, fallbackToInterval });
};
export const lastVisitLoaderForLoader = (
@ -107,7 +108,7 @@ interface VisitsReducerOptions<State extends VisitsInfo, AT extends ReturnType<t
export const createVisitsReducer = <State extends VisitsInfo, AT extends ReturnType<typeof createVisitsAsyncThunk>>(
{ name, asyncThunkCreator, initialState, filterCreatedVisits }: VisitsReducerOptions<State, AT>,
) => {
const { asyncThunk, largeAction, fallbackToIntervalAction, progressChangedAction } = asyncThunkCreator;
const { pending, rejected, fulfilled, large, progressChanged, fallbackToInterval } = asyncThunkCreator;
const { reducer, actions } = createSlice({
name,
initialState,
@ -115,17 +116,17 @@ export const createVisitsReducer = <State extends VisitsInfo, AT extends ReturnT
cancelGetVisits: (state) => ({ ...state, cancelLoad: true }),
},
extraReducers: (builder) => {
builder.addCase(asyncThunk.pending, () => ({ ...initialState, loading: true }));
builder.addCase(asyncThunk.rejected, (_, { error }) => (
builder.addCase(pending, () => ({ ...initialState, loading: true }));
builder.addCase(rejected, (_, { error }) => (
{ ...initialState, error: true, errorData: parseApiError(error) }
));
builder.addCase(asyncThunk.fulfilled, (state, { payload }) => (
builder.addCase(fulfilled, (state, { payload }) => (
{ ...state, ...payload, loading: false, loadingLarge: false, error: false }
));
builder.addCase(largeAction, (state) => ({ ...state, loadingLarge: true }));
builder.addCase(progressChangedAction, (state, { payload: progress }) => ({ ...state, progress }));
builder.addCase(fallbackToIntervalAction, (state, { payload: fallbackInterval }) => (
builder.addCase(large, (state) => ({ ...state, loadingLarge: true }));
builder.addCase(progressChanged, (state, { payload: progress }) => ({ ...state, progress }));
builder.addCase(fallbackToInterval, (state, { payload: fallbackInterval }) => (
{ ...state, fallbackInterval }
));

View file

@ -54,24 +54,19 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
bottle.serviceFactory('VisitsParser', () => visitsParser);
// Actions
bottle.serviceFactory('getShortUrlVisitsCreator', getShortUrlVisits, 'buildShlinkApiClient');
bottle.serviceFactory('getShortUrlVisits', prop('asyncThunk'), 'getShortUrlVisitsCreator');
bottle.serviceFactory('getShortUrlVisits', getShortUrlVisits, 'buildShlinkApiClient');
bottle.serviceFactory('cancelGetShortUrlVisits', prop('cancelGetVisits'), 'shortUrlVisitsReducerCreator');
bottle.serviceFactory('getTagVisitsCreator', getTagVisits, 'buildShlinkApiClient');
bottle.serviceFactory('getTagVisits', prop('asyncThunk'), 'getTagVisitsCreator');
bottle.serviceFactory('getTagVisits', getTagVisits, 'buildShlinkApiClient');
bottle.serviceFactory('cancelGetTagVisits', prop('cancelGetVisits'), 'tagVisitsReducerCreator');
bottle.serviceFactory('getDomainVisitsCreator', getDomainVisits, 'buildShlinkApiClient');
bottle.serviceFactory('getDomainVisits', prop('asyncThunk'), 'getDomainVisitsCreator');
bottle.serviceFactory('getDomainVisits', getDomainVisits, 'buildShlinkApiClient');
bottle.serviceFactory('cancelGetDomainVisits', prop('cancelGetVisits'), 'domainVisitsReducerCreator');
bottle.serviceFactory('getOrphanVisitsCreator', getOrphanVisits, 'buildShlinkApiClient');
bottle.serviceFactory('getOrphanVisits', prop('asyncThunk'), 'getOrphanVisitsCreator');
bottle.serviceFactory('getOrphanVisits', getOrphanVisits, 'buildShlinkApiClient');
bottle.serviceFactory('cancelGetOrphanVisits', prop('cancelGetVisits'), 'orphanVisitsReducerCreator');
bottle.serviceFactory('getNonOrphanVisitsCreator', getNonOrphanVisits, 'buildShlinkApiClient');
bottle.serviceFactory('getNonOrphanVisits', prop('asyncThunk'), 'getNonOrphanVisitsCreator');
bottle.serviceFactory('getNonOrphanVisits', getNonOrphanVisits, 'buildShlinkApiClient');
bottle.serviceFactory('cancelGetNonOrphanVisits', prop('cancelGetVisits'), 'nonOrphanVisitsReducerCreator');
bottle.serviceFactory('createNewVisits', () => createNewVisits);
@ -81,19 +76,19 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
bottle.serviceFactory('visitsOverviewReducerCreator', visitsOverviewReducerCreator, 'loadVisitsOverview');
bottle.serviceFactory('visitsOverviewReducer', prop('reducer'), 'visitsOverviewReducerCreator');
bottle.serviceFactory('domainVisitsReducerCreator', domainVisitsReducerCreator, 'getDomainVisitsCreator');
bottle.serviceFactory('domainVisitsReducerCreator', domainVisitsReducerCreator, 'getDomainVisits');
bottle.serviceFactory('domainVisitsReducer', prop('reducer'), 'domainVisitsReducerCreator');
bottle.serviceFactory('nonOrphanVisitsReducerCreator', nonOrphanVisitsReducerCreator, 'getNonOrphanVisitsCreator');
bottle.serviceFactory('nonOrphanVisitsReducerCreator', nonOrphanVisitsReducerCreator, 'getNonOrphanVisits');
bottle.serviceFactory('nonOrphanVisitsReducer', prop('reducer'), 'nonOrphanVisitsReducerCreator');
bottle.serviceFactory('orphanVisitsReducerCreator', orphanVisitsReducerCreator, 'getOrphanVisitsCreator');
bottle.serviceFactory('orphanVisitsReducerCreator', orphanVisitsReducerCreator, 'getOrphanVisits');
bottle.serviceFactory('orphanVisitsReducer', prop('reducer'), 'orphanVisitsReducerCreator');
bottle.serviceFactory('shortUrlVisitsReducerCreator', shortUrlVisitsReducerCreator, 'getShortUrlVisitsCreator');
bottle.serviceFactory('shortUrlVisitsReducerCreator', shortUrlVisitsReducerCreator, 'getShortUrlVisits');
bottle.serviceFactory('shortUrlVisitsReducer', prop('reducer'), 'shortUrlVisitsReducerCreator');
bottle.serviceFactory('tagVisitsReducerCreator', tagVisitsReducerCreator, 'getTagVisitsCreator');
bottle.serviceFactory('tagVisitsReducerCreator', tagVisitsReducerCreator, 'getTagVisits');
bottle.serviceFactory('tagVisitsReducer', prop('reducer'), 'tagVisitsReducerCreator');
};

View file

@ -21,7 +21,7 @@ describe('<Paginator />', () => {
])('renders an empty gap if the number of pages is below 2', (paginator) => {
const { container } = setUp(paginator);
expect(container.firstChild).toBeEmpty();
expect(container.firstChild).toBeEmptyDOMElement();
expect(container.firstChild).toHaveClass('pb-3');
});

View file

@ -21,9 +21,8 @@ describe('domainVisitsReducer', () => {
const visitsMocks = rangeOf(2, () => Mock.all<Visit>());
const getDomainVisitsCall = jest.fn();
const buildApiClientMock = () => Mock.of<ShlinkApiClient>({ getDomainVisits: getDomainVisitsCall });
const creator = getDomainVisitsCreator(buildApiClientMock);
const { asyncThunk: getDomainVisits, progressChangedAction, largeAction, fallbackToIntervalAction } = creator;
const { reducer, cancelGetVisits: cancelGetDomainVisits } = domainVisitsReducerCreator(creator);
const getDomainVisits = getDomainVisitsCreator(buildApiClientMock);
const { reducer, cancelGetVisits: cancelGetDomainVisits } = domainVisitsReducerCreator(getDomainVisits);
beforeEach(jest.clearAllMocks);
@ -36,7 +35,7 @@ describe('domainVisitsReducer', () => {
});
it('returns loadingLarge on GET_DOMAIN_VISITS_LARGE', () => {
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: largeAction.toString() });
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: getDomainVisits.large.toString() });
expect(loadingLarge).toEqual(true);
});
@ -130,7 +129,7 @@ describe('domainVisitsReducer', () => {
});
it('returns new progress on GET_DOMAIN_VISITS_PROGRESS_CHANGED', () => {
const state = reducer(undefined, { type: progressChangedAction.toString(), payload: 85 });
const state = reducer(undefined, { type: getDomainVisits.progressChanged.toString(), payload: 85 });
expect(state).toEqual(expect.objectContaining({ progress: 85 }));
});
@ -139,7 +138,7 @@ describe('domainVisitsReducer', () => {
const fallbackInterval: DateInterval = 'last30Days';
const state = reducer(
undefined,
{ type: fallbackToIntervalAction.toString(), payload: fallbackInterval },
{ type: getDomainVisits.fallbackToInterval.toString(), payload: fallbackInterval },
);
expect(state).toEqual(expect.objectContaining({ fallbackInterval }));
@ -198,12 +197,12 @@ describe('domainVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 20)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last30Days' },
{ type: getDomainVisits.fallbackToInterval.toString(), payload: 'last30Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 100)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last180Days' },
{ type: getDomainVisits.fallbackToInterval.toString(), payload: 'last180Days' },
3,
],
[[], expect.objectContaining({ type: getDomainVisits.fulfilled.toString() }), 2],

View file

@ -19,9 +19,8 @@ describe('nonOrphanVisitsReducer', () => {
const visitsMocks = rangeOf(2, () => Mock.all<Visit>());
const getNonOrphanVisitsCall = jest.fn();
const buildShlinkApiClient = () => Mock.of<ShlinkApiClient>({ getNonOrphanVisits: getNonOrphanVisitsCall });
const creator = getNonOrphanVisitsCreator(buildShlinkApiClient);
const { asyncThunk: getNonOrphanVisits, progressChangedAction, largeAction, fallbackToIntervalAction } = creator;
const { reducer, cancelGetVisits: cancelGetNonOrphanVisits } = nonOrphanVisitsReducerCreator(creator);
const getNonOrphanVisits = getNonOrphanVisitsCreator(buildShlinkApiClient);
const { reducer, cancelGetVisits: cancelGetNonOrphanVisits } = nonOrphanVisitsReducerCreator(getNonOrphanVisits);
beforeEach(jest.clearAllMocks);
@ -34,7 +33,10 @@ describe('nonOrphanVisitsReducer', () => {
});
it('returns loadingLarge on GET_NON_ORPHAN_VISITS_LARGE', () => {
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: largeAction.toString() });
const { loadingLarge } = reducer(
buildState({ loadingLarge: false }),
{ type: getNonOrphanVisits.large.toString() },
);
expect(loadingLarge).toEqual(true);
});
@ -110,7 +112,7 @@ describe('nonOrphanVisitsReducer', () => {
});
it('returns new progress on GET_NON_ORPHAN_VISITS_PROGRESS_CHANGED', () => {
const state = reducer(undefined, { type: progressChangedAction.toString(), payload: 85 });
const state = reducer(undefined, { type: getNonOrphanVisits.progressChanged.toString(), payload: 85 });
expect(state).toEqual(expect.objectContaining({ progress: 85 }));
});
@ -118,7 +120,7 @@ describe('nonOrphanVisitsReducer', () => {
const fallbackInterval: DateInterval = 'last30Days';
const state = reducer(
undefined,
{ type: fallbackToIntervalAction.toString(), payload: fallbackInterval },
{ type: getNonOrphanVisits.fallbackToInterval.toString(), payload: fallbackInterval },
);
expect(state).toEqual(expect.objectContaining({ fallbackInterval }));
@ -178,12 +180,12 @@ describe('nonOrphanVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 5)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last7Days' },
{ type: getNonOrphanVisits.fallbackToInterval.toString(), payload: 'last7Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 200)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last365Days' },
{ type: getNonOrphanVisits.fallbackToInterval.toString(), payload: 'last365Days' },
3,
],
[[], expect.objectContaining({ type: getNonOrphanVisits.fulfilled.toString() }), 2],

View file

@ -19,9 +19,8 @@ describe('orphanVisitsReducer', () => {
const visitsMocks = rangeOf(2, () => Mock.all<Visit>());
const getOrphanVisitsCall = jest.fn();
const buildShlinkApiClientMock = () => Mock.of<ShlinkApiClient>({ getOrphanVisits: getOrphanVisitsCall });
const creator = getOrphanVisitsCreator(buildShlinkApiClientMock);
const { asyncThunk: getOrphanVisits, largeAction, progressChangedAction, fallbackToIntervalAction } = creator;
const { reducer, cancelGetVisits: cancelGetOrphanVisits } = orphanVisitsReducerCreator(creator);
const getOrphanVisits = getOrphanVisitsCreator(buildShlinkApiClientMock);
const { reducer, cancelGetVisits: cancelGetOrphanVisits } = orphanVisitsReducerCreator(getOrphanVisits);
beforeEach(jest.clearAllMocks);
@ -34,7 +33,7 @@ describe('orphanVisitsReducer', () => {
});
it('returns loadingLarge on GET_ORPHAN_VISITS_LARGE', () => {
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: largeAction.toString() });
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: getOrphanVisits.large.toString() });
expect(loadingLarge).toEqual(true);
});
@ -110,7 +109,7 @@ describe('orphanVisitsReducer', () => {
});
it('returns new progress on GET_ORPHAN_VISITS_PROGRESS_CHANGED', () => {
const state = reducer(undefined, { type: progressChangedAction.toString(), payload: 85 });
const state = reducer(undefined, { type: getOrphanVisits.progressChanged.toString(), payload: 85 });
expect(state).toEqual(expect.objectContaining({ progress: 85 }));
});
@ -118,7 +117,7 @@ describe('orphanVisitsReducer', () => {
const fallbackInterval: DateInterval = 'last30Days';
const state = reducer(
undefined,
{ type: fallbackToIntervalAction.toString(), payload: fallbackInterval },
{ type: getOrphanVisits.fallbackToInterval.toString(), payload: fallbackInterval },
);
expect(state).toEqual(expect.objectContaining({ fallbackInterval }));
@ -176,12 +175,12 @@ describe('orphanVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 5)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last7Days' },
{ type: getOrphanVisits.fallbackToInterval.toString(), payload: 'last7Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 200)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last365Days' },
{ type: getOrphanVisits.fallbackToInterval.toString(), payload: 'last365Days' },
3,
],
[[], expect.objectContaining({ type: getOrphanVisits.fulfilled.toString() }), 2],

View file

@ -19,9 +19,8 @@ describe('shortUrlVisitsReducer', () => {
const visitsMocks = rangeOf(2, () => Mock.all<Visit>());
const getShortUrlVisitsCall = jest.fn();
const buildApiClientMock = () => Mock.of<ShlinkApiClient>({ getShortUrlVisits: getShortUrlVisitsCall });
const creator = getShortUrlVisitsCreator(buildApiClientMock);
const { asyncThunk: getShortUrlVisits, largeAction, progressChangedAction, fallbackToIntervalAction } = creator;
const { reducer, cancelGetVisits: cancelGetShortUrlVisits } = shortUrlVisitsReducerCreator(creator);
const getShortUrlVisits = getShortUrlVisitsCreator(buildApiClientMock);
const { reducer, cancelGetVisits: cancelGetShortUrlVisits } = shortUrlVisitsReducerCreator(getShortUrlVisits);
beforeEach(jest.clearAllMocks);
@ -34,7 +33,10 @@ describe('shortUrlVisitsReducer', () => {
});
it('returns loadingLarge on GET_SHORT_URL_VISITS_LARGE', () => {
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: largeAction.toString() });
const { loadingLarge } = reducer(
buildState({ loadingLarge: false }),
{ type: getShortUrlVisits.large.toString() },
);
expect(loadingLarge).toEqual(true);
});
@ -130,7 +132,7 @@ describe('shortUrlVisitsReducer', () => {
});
it('returns new progress on GET_SHORT_URL_VISITS_PROGRESS_CHANGED', () => {
const state = reducer(undefined, { type: progressChangedAction.toString(), payload: 85 });
const state = reducer(undefined, { type: getShortUrlVisits.progressChanged.toString(), payload: 85 });
expect(state).toEqual(expect.objectContaining({ progress: 85 }));
});
@ -138,7 +140,7 @@ describe('shortUrlVisitsReducer', () => {
const fallbackInterval: DateInterval = 'last30Days';
const state = reducer(
undefined,
{ type: fallbackToIntervalAction.toString(), payload: fallbackInterval },
{ type: getShortUrlVisits.fallbackToInterval.toString(), payload: fallbackInterval },
);
expect(state).toEqual(expect.objectContaining({ fallbackInterval }));
@ -220,12 +222,12 @@ describe('shortUrlVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 5)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last7Days' },
{ type: getShortUrlVisits.fallbackToInterval.toString(), payload: 'last7Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 200)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last365Days' },
{ type: getShortUrlVisits.fallbackToInterval.toString(), payload: 'last365Days' },
3,
],
[[], expect.objectContaining({ type: getShortUrlVisits.fulfilled.toString() }), 2],

View file

@ -19,9 +19,8 @@ describe('tagVisitsReducer', () => {
const visitsMocks = rangeOf(2, () => Mock.all<Visit>());
const getTagVisitsCall = jest.fn();
const buildShlinkApiClientMock = () => Mock.of<ShlinkApiClient>({ getTagVisits: getTagVisitsCall });
const creator = getTagVisitsCreator(buildShlinkApiClientMock);
const { asyncThunk: getTagVisits, fallbackToIntervalAction, largeAction, progressChangedAction } = creator;
const { reducer, cancelGetVisits: cancelGetTagVisits } = tagVisitsReducerCreator(creator);
const getTagVisits = getTagVisitsCreator(buildShlinkApiClientMock);
const { reducer, cancelGetVisits: cancelGetTagVisits } = tagVisitsReducerCreator(getTagVisits);
beforeEach(jest.clearAllMocks);
@ -34,7 +33,7 @@ describe('tagVisitsReducer', () => {
});
it('returns loadingLarge on GET_TAG_VISITS_LARGE', () => {
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: largeAction.toString() });
const { loadingLarge } = reducer(buildState({ loadingLarge: false }), { type: getTagVisits.large.toString() });
expect(loadingLarge).toEqual(true);
});
@ -130,13 +129,13 @@ describe('tagVisitsReducer', () => {
});
it('returns new progress on GET_TAG_VISITS_PROGRESS_CHANGED', () => {
const state = reducer(undefined, { type: progressChangedAction.toString(), payload: 85 });
const state = reducer(undefined, { type: getTagVisits.progressChanged.toString(), payload: 85 });
expect(state).toEqual(expect.objectContaining({ progress: 85 }));
});
it('returns fallbackInterval on GET_TAG_VISITS_FALLBACK_TO_INTERVAL', () => {
const fallbackInterval: DateInterval = 'last30Days';
const state = reducer(undefined, { type: fallbackToIntervalAction.toString(), payload: fallbackInterval });
const state = reducer(undefined, { type: getTagVisits.fallbackToInterval.toString(), payload: fallbackInterval });
expect(state).toEqual(expect.objectContaining({ fallbackInterval }));
});
@ -194,12 +193,12 @@ describe('tagVisitsReducer', () => {
it.each([
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 20)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last30Days' },
{ type: getTagVisits.fallbackToInterval.toString(), payload: 'last30Days' },
3,
],
[
[Mock.of<Visit>({ date: formatISO(subDays(now, 100)) })],
{ type: fallbackToIntervalAction.toString(), payload: 'last180Days' },
{ type: getTagVisits.fallbackToInterval.toString(), payload: 'last180Days' },
3,
],
[[], expect.objectContaining({ type: getTagVisits.fulfilled.toString() }), 2],