mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-08-01 00:21:52 +00:00
Enhanced visits async thunk so that it wraps both standard async thunk actions and extra ones
This commit is contained in:
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user