From eb0ab92472ac3a72789502b6a71fcf43f251cf8e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 28 Feb 2021 10:36:56 +0100 Subject: [PATCH] Created OrphanVisits test --- package.json | 2 +- src/visits/OrphanVisits.tsx | 6 ++--- test/visits/OrphanVisits.test.tsx | 41 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 test/visits/OrphanVisits.test.tsx diff --git a/package.json b/package.json index 2f4a282a..fc81f1d2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "start": "node scripts/start.js", "serve:build": "serve ./build", "build": "node scripts/build.js", - "test": "node scripts/test.js --env=jsdom --colors", + "test": "node scripts/test.js --env=jsdom --colors --verbose", "test:ci": "npm run test -- --coverage --coverageReporters=text --coverageReporters=text-summary --coverageReporters=clover", "test:pretty": "npm run test -- --coverage --coverageReporters=text --coverageReporters=text-summary --coverageReporters=html", "mutate": "./node_modules/.bin/stryker run --concurrency 4" diff --git a/src/visits/OrphanVisits.tsx b/src/visits/OrphanVisits.tsx index a6ae86a7..cb959869 100644 --- a/src/visits/OrphanVisits.tsx +++ b/src/visits/OrphanVisits.tsx @@ -2,13 +2,13 @@ import { RouteComponentProps } from 'react-router'; import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub'; import { ShlinkVisitsParams } from '../api/types'; import { Topics } from '../mercure/helpers/Topics'; -import { TagVisits as TagVisitsState } from './reducers/tagVisits'; import VisitsStats from './VisitsStats'; import { OrphanVisitsHeader } from './OrphanVisitsHeader'; +import { VisitsInfo } from './types'; -export interface OrphanVisitsProps extends RouteComponentProps<{ tag: string }> { +export interface OrphanVisitsProps extends RouteComponentProps { getOrphanVisits: (params: ShlinkVisitsParams) => void; - orphanVisits: TagVisitsState; + orphanVisits: VisitsInfo; cancelGetOrphanVisits: () => void; } diff --git a/test/visits/OrphanVisits.test.tsx b/test/visits/OrphanVisits.test.tsx new file mode 100644 index 00000000..be362905 --- /dev/null +++ b/test/visits/OrphanVisits.test.tsx @@ -0,0 +1,41 @@ +import { shallow } from 'enzyme'; +import { Mock } from 'ts-mockery'; +import { History, Location } from 'history'; +import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/no-unused-vars +import { OrphanVisits } from '../../src/visits/OrphanVisits'; +import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; +import { VisitsInfo } from '../../src/visits/types'; +import VisitsStats from '../../src/visits/VisitsStats'; +import { OrphanVisitsHeader } from '../../src/visits/OrphanVisitsHeader'; + +describe('', () => { + it('wraps visits stats and header', () => { + const goBack = jest.fn(); + const getOrphanVisits = jest.fn(); + const cancelGetOrphanVisits = jest.fn(); + const orphanVisits = Mock.all(); + + const wrapper = shallow( + ({ mercureInfo: {} })} + getOrphanVisits={getOrphanVisits} + orphanVisits={orphanVisits} + cancelGetOrphanVisits={cancelGetOrphanVisits} + history={Mock.of({ goBack })} + location={Mock.all()} + match={Mock.of({ url: 'the_base_url' })} + />, + ).dive(); + const stats = wrapper.find(VisitsStats); + const header = wrapper.find(OrphanVisitsHeader); + + expect(stats).toHaveLength(1); + expect(header).toHaveLength(1); + expect(stats.prop('getVisits')).toEqual(getOrphanVisits); + expect(stats.prop('cancelGetVisits')).toEqual(cancelGetOrphanVisits); + expect(stats.prop('visitsInfo')).toEqual(orphanVisits); + expect(stats.prop('baseUrl')).toEqual('the_base_url'); + expect(header.prop('orphanVisits')).toEqual(orphanVisits); + expect(header.prop('goBack')).toEqual(goBack); + }); +});