mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-22 06:26:19 +00:00
Updated to airbnb coding styles
This commit is contained in:
@@ -42,9 +42,9 @@ describe('<ShortUrlVisitsHeader />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ null, longUrl ],
|
||||
[ undefined, longUrl ],
|
||||
[ 'My cool title', 'My cool title' ],
|
||||
[null, longUrl],
|
||||
[undefined, longUrl],
|
||||
['My cool title', 'My cool title'],
|
||||
])('shows the long URL and title', (title, expectedContent) => {
|
||||
const wrapper = createWrapper(title);
|
||||
const longUrlLink = wrapper.find(ExternalLink).last();
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Visit } from '../../src/visits/types';
|
||||
|
||||
describe('<VisitsHeader />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
const visits = [ Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>() ];
|
||||
const visits = [Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>()];
|
||||
const title = 'My header title';
|
||||
const goBack = jest.fn();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { DoughnutChartCard } from '../../src/visits/charts/DoughnutChartCard';
|
||||
import { ExportBtn } from '../../src/utils/ExportBtn';
|
||||
|
||||
describe('<VisitsStats />', () => {
|
||||
const visits = [ Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>() ];
|
||||
const visits = [Mock.all<Visit>(), Mock.all<Visit>(), Mock.all<Visit>()];
|
||||
|
||||
let wrapper: ShallowWrapper;
|
||||
const getVisitsMock = jest.fn();
|
||||
|
||||
@@ -47,8 +47,8 @@ describe('<VisitsTable />', () => {
|
||||
afterEach(() => wrapper?.unmount());
|
||||
|
||||
it.each([
|
||||
[ '2.6.0' as SemVer, [ 'Date', 'Country', 'City', 'Browser', 'OS', 'Referrer' ]],
|
||||
[ '2.7.0' as SemVer, [ 'fa-robot', 'Date', 'Country', 'City', 'Browser', 'OS', 'Referrer' ]],
|
||||
['2.6.0' as SemVer, ['Date', 'Country', 'City', 'Browser', 'OS', 'Referrer']],
|
||||
['2.7.0' as SemVer, ['fa-robot', 'Date', 'Country', 'City', 'Browser', 'OS', 'Referrer']],
|
||||
])('renders columns as expected', (version, expectedColumns) => {
|
||||
const wrapper = createServerVersionWrapper(version);
|
||||
const th = wrapper.find('thead').find('th');
|
||||
@@ -68,11 +68,11 @@ describe('<VisitsTable />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ 50, 3 ],
|
||||
[ 21, 2 ],
|
||||
[ 30, 2 ],
|
||||
[ 60, 3 ],
|
||||
[ 115, 6 ],
|
||||
[50, 3],
|
||||
[21, 2],
|
||||
[30, 2],
|
||||
[60, 3],
|
||||
[115, 6],
|
||||
])('renders the expected amount of pages', (visitsCount, expectedAmountOfPages) => {
|
||||
const wrapper = createWrapper(
|
||||
rangeOf(visitsCount, () => Mock.of<NormalizedVisit>({ browser: '', date: '', referer: '' })),
|
||||
@@ -85,7 +85,7 @@ describe('<VisitsTable />', () => {
|
||||
});
|
||||
|
||||
it.each(
|
||||
rangeOf(20, (value) => [ value ]),
|
||||
rangeOf(20, (value) => [value]),
|
||||
)('does not render footer when there is only one page to render', (visitsCount) => {
|
||||
const wrapper = createWrapper(
|
||||
rangeOf(visitsCount, () => Mock.of<NormalizedVisit>({ browser: '', date: '', referer: '' })),
|
||||
@@ -101,7 +101,7 @@ describe('<VisitsTable />', () => {
|
||||
const visits = rangeOf(10, () => Mock.of<NormalizedVisit>({ browser: '', date: '', referer: '' }));
|
||||
const wrapper = createWrapper(
|
||||
visits,
|
||||
[ visits[1], visits[2] ],
|
||||
[visits[1], visits[2]],
|
||||
);
|
||||
|
||||
expect(wrapper.find('.text-primary')).toHaveLength(3);
|
||||
@@ -109,11 +109,11 @@ describe('<VisitsTable />', () => {
|
||||
|
||||
// Select one extra
|
||||
wrapper.find('tr').at(5).simulate('click');
|
||||
expect(setSelectedVisits).toHaveBeenCalledWith([ visits[1], visits[2], visits[4] ]);
|
||||
expect(setSelectedVisits).toHaveBeenCalledWith([visits[1], visits[2], visits[4]]);
|
||||
|
||||
// Deselect one
|
||||
wrapper.find('tr').at(3).simulate('click');
|
||||
expect(setSelectedVisits).toHaveBeenCalledWith([ visits[1] ]);
|
||||
expect(setSelectedVisits).toHaveBeenCalledWith([visits[1]]);
|
||||
|
||||
// Select all
|
||||
wrapper.find('thead').find('th').at(0).simulate('click');
|
||||
@@ -128,15 +128,25 @@ describe('<VisitsTable />', () => {
|
||||
country: `Country_${index}`,
|
||||
})));
|
||||
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td').at(2).text()).toContain('Country_1');
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td')
|
||||
.at(2)
|
||||
.text()).toContain('Country_1');
|
||||
wrapper.find('thead').find('th').at(1).simulate('click'); // Date column ASC
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td').at(2).text()).toContain('Country_9');
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td')
|
||||
.at(2)
|
||||
.text()).toContain('Country_9');
|
||||
wrapper.find('thead').find('th').at(6).simulate('click'); // Referer column - ASC
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td').at(2).text()).toContain('Country_1');
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td')
|
||||
.at(2)
|
||||
.text()).toContain('Country_1');
|
||||
wrapper.find('thead').find('th').at(6).simulate('click'); // Referer column - DESC
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td').at(2).text()).toContain('Country_9');
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td')
|
||||
.at(2)
|
||||
.text()).toContain('Country_9');
|
||||
wrapper.find('thead').find('th').at(6).simulate('click'); // Referer column - reset
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td').at(2).text()).toContain('Country_1');
|
||||
expect(wrapper.find('tbody').find('tr').at(0).find('td')
|
||||
.at(2)
|
||||
.text()).toContain('Country_1');
|
||||
});
|
||||
|
||||
it('filters list when writing in search box', () => {
|
||||
@@ -156,10 +166,10 @@ describe('<VisitsTable />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ true, '2.6.0' as SemVer, 8 ],
|
||||
[ false, '2.6.0' as SemVer, 7 ],
|
||||
[ true, '2.7.0' as SemVer, 9 ],
|
||||
[ false, '2.7.0' as SemVer, 8 ],
|
||||
[true, '2.6.0' as SemVer, 8],
|
||||
[false, '2.6.0' as SemVer, 7],
|
||||
[true, '2.7.0' as SemVer, 9],
|
||||
[false, '2.7.0' as SemVer, 8],
|
||||
])('displays proper amount of columns for orphan and non-orphan visits', (isOrphanVisits, version, expectedCols) => {
|
||||
const wrapper = createOrphanVisitsWrapper(isOrphanVisits, version);
|
||||
const rowsWithColspan = wrapper.find('[colSpan]');
|
||||
|
||||
@@ -27,8 +27,8 @@ describe('<ChartCard />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ 'the title', 'the title' ],
|
||||
[ () => 'the title from func', 'the title from func' ],
|
||||
['the title', 'the title'],
|
||||
[() => 'the title from func', 'the title from func'],
|
||||
])('properly renders title by parsing provided value', (title, expectedTitle) => {
|
||||
const wrapper = createWrapper(title);
|
||||
const header = wrapper.find(CardHeader);
|
||||
|
||||
@@ -4,10 +4,10 @@ import { Chart, ChartDataset } from 'chart.js';
|
||||
import { DoughnutChartLegend } from '../../../src/visits/charts/DoughnutChartLegend';
|
||||
|
||||
describe('<DoughnutChartLegend />', () => {
|
||||
const labels = [ 'foo', 'bar', 'baz', 'foo2', 'bar2' ];
|
||||
const colors = [ 'foo_color', 'bar_color', 'baz_color' ];
|
||||
const labels = ['foo', 'bar', 'baz', 'foo2', 'bar2'];
|
||||
const colors = ['foo_color', 'bar_color', 'baz_color'];
|
||||
const defaultColor = 'red';
|
||||
const datasets = [ Mock.of<ChartDataset>({ backgroundColor: colors }) ];
|
||||
const datasets = [Mock.of<ChartDataset>({ backgroundColor: colors })];
|
||||
const chart = Mock.of<Chart>({
|
||||
config: {
|
||||
data: { labels, datasets },
|
||||
|
||||
@@ -39,16 +39,16 @@ describe('<HorizontalBarChart />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ foo: 23 }, [ 100, 456 ], [ 23, 0 ]],
|
||||
[{ foo: 50 }, [ 73, 456 ], [ 50, 0 ]],
|
||||
[{ bar: 45 }, [ 123, 411 ], [ 0, 45 ]],
|
||||
[{ bar: 20, foo: 13 }, [ 110, 436 ], [ 13, 20 ]],
|
||||
[ undefined, [ 123, 456 ], undefined ],
|
||||
[{ foo: 23 }, [100, 456], [23, 0]],
|
||||
[{ foo: 50 }, [73, 456], [50, 0]],
|
||||
[{ bar: 45 }, [123, 411], [0, 45]],
|
||||
[{ bar: 20, foo: 13 }, [110, 436], [13, 20]],
|
||||
[undefined, [123, 456], undefined],
|
||||
])('splits highlighted data from regular data', (highlightedStats, expectedData, expectedHighlightedData) => {
|
||||
wrapper = shallow(<HorizontalBarChart stats={stats} highlightedStats={highlightedStats} />);
|
||||
const horizontal = wrapper.find(Bar);
|
||||
|
||||
const { datasets: [{ data, label }, highlightedData ] } = horizontal.prop('data') as any;
|
||||
const { datasets: [{ data, label }, highlightedData] } = horizontal.prop('data') as any;
|
||||
|
||||
expect(label).toEqual('Visits');
|
||||
expect(data).toEqual(expectedData);
|
||||
|
||||
@@ -27,13 +27,13 @@ describe('<LineChartCard />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[[], 'monthly' ],
|
||||
[[{ date: formatISO(subDays(new Date(), 1)) }], 'hourly' ],
|
||||
[[{ date: formatISO(subDays(new Date(), 3)) }], 'daily' ],
|
||||
[[{ date: formatISO(subMonths(new Date(), 2)) }], 'weekly' ],
|
||||
[[{ date: formatISO(subMonths(new Date(), 6)) }], 'weekly' ],
|
||||
[[{ date: formatISO(subMonths(new Date(), 7)) }], 'monthly' ],
|
||||
[[{ date: formatISO(subYears(new Date(), 1)) }], 'monthly' ],
|
||||
[[], 'monthly'],
|
||||
[[{ date: formatISO(subDays(new Date(), 1)) }], 'hourly'],
|
||||
[[{ date: formatISO(subDays(new Date(), 3)) }], 'daily'],
|
||||
[[{ date: formatISO(subMonths(new Date(), 2)) }], 'weekly'],
|
||||
[[{ date: formatISO(subMonths(new Date(), 6)) }], 'weekly'],
|
||||
[[{ date: formatISO(subMonths(new Date(), 7)) }], 'monthly'],
|
||||
[[{ date: formatISO(subYears(new Date(), 1)) }], 'monthly'],
|
||||
])('renders group menu and selects proper grouping item based on visits dates', (visits, expectedActiveItem) => {
|
||||
const wrapper = createWrapper(visits.map((visit) => Mock.of<NormalizedVisit>(visit)));
|
||||
const items = wrapper.find(DropdownItem);
|
||||
@@ -80,8 +80,8 @@ describe('<LineChartCard />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[[ Mock.of<NormalizedVisit>({ date: '2016-04-01' }) ], [], 1 ],
|
||||
[[ Mock.of<NormalizedVisit>({ date: '2016-04-01' }) ], [ Mock.of<NormalizedVisit>({ date: '2016-04-01' }) ], 2 ],
|
||||
[[Mock.of<NormalizedVisit>({ date: '2016-04-01' })], [], 1],
|
||||
[[Mock.of<NormalizedVisit>({ date: '2016-04-01' })], [Mock.of<NormalizedVisit>({ date: '2016-04-01' })], 2],
|
||||
])('renders chart with expected data', (visits, highlightedVisits, expectedLines) => {
|
||||
const wrapper = createWrapper(visits, highlightedVisits);
|
||||
const chart = wrapper.find(Line);
|
||||
|
||||
@@ -57,10 +57,10 @@ describe('<SortableBarChartCard />', () => {
|
||||
};
|
||||
});
|
||||
|
||||
it('name - ASC', () => assert('name', 'ASC', [ 'Bar', 'Foo' ], [ 50, 100 ]));
|
||||
it('name - DESC', () => assert('name', 'DESC', [ 'Foo', 'Bar' ], [ 100, 50 ]));
|
||||
it('value - ASC', () => assert('value', 'ASC', [ 'Bar', 'Foo' ], [ 50, 100 ]));
|
||||
it('value - DESC', () => assert('value', 'DESC', [ 'Foo', 'Bar' ], [ 100, 50 ]));
|
||||
it('name - ASC', () => assert('name', 'ASC', ['Bar', 'Foo'], [50, 100]));
|
||||
it('name - DESC', () => assert('name', 'DESC', ['Foo', 'Bar'], [100, 50]));
|
||||
it('value - ASC', () => assert('value', 'ASC', ['Bar', 'Foo'], [50, 100]));
|
||||
it('value - DESC', () => assert('value', 'DESC', ['Foo', 'Bar'], [100, 50]));
|
||||
});
|
||||
|
||||
describe('renders properly paginated stats when pagination is set', () => {
|
||||
@@ -83,7 +83,7 @@ describe('<SortableBarChartCard />', () => {
|
||||
};
|
||||
});
|
||||
|
||||
const buildExpected = (size: number): string[] => [ 'Foo', 'Bar', ...rangeOf(size - 2, (i) => `key_${i}`) ];
|
||||
const buildExpected = (size: number): string[] => ['Foo', 'Bar', ...rangeOf(size - 2, (i) => `key_${i}`)];
|
||||
|
||||
it('50 items per page', () => assert(50, buildExpected(50)));
|
||||
it('100 items per page', () => assert(100, buildExpected(100)));
|
||||
|
||||
@@ -17,12 +17,12 @@ describe('<MapModal />', () => {
|
||||
{
|
||||
cityName: 'Zaragoza',
|
||||
count: 54,
|
||||
latLong: [ zaragozaLat, zaragozaLong ],
|
||||
latLong: [zaragozaLat, zaragozaLong],
|
||||
},
|
||||
{
|
||||
cityName: 'New York',
|
||||
count: 7,
|
||||
latLong: [ newYorkLat, newYorkLong ],
|
||||
latLong: [newYorkLat, newYorkLong],
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('<OpenMapModalBtn />', () => {
|
||||
});
|
||||
|
||||
it('opens dropdown instead of modal when a list of active cities has been provided', () => {
|
||||
const wrapper = createWrapper([ 'bar' ]);
|
||||
const wrapper = createWrapper(['bar']);
|
||||
|
||||
wrapper.find('.open-map-modal-btn__btn').simulate('click');
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('<OpenMapModalBtn />', () => {
|
||||
});
|
||||
|
||||
it('filters out non-active cities from list of locations', () => {
|
||||
const wrapper = createWrapper([ 'bar' ]);
|
||||
const wrapper = createWrapper(['bar']);
|
||||
|
||||
wrapper.find('.open-map-modal-btn__btn').simulate('click');
|
||||
wrapper.find(Dropdown).find(DropdownItem).at(1).simulate('click');
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('<VisitsFilterDropdown />', () => {
|
||||
wrapper = shallow(
|
||||
<VisitsFilterDropdown
|
||||
isOrphanVisits={isOrphanVisits}
|
||||
botsSupported={true}
|
||||
botsSupported
|
||||
selected={selected}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
@@ -29,8 +29,8 @@ describe('<VisitsFilterDropdown />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ false, 4, 1 ],
|
||||
[ true, 9, 2 ],
|
||||
[false, 4, 1],
|
||||
[true, 9, 2],
|
||||
])('renders expected amount of items', (isOrphanVisits, expectedItemsAmount, expectedHeadersAmount) => {
|
||||
const wrapper = createWrapper({}, isOrphanVisits);
|
||||
const items = wrapper.find(DropdownItem);
|
||||
@@ -41,10 +41,10 @@ describe('<VisitsFilterDropdown />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ 'base_url' as OrphanVisitType, 4, 1 ],
|
||||
[ 'invalid_short_url' as OrphanVisitType, 5, 1 ],
|
||||
[ 'regular_404' as OrphanVisitType, 6, 1 ],
|
||||
[ undefined, -1, 0 ],
|
||||
['base_url' as OrphanVisitType, 4, 1],
|
||||
['invalid_short_url' as OrphanVisitType, 5, 1],
|
||||
['regular_404' as OrphanVisitType, 6, 1],
|
||||
[undefined, -1, 0],
|
||||
])('sets expected item as active', (orphanVisitsType, expectedSelectedIndex, expectedActiveItems) => {
|
||||
const wrapper = createWrapper({ orphanVisitsType });
|
||||
const items = wrapper.find(DropdownItem);
|
||||
@@ -60,11 +60,11 @@ describe('<VisitsFilterDropdown />', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ 1, { excludeBots: true }],
|
||||
[ 4, { orphanVisitsType: 'base_url' }],
|
||||
[ 5, { orphanVisitsType: 'invalid_short_url' }],
|
||||
[ 6, { orphanVisitsType: 'regular_404' }],
|
||||
[ 8, {}],
|
||||
[1, { excludeBots: true }],
|
||||
[4, { orphanVisitsType: 'base_url' }],
|
||||
[5, { orphanVisitsType: 'invalid_short_url' }],
|
||||
[6, { orphanVisitsType: 'regular_404' }],
|
||||
[8, {}],
|
||||
])('invokes onChange with proper selection when an item is clicked', (index, expectedSelection) => {
|
||||
const wrapper = createWrapper();
|
||||
const itemToClick = wrapper.find(DropdownItem).at(index);
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('nonOrphanVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{}, visitsMocks.length + 2 ],
|
||||
[{}, visitsMocks.length + 2],
|
||||
[
|
||||
Mock.of<VisitsInfo>({
|
||||
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
|
||||
@@ -152,7 +152,7 @@ describe('nonOrphanVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ undefined ],
|
||||
[undefined],
|
||||
[{}],
|
||||
])('dispatches start and success when promise is resolved', async (query) => {
|
||||
const visits = visitsMocks.map((visit) => ({ ...visit, visitedUrl: '' }));
|
||||
@@ -175,14 +175,14 @@ describe('nonOrphanVisitsReducer', () => {
|
||||
|
||||
it.each([
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) })],
|
||||
{ type: GET_NON_ORPHAN_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last7Days' },
|
||||
],
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) })],
|
||||
{ type: GET_NON_ORPHAN_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last365Days' },
|
||||
],
|
||||
[[], expect.objectContaining({ type: GET_NON_ORPHAN_VISITS }) ],
|
||||
[[], expect.objectContaining({ type: GET_NON_ORPHAN_VISITS })],
|
||||
])('dispatches fallback interval when the list of visits is empty', async (lastVisits, expectedSecondDispatch) => {
|
||||
const buildVisitsResult = (data: Visit[] = []): ShlinkVisits => ({
|
||||
data,
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('orphanVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{}, visitsMocks.length + 2 ],
|
||||
[{}, visitsMocks.length + 2],
|
||||
[
|
||||
Mock.of<VisitsInfo>({
|
||||
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
|
||||
@@ -152,7 +152,7 @@ describe('orphanVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ undefined ],
|
||||
[undefined],
|
||||
[{}],
|
||||
])('dispatches start and success when promise is resolved', async (query) => {
|
||||
const visits = visitsMocks.map((visit) => ({ ...visit, visitedUrl: '' }));
|
||||
@@ -175,14 +175,14 @@ describe('orphanVisitsReducer', () => {
|
||||
|
||||
it.each([
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) })],
|
||||
{ type: GET_ORPHAN_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last7Days' },
|
||||
],
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) })],
|
||||
{ type: GET_ORPHAN_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last365Days' },
|
||||
],
|
||||
[[], expect.objectContaining({ type: GET_ORPHAN_VISITS }) ],
|
||||
[[], expect.objectContaining({ type: GET_ORPHAN_VISITS })],
|
||||
])('dispatches fallback interval when the list of visits is empty', async (lastVisits, expectedSecondDispatch) => {
|
||||
const buildVisitsResult = (data: Visit[] = []): ShlinkVisits => ({
|
||||
data,
|
||||
|
||||
@@ -71,8 +71,8 @@ describe('shortUrlVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ shortCode: 'abc123' }, visitsMocks.length + 1 ],
|
||||
[{ shortCode: 'def456' }, visitsMocks.length ],
|
||||
[{ shortCode: 'abc123' }, visitsMocks.length + 1],
|
||||
[{ shortCode: 'def456' }, visitsMocks.length],
|
||||
[
|
||||
Mock.of<ShortUrlVisits>({
|
||||
shortCode: 'abc123',
|
||||
@@ -173,9 +173,9 @@ describe('shortUrlVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ undefined, undefined ],
|
||||
[{}, undefined ],
|
||||
[{ domain: 'foobar.com' }, 'foobar.com' ],
|
||||
[undefined, undefined],
|
||||
[{}, undefined],
|
||||
[{ domain: 'foobar.com' }, 'foobar.com'],
|
||||
])('dispatches start and success when promise is resolved', async (query, domain) => {
|
||||
const visits = visitsMocks;
|
||||
const shortCode = 'abc123';
|
||||
@@ -215,20 +215,20 @@ describe('shortUrlVisitsReducer', () => {
|
||||
|
||||
expect(ShlinkApiClient.getShortUrlVisits).toHaveBeenCalledTimes(expectedRequests);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(3, expect.objectContaining({
|
||||
visits: [ ...visitsMocks, ...visitsMocks, ...visitsMocks ],
|
||||
visits: [...visitsMocks, ...visitsMocks, ...visitsMocks],
|
||||
}));
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 5)) })],
|
||||
{ type: GET_SHORT_URL_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last7Days' },
|
||||
],
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 200)) })],
|
||||
{ type: GET_SHORT_URL_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last365Days' },
|
||||
],
|
||||
[[], expect.objectContaining({ type: GET_SHORT_URL_VISITS }) ],
|
||||
[[], expect.objectContaining({ type: GET_SHORT_URL_VISITS })],
|
||||
])('dispatches fallback interval when the list of visits is empty', async (lastVisits, expectedSecondDispatch) => {
|
||||
const buildVisitsResult = (data: Visit[] = []): ShlinkVisits => ({
|
||||
data,
|
||||
|
||||
@@ -71,8 +71,8 @@ describe('tagVisitsReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ tag: 'foo' }, visitsMocks.length + 1 ],
|
||||
[{ tag: 'bar' }, visitsMocks.length ],
|
||||
[{ tag: 'foo' }, visitsMocks.length + 1],
|
||||
[{ tag: 'bar' }, visitsMocks.length],
|
||||
[
|
||||
Mock.of<TagVisits>({
|
||||
tag: 'foo',
|
||||
@@ -119,7 +119,7 @@ describe('tagVisitsReducer', () => {
|
||||
],
|
||||
])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => {
|
||||
const shortUrl = {
|
||||
tags: [ 'foo', 'baz' ],
|
||||
tags: ['foo', 'baz'],
|
||||
};
|
||||
const prevState = buildState({
|
||||
...state,
|
||||
@@ -163,22 +163,22 @@ describe('tagVisitsReducer', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
it('dispatches start and error when promise is rejected', async () => {
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.reject({}));
|
||||
const shlinkApiClient = buildApiClientMock(Promise.reject(new Error()));
|
||||
|
||||
await getTagVisits(() => ShlinkApiClient)('foo')(dispatchMock, getState);
|
||||
await getTagVisits(() => shlinkApiClient)('foo')(dispatchMock, getState);
|
||||
|
||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_TAG_VISITS_START });
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_TAG_VISITS_ERROR });
|
||||
expect(ShlinkApiClient.getTagVisits).toHaveBeenCalledTimes(1);
|
||||
expect(shlinkApiClient.getTagVisits).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ undefined ],
|
||||
[undefined],
|
||||
[{}],
|
||||
])('dispatches start and success when promise is resolved', async (query) => {
|
||||
const visits = visitsMocks;
|
||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve({
|
||||
const shlinkApiClient = buildApiClientMock(Promise.resolve({
|
||||
data: visitsMocks,
|
||||
pagination: {
|
||||
currentPage: 1,
|
||||
@@ -187,24 +187,24 @@ describe('tagVisitsReducer', () => {
|
||||
},
|
||||
}));
|
||||
|
||||
await getTagVisits(() => ShlinkApiClient)(tag, query)(dispatchMock, getState);
|
||||
await getTagVisits(() => shlinkApiClient)(tag, query)(dispatchMock, getState);
|
||||
|
||||
expect(dispatchMock).toHaveBeenCalledTimes(2);
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_TAG_VISITS_START });
|
||||
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_TAG_VISITS, visits, tag, query: query ?? {} });
|
||||
expect(ShlinkApiClient.getTagVisits).toHaveBeenCalledTimes(1);
|
||||
expect(shlinkApiClient.getTagVisits).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 20)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 20)) })],
|
||||
{ type: GET_TAG_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last30Days' },
|
||||
],
|
||||
[
|
||||
[ Mock.of<Visit>({ date: formatISO(subDays(new Date(), 100)) }) ],
|
||||
[Mock.of<Visit>({ date: formatISO(subDays(new Date(), 100)) })],
|
||||
{ type: GET_TAG_VISITS_FALLBACK_TO_INTERVAL, fallbackInterval: 'last180Days' },
|
||||
],
|
||||
[[], expect.objectContaining({ type: GET_TAG_VISITS }) ],
|
||||
[[], expect.objectContaining({ type: GET_TAG_VISITS })],
|
||||
])('dispatches fallback interval when the list of visits is empty', async (lastVisits, expectedSecondDispatch) => {
|
||||
const buildVisitsResult = (data: Visit[] = []): ShlinkVisits => ({
|
||||
data,
|
||||
|
||||
@@ -8,9 +8,10 @@ describe('visitCreationReducer', () => {
|
||||
const shortUrl = Mock.all<ShortUrl>();
|
||||
const visit = Mock.all<Visit>();
|
||||
|
||||
it('just returns the action with proper type', () =>
|
||||
it('just returns the action with proper type', () => {
|
||||
expect(createNewVisits([{ shortUrl, visit }])).toEqual(
|
||||
{ type: CREATE_VISITS, createdVisits: [{ shortUrl, visit }] },
|
||||
));
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,9 +44,9 @@ describe('visitsOverviewReducer', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ 50, 53 ],
|
||||
[ 0, 3 ],
|
||||
[ undefined, 3 ],
|
||||
[50, 53],
|
||||
[0, 3],
|
||||
[undefined, 3],
|
||||
])('returns updated amounts on CREATE_VISITS', (providedOrphanVisitsCount, expectedOrphanVisitsCount) => {
|
||||
const { visitsCount, orphanVisitsCount } = reducer(
|
||||
state({ visitsCount: 100, orphanVisitsCount: providedOrphanVisitsCount }),
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('VisitsParser', () => {
|
||||
const { referrers } = stats;
|
||||
|
||||
expect(referrers).toEqual({
|
||||
'Direct': 2,
|
||||
Direct: 2,
|
||||
'google.com': 2,
|
||||
'm.facebook.com': 1,
|
||||
});
|
||||
@@ -120,9 +120,9 @@ describe('VisitsParser', () => {
|
||||
const { countries } = stats;
|
||||
|
||||
expect(countries).toEqual({
|
||||
'Spain': 3,
|
||||
Spain: 3,
|
||||
'United States': 1,
|
||||
'Unknown': 1,
|
||||
Unknown: 1,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -130,9 +130,9 @@ describe('VisitsParser', () => {
|
||||
const { cities } = stats;
|
||||
|
||||
expect(cities).toEqual({
|
||||
'Zaragoza': 2,
|
||||
Zaragoza: 2,
|
||||
'New York': 1,
|
||||
'Unknown': 2,
|
||||
Unknown: 2,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -144,15 +144,15 @@ describe('VisitsParser', () => {
|
||||
const newYorkLong = 6758;
|
||||
|
||||
expect(citiesForMap).toEqual({
|
||||
'Zaragoza': {
|
||||
Zaragoza: {
|
||||
cityName: 'Zaragoza',
|
||||
count: 2,
|
||||
latLong: [ zaragozaLat, zaragozaLong ],
|
||||
latLong: [zaragozaLat, zaragozaLong],
|
||||
},
|
||||
'New York': {
|
||||
cityName: 'New York',
|
||||
count: 1,
|
||||
latLong: [ newYorkLat, newYorkLong ],
|
||||
latLong: [newYorkLat, newYorkLong],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('visitsTypeHelpers', () => {
|
||||
];
|
||||
|
||||
return [
|
||||
[ ...orphanVisits, ...regularVisits ],
|
||||
[...orphanVisits, ...regularVisits],
|
||||
{ orphanVisits, regularVisits },
|
||||
];
|
||||
})(),
|
||||
@@ -43,7 +43,7 @@ describe('visitsTypeHelpers', () => {
|
||||
}),
|
||||
];
|
||||
|
||||
return [ orphanVisits, { orphanVisits, regularVisits: [] }];
|
||||
return [orphanVisits, { orphanVisits, regularVisits: [] }];
|
||||
})(),
|
||||
((): [CreateVisit[], GroupedNewVisits] => {
|
||||
const regularVisits: CreateVisit[] = [
|
||||
@@ -52,7 +52,7 @@ describe('visitsTypeHelpers', () => {
|
||||
Mock.of<CreateVisit>({ visit: Mock.all<Visit>() }),
|
||||
];
|
||||
|
||||
return [ regularVisits, { orphanVisits: [], regularVisits }];
|
||||
return [regularVisits, { orphanVisits: [], regularVisits }];
|
||||
})(),
|
||||
])('groups new visits as expected', (createdVisits, expectedResult) => {
|
||||
expect(groupNewVisitsByType(createdVisits)).toEqual(expectedResult);
|
||||
@@ -61,7 +61,7 @@ describe('visitsTypeHelpers', () => {
|
||||
|
||||
describe('toApiParams', () => {
|
||||
it.each([
|
||||
[ { page: 5, itemsPerPage: 100 } as VisitsParams, { page: 5, itemsPerPage: 100 } as ShlinkVisitsParams ],
|
||||
[{ page: 5, itemsPerPage: 100 } as VisitsParams, { page: 5, itemsPerPage: 100 } as ShlinkVisitsParams],
|
||||
[
|
||||
{
|
||||
page: 1,
|
||||
|
||||
Reference in New Issue
Block a user