mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 17:43:51 +00:00
Fixed tests
This commit is contained in:
@@ -35,9 +35,7 @@ export const extractDomain = (url: string | Empty): string => {
|
|||||||
return 'Direct';
|
return 'Direct';
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = url.includes('://') ? url.split('/')[2] : url.split('/')[0];
|
return url.split('/')[url.includes('://') ? 2 : 0]?.split(':')[0] ?? '';
|
||||||
|
|
||||||
return domain.split(':')[0];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fillTheGaps = (stats: Stats, labels: string[]): number[] =>
|
export const fillTheGaps = (stats: Stats, labels: string[]): number[] =>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { shallow, ShallowWrapper } from 'enzyme';
|
|||||||
import { Doughnut, HorizontalBar } from 'react-chartjs-2';
|
import { Doughnut, HorizontalBar } from 'react-chartjs-2';
|
||||||
import { keys, values } from 'ramda';
|
import { keys, values } from 'ramda';
|
||||||
import DefaultChart from '../../../src/visits/helpers/DefaultChart';
|
import DefaultChart from '../../../src/visits/helpers/DefaultChart';
|
||||||
|
import { prettify } from '../../../src/utils/helpers/numbers';
|
||||||
|
|
||||||
describe('<DefaultChart />', () => {
|
describe('<DefaultChart />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
@@ -69,7 +70,7 @@ describe('<DefaultChart />', () => {
|
|||||||
expect(scales).toEqual({
|
expect(scales).toEqual({
|
||||||
xAxes: [
|
xAxes: [
|
||||||
{
|
{
|
||||||
ticks: { beginAtZero: true, precision: 0 },
|
ticks: { beginAtZero: true, precision: 0, callback: prettify },
|
||||||
stacked: true,
|
stacked: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import moment from 'moment';
|
|||||||
import { Mock } from 'ts-mockery';
|
import { Mock } from 'ts-mockery';
|
||||||
import LineChartCard from '../../../src/visits/helpers/LineChartCard';
|
import LineChartCard from '../../../src/visits/helpers/LineChartCard';
|
||||||
import ToggleSwitch from '../../../src/utils/ToggleSwitch';
|
import ToggleSwitch from '../../../src/utils/ToggleSwitch';
|
||||||
import { Visit } from '../../../src/visits/types';
|
import { NormalizedVisit } from '../../../src/visits/types';
|
||||||
|
import { prettify } from '../../../src/utils/helpers/numbers';
|
||||||
|
|
||||||
describe('<LineChartCard />', () => {
|
describe('<LineChartCard />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
const createWrapper = (visits: Visit[] = [], highlightedVisits: Visit[] = []) => {
|
const createWrapper = (visits: NormalizedVisit[] = [], highlightedVisits: NormalizedVisit[] = []) => {
|
||||||
wrapper = shallow(<LineChartCard title="Cool title" visits={visits} highlightedVisits={highlightedVisits} />);
|
wrapper = shallow(<LineChartCard title="Cool title" visits={visits} highlightedVisits={highlightedVisits} />);
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
@@ -34,7 +35,7 @@ describe('<LineChartCard />', () => {
|
|||||||
[[{ date: moment().subtract(7, 'month').format() }], 'monthly' ],
|
[[{ date: moment().subtract(7, 'month').format() }], 'monthly' ],
|
||||||
[[{ date: moment().subtract(1, 'year').format() }], 'monthly' ],
|
[[{ date: moment().subtract(1, 'year').format() }], 'monthly' ],
|
||||||
])('renders group menu and selects proper grouping item based on visits dates', (visits, expectedActiveItem) => {
|
])('renders group menu and selects proper grouping item based on visits dates', (visits, expectedActiveItem) => {
|
||||||
const wrapper = createWrapper(visits.map((visit) => Mock.of<Visit>(visit)));
|
const wrapper = createWrapper(visits.map((visit) => Mock.of<NormalizedVisit>(visit)));
|
||||||
const items = wrapper.find(DropdownItem);
|
const items = wrapper.find(DropdownItem);
|
||||||
|
|
||||||
expect(items).toHaveLength(4);
|
expect(items).toHaveLength(4);
|
||||||
@@ -58,7 +59,7 @@ describe('<LineChartCard />', () => {
|
|||||||
scales: {
|
scales: {
|
||||||
yAxes: [
|
yAxes: [
|
||||||
{
|
{
|
||||||
ticks: { beginAtZero: true, precision: 0 },
|
ticks: { beginAtZero: true, precision: 0, callback: prettify },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
xAxes: [
|
xAxes: [
|
||||||
@@ -67,16 +68,16 @@ describe('<LineChartCard />', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
tooltips: {
|
tooltips: expect.objectContaining({
|
||||||
intersect: false,
|
intersect: false,
|
||||||
axis: 'x',
|
axis: 'x',
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[[ Mock.of<Visit>({}) ], [], 1 ],
|
[[ Mock.of<NormalizedVisit>({}) ], [], 1 ],
|
||||||
[[ Mock.of<Visit>({}) ], [ Mock.of<Visit>({}) ], 2 ],
|
[[ Mock.of<NormalizedVisit>({}) ], [ Mock.of<NormalizedVisit>({}) ], 2 ],
|
||||||
])('renders chart with expected data', (visits, highlightedVisits, expectedLines) => {
|
])('renders chart with expected data', (visits, highlightedVisits, expectedLines) => {
|
||||||
const wrapper = createWrapper(visits, highlightedVisits);
|
const wrapper = createWrapper(visits, highlightedVisits);
|
||||||
const chart = wrapper.find(Line);
|
const chart = wrapper.find(Line);
|
||||||
@@ -87,8 +88,8 @@ describe('<LineChartCard />', () => {
|
|||||||
|
|
||||||
it('includes stats for visits with no dates if selected', () => {
|
it('includes stats for visits with no dates if selected', () => {
|
||||||
const wrapper = createWrapper([
|
const wrapper = createWrapper([
|
||||||
Mock.of<Visit>({ date: '2016-04-01' }),
|
Mock.of<NormalizedVisit>({ date: '2016-04-01' }),
|
||||||
Mock.of<Visit>({ date: '2016-01-01' }),
|
Mock.of<NormalizedVisit>({ date: '2016-01-01' }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect((wrapper.find(Line).prop('data') as any).labels).toHaveLength(2);
|
expect((wrapper.find(Line).prop('data') as any).labels).toHaveLength(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user