Created tests for non-orphan visits components

This commit is contained in:
Alejandro Celaya 2022-02-05 16:37:01 +01:00
parent 9bc5a050eb
commit 5edb62e76b
5 changed files with 72 additions and 1 deletions

View file

@ -0,0 +1,47 @@
import { shallow } from 'enzyme';
import { Mock } from 'ts-mockery';
import { History, Location } from 'history';
import { match } from 'react-router';
import { NonOrphanVisits as createNonOrphanVisits } from '../../src/visits/NonOrphanVisits';
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
import { VisitsInfo } from '../../src/visits/types';
import VisitsStats from '../../src/visits/VisitsStats';
import { NonOrphanVisitsHeader } from '../../src/visits/NonOrphanVisitsHeader';
import { Settings } from '../../src/settings/reducers/settings';
import { VisitsExporter } from '../../src/visits/services/VisitsExporter';
import { SelectedServer } from '../../src/servers/data';
describe('<NonOrphanVisits />', () => {
it('wraps visits stats and header', () => {
const goBack = jest.fn();
const getNonOrphanVisits = jest.fn();
const cancelGetNonOrphanVisits = jest.fn();
const nonOrphanVisits = Mock.all<VisitsInfo>();
const NonOrphanVisits = createNonOrphanVisits(Mock.all<VisitsExporter>());
const wrapper = shallow(
<NonOrphanVisits
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
getNonOrphanVisits={getNonOrphanVisits}
nonOrphanVisits={nonOrphanVisits}
cancelGetNonOrphanVisits={cancelGetNonOrphanVisits}
history={Mock.of<History>({ goBack })}
location={Mock.all<Location>()}
match={Mock.of<match>({ url: 'the_base_url' })}
settings={Mock.all<Settings>()}
selectedServer={Mock.all<SelectedServer>()}
/>,
).dive();
const stats = wrapper.find(VisitsStats);
const header = wrapper.find(NonOrphanVisitsHeader);
expect(stats).toHaveLength(1);
expect(header).toHaveLength(1);
expect(stats.prop('cancelGetVisits')).toEqual(cancelGetNonOrphanVisits);
expect(stats.prop('visitsInfo')).toEqual(nonOrphanVisits);
expect(stats.prop('baseUrl')).toEqual('the_base_url');
expect(stats.prop('isOrphanVisits')).not.toBeDefined();
expect(header.prop('nonOrphanVisits')).toEqual(nonOrphanVisits);
expect(header.prop('goBack')).toEqual(goBack);
});
});

View file

@ -0,0 +1,21 @@
import { shallow } from 'enzyme';
import { Mock } from 'ts-mockery';
import { NonOrphanVisitsHeader } from '../../src/visits/NonOrphanVisitsHeader';
import VisitsHeader from '../../src/visits/VisitsHeader';
import { Visit, VisitsInfo } from '../../src/visits/types';
describe('<NonOrphanVisitsHeader />', () => {
it('wraps a VisitsHeader with provided data', () => {
const visits: Visit[] = [];
const orphanVisits = Mock.of<VisitsInfo>({ visits });
const goBack = jest.fn();
const wrapper = shallow(<NonOrphanVisitsHeader nonOrphanVisits={orphanVisits} goBack={goBack} />);
const visitsHeader = wrapper.find(VisitsHeader);
expect(visitsHeader).toHaveLength(1);
expect(visitsHeader.prop('visits')).toEqual(visits);
expect(visitsHeader.prop('goBack')).toEqual(goBack);
expect(visitsHeader.prop('title')).toEqual('Non-orphan visits');
});
});

View file

@ -1,7 +1,7 @@
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 { match } from 'react-router';
import { OrphanVisits as createOrphanVisits } from '../../src/visits/OrphanVisits';
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
import { VisitsInfo } from '../../src/visits/types';
@ -40,6 +40,7 @@ describe('<OrphanVisits />', () => {
expect(stats.prop('cancelGetVisits')).toEqual(cancelGetOrphanVisits);
expect(stats.prop('visitsInfo')).toEqual(orphanVisits);
expect(stats.prop('baseUrl')).toEqual('the_base_url');
expect(stats.prop('isOrphanVisits')).toEqual(true);
expect(header.prop('orphanVisits')).toEqual(orphanVisits);
expect(header.prop('goBack')).toEqual(goBack);
});

View file

@ -48,6 +48,7 @@ describe('<ShortUrlVisits />', () => {
const visitHeader = wrapper.find(ShortUrlVisitsHeader);
expect(visitStats).toHaveLength(1);
expect(visitStats.prop('isOrphanVisits')).not.toBeDefined();
expect(visitHeader).toHaveLength(1);
});
});

View file

@ -44,6 +44,7 @@ describe('<TagVisits />', () => {
const visitHeader = wrapper.find(TagVisitsHeader);
expect(visitStats).toHaveLength(1);
expect(visitStats.prop('isOrphanVisits')).not.toBeDefined();
expect(visitHeader).toHaveLength(1);
});
});