shlink-web-client/test/visits/ShortUrlVisits.test.tsx

53 lines
2 KiB
TypeScript
Raw Normal View History

2018-09-08 14:28:40 +03:00
import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
2018-09-08 14:28:40 +03:00
import { identity } from 'ramda';
import { Mock } from 'ts-mockery';
import { History, Location } from 'history';
import { match } from 'react-router'; // eslint-disable-line @typescript-eslint/no-unused-vars
2020-09-05 09:49:18 +03:00
import ShortUrlVisits, { ShortUrlVisitsProps } from '../../src/visits/ShortUrlVisits';
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
import { ShortUrlVisits as ShortUrlVisitsState } from '../../src/visits/reducers/shortUrlVisits';
import { ShortUrlDetail } from '../../src/visits/reducers/shortUrlDetail';
2020-09-05 09:49:18 +03:00
import VisitsStats from '../../src/visits/VisitsStats';
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
2018-09-08 14:28:40 +03:00
describe('<ShortUrlVisits />', () => {
let wrapper: ShallowWrapper;
2019-04-19 13:41:59 +03:00
const getShortUrlVisitsMock = jest.fn();
const match = Mock.of<match<{ shortCode: string }>>({
2018-09-08 14:28:40 +03:00
params: { shortCode: 'abc123' },
});
const location = Mock.of<Location>({ search: '' });
const history = Mock.of<History>({
2020-04-26 11:43:00 +03:00
goBack: jest.fn(),
});
2018-09-08 14:28:40 +03:00
beforeEach(() => {
2018-09-08 14:28:40 +03:00
wrapper = shallow(
<ShortUrlVisits
{...Mock.all<ShortUrlVisitsProps>()}
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
2018-09-08 14:28:40 +03:00
getShortUrlDetail={identity}
getShortUrlVisits={getShortUrlVisitsMock}
match={match}
location={location}
2020-04-26 11:43:00 +03:00
history={history}
shortUrlVisits={Mock.of<ShortUrlVisitsState>({ loading: true, visits: [] })}
shortUrlDetail={Mock.all<ShortUrlDetail>()}
2020-09-05 09:49:18 +03:00
cancelGetShortUrlVisits={() => {}}
2020-08-22 09:10:31 +03:00
/>,
).dive(); // Dive is needed as this component is wrapped in a HOC
2018-09-08 14:28:40 +03:00
});
afterEach(() => wrapper.unmount());
afterEach(jest.resetAllMocks);
it('renders visit stats and visits header', () => {
const visitStats = wrapper.find(VisitsStats);
const visitHeader = wrapper.find(ShortUrlVisitsHeader);
expect(visitStats).toHaveLength(1);
expect(visitHeader).toHaveLength(1);
});
2018-09-08 14:28:40 +03:00
});