mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Improved domainVisits reducer covering new visits for different domains and default domain
This commit is contained in:
parent
3aa990a1b0
commit
bbaa4d0f05
1 changed files with 13 additions and 7 deletions
|
@ -10,7 +10,7 @@ import reducer, {
|
||||||
GET_DOMAIN_VISITS_CANCEL,
|
GET_DOMAIN_VISITS_CANCEL,
|
||||||
GET_DOMAIN_VISITS_PROGRESS_CHANGED,
|
GET_DOMAIN_VISITS_PROGRESS_CHANGED,
|
||||||
GET_DOMAIN_VISITS_FALLBACK_TO_INTERVAL,
|
GET_DOMAIN_VISITS_FALLBACK_TO_INTERVAL,
|
||||||
DomainVisits,
|
DomainVisits, DEFAULT_DOMAIN
|
||||||
} from '../../../src/visits/reducers/domainVisits';
|
} from '../../../src/visits/reducers/domainVisits';
|
||||||
import { CREATE_VISITS } from '../../../src/visits/reducers/visitCreation';
|
import { CREATE_VISITS } from '../../../src/visits/reducers/visitCreation';
|
||||||
import { rangeOf } from '../../../src/utils/utils';
|
import { rangeOf } from '../../../src/utils/utils';
|
||||||
|
@ -20,6 +20,7 @@ import ShlinkApiClient from '../../../src/api/services/ShlinkApiClient';
|
||||||
import { ShlinkState } from '../../../src/container/types';
|
import { ShlinkState } from '../../../src/container/types';
|
||||||
import { formatIsoDate } from '../../../src/utils/helpers/date';
|
import { formatIsoDate } from '../../../src/utils/helpers/date';
|
||||||
import { DateInterval } from '../../../src/utils/dates/types';
|
import { DateInterval } from '../../../src/utils/dates/types';
|
||||||
|
import { ShortUrl } from '../../../src/short-urls/data';
|
||||||
|
|
||||||
describe('domainVisitsReducer', () => {
|
describe('domainVisitsReducer', () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -71,13 +72,16 @@ describe('domainVisitsReducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[{ domain: 'foo.com' }, visitsMocks.length + 1],
|
[{ domain: 'foo.com' }, 'foo.com', visitsMocks.length + 1],
|
||||||
[{ domain: 'bar.com' }, visitsMocks.length],
|
[{ domain: 'bar.com' }, 'foo.com', visitsMocks.length],
|
||||||
|
[Mock.of<DomainVisits>({ domain: 'foo.com' }), 'foo.com', visitsMocks.length + 1],
|
||||||
|
[Mock.of<DomainVisits>({ domain: DEFAULT_DOMAIN }), null, visitsMocks.length + 1],
|
||||||
[
|
[
|
||||||
Mock.of<DomainVisits>({
|
Mock.of<DomainVisits>({
|
||||||
domain: 'foo.com',
|
domain: 'foo.com',
|
||||||
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
|
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
|
||||||
}),
|
}),
|
||||||
|
'foo.com',
|
||||||
visitsMocks.length,
|
visitsMocks.length,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -85,6 +89,7 @@ describe('domainVisitsReducer', () => {
|
||||||
domain: 'foo.com',
|
domain: 'foo.com',
|
||||||
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
|
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
|
||||||
}),
|
}),
|
||||||
|
'foo.com',
|
||||||
visitsMocks.length,
|
visitsMocks.length,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -95,6 +100,7 @@ describe('domainVisitsReducer', () => {
|
||||||
endDate: formatIsoDate(subDays(now, 2)) ?? undefined,
|
endDate: formatIsoDate(subDays(now, 2)) ?? undefined,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
'foo.com',
|
||||||
visitsMocks.length,
|
visitsMocks.length,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -105,6 +111,7 @@ describe('domainVisitsReducer', () => {
|
||||||
endDate: formatIsoDate(addDays(now, 3)) ?? undefined,
|
endDate: formatIsoDate(addDays(now, 3)) ?? undefined,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
'foo.com',
|
||||||
visitsMocks.length + 1,
|
visitsMocks.length + 1,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -115,12 +122,11 @@ describe('domainVisitsReducer', () => {
|
||||||
endDate: formatIsoDate(addDays(now, 3)) ?? undefined,
|
endDate: formatIsoDate(addDays(now, 3)) ?? undefined,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
'foo.com',
|
||||||
visitsMocks.length,
|
visitsMocks.length,
|
||||||
],
|
],
|
||||||
])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => {
|
])('prepends new visits on CREATE_VISIT', (state, shortUrlDomain, expectedVisits) => {
|
||||||
const shortUrl = {
|
const shortUrl = Mock.of<ShortUrl>({ domain: shortUrlDomain });
|
||||||
domain: 'foo.com',
|
|
||||||
};
|
|
||||||
const prevState = buildState({
|
const prevState = buildState({
|
||||||
...state,
|
...state,
|
||||||
visits: visitsMocks,
|
visits: visitsMocks,
|
||||||
|
|
Loading…
Reference in a new issue