From 51556d76acb5ba3b53273b2aa08992eba8ae6350 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 17 Sep 2020 18:05:26 +0200 Subject: [PATCH] Fixed tests --- src/utils/helpers/visits.ts | 4 +--- test/visits/helpers/DefaultChart.test.tsx | 3 ++- test/visits/helpers/LineChartCard.test.tsx | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/utils/helpers/visits.ts b/src/utils/helpers/visits.ts index 7a2bd7e2..89dc1d57 100644 --- a/src/utils/helpers/visits.ts +++ b/src/utils/helpers/visits.ts @@ -35,9 +35,7 @@ export const extractDomain = (url: string | Empty): string => { return 'Direct'; } - const domain = url.includes('://') ? url.split('/')[2] : url.split('/')[0]; - - return domain.split(':')[0]; + return url.split('/')[url.includes('://') ? 2 : 0]?.split(':')[0] ?? ''; }; export const fillTheGaps = (stats: Stats, labels: string[]): number[] => diff --git a/test/visits/helpers/DefaultChart.test.tsx b/test/visits/helpers/DefaultChart.test.tsx index 43312cec..4ac0056f 100644 --- a/test/visits/helpers/DefaultChart.test.tsx +++ b/test/visits/helpers/DefaultChart.test.tsx @@ -3,6 +3,7 @@ import { shallow, ShallowWrapper } from 'enzyme'; import { Doughnut, HorizontalBar } from 'react-chartjs-2'; import { keys, values } from 'ramda'; import DefaultChart from '../../../src/visits/helpers/DefaultChart'; +import { prettify } from '../../../src/utils/helpers/numbers'; describe('', () => { let wrapper: ShallowWrapper; @@ -69,7 +70,7 @@ describe('', () => { expect(scales).toEqual({ xAxes: [ { - ticks: { beginAtZero: true, precision: 0 }, + ticks: { beginAtZero: true, precision: 0, callback: prettify }, stacked: true, }, ], diff --git a/test/visits/helpers/LineChartCard.test.tsx b/test/visits/helpers/LineChartCard.test.tsx index 1fc0113a..8aaf2a48 100644 --- a/test/visits/helpers/LineChartCard.test.tsx +++ b/test/visits/helpers/LineChartCard.test.tsx @@ -6,11 +6,12 @@ import moment from 'moment'; import { Mock } from 'ts-mockery'; import LineChartCard from '../../../src/visits/helpers/LineChartCard'; 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('', () => { let wrapper: ShallowWrapper; - const createWrapper = (visits: Visit[] = [], highlightedVisits: Visit[] = []) => { + const createWrapper = (visits: NormalizedVisit[] = [], highlightedVisits: NormalizedVisit[] = []) => { wrapper = shallow(); return wrapper; @@ -34,7 +35,7 @@ describe('', () => { [[{ date: moment().subtract(7, 'month').format() }], 'monthly' ], [[{ date: moment().subtract(1, 'year').format() }], 'monthly' ], ])('renders group menu and selects proper grouping item based on visits dates', (visits, expectedActiveItem) => { - const wrapper = createWrapper(visits.map((visit) => Mock.of(visit))); + const wrapper = createWrapper(visits.map((visit) => Mock.of(visit))); const items = wrapper.find(DropdownItem); expect(items).toHaveLength(4); @@ -58,7 +59,7 @@ describe('', () => { scales: { yAxes: [ { - ticks: { beginAtZero: true, precision: 0 }, + ticks: { beginAtZero: true, precision: 0, callback: prettify }, }, ], xAxes: [ @@ -67,16 +68,16 @@ describe('', () => { }, ], }, - tooltips: { + tooltips: expect.objectContaining({ intersect: false, axis: 'x', - }, + }), }); }); it.each([ - [[ Mock.of({}) ], [], 1 ], - [[ Mock.of({}) ], [ Mock.of({}) ], 2 ], + [[ Mock.of({}) ], [], 1 ], + [[ Mock.of({}) ], [ Mock.of({}) ], 2 ], ])('renders chart with expected data', (visits, highlightedVisits, expectedLines) => { const wrapper = createWrapper(visits, highlightedVisits); const chart = wrapper.find(Line); @@ -87,8 +88,8 @@ describe('', () => { it('includes stats for visits with no dates if selected', () => { const wrapper = createWrapper([ - Mock.of({ date: '2016-04-01' }), - Mock.of({ date: '2016-01-01' }), + Mock.of({ date: '2016-04-01' }), + Mock.of({ date: '2016-01-01' }), ]); expect((wrapper.find(Line).prop('data') as any).labels).toHaveLength(2);