2018-09-08 14:28:40 +03:00
|
|
|
import React from 'react';
|
2020-09-04 20:33:16 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2018-09-08 14:28:40 +03:00
|
|
|
import { identity } from 'ramda';
|
2020-09-04 20:33:16 +03:00
|
|
|
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';
|
2020-05-10 20:37:00 +03:00
|
|
|
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
|
2020-09-04 20:33:16 +03:00
|
|
|
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';
|
2018-09-08 14:28:40 +03:00
|
|
|
|
|
|
|
describe('<ShortUrlVisits />', () => {
|
2020-09-04 20:33:16 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2019-04-19 13:41:59 +03:00
|
|
|
const getShortUrlVisitsMock = jest.fn();
|
2020-09-04 20:33:16 +03:00
|
|
|
const match = Mock.of<match<{ shortCode: string }>>({
|
2018-09-08 14:28:40 +03:00
|
|
|
params: { shortCode: 'abc123' },
|
2020-09-04 20:33:16 +03:00
|
|
|
});
|
|
|
|
const location = Mock.of<Location>({ search: '' });
|
|
|
|
const history = Mock.of<History>({
|
2020-04-26 11:43:00 +03:00
|
|
|
goBack: jest.fn(),
|
2020-09-04 20:33:16 +03:00
|
|
|
});
|
2018-09-08 14:28:40 +03:00
|
|
|
|
2020-05-10 18:49:55 +03:00
|
|
|
beforeEach(() => {
|
2018-09-08 14:28:40 +03:00
|
|
|
wrapper = shallow(
|
2018-12-18 16:32:02 +03:00
|
|
|
<ShortUrlVisits
|
2020-09-04 20:33:16 +03:00
|
|
|
{...Mock.all<ShortUrlVisitsProps>()}
|
2018-09-08 14:28:40 +03:00
|
|
|
getShortUrlDetail={identity}
|
|
|
|
getShortUrlVisits={getShortUrlVisitsMock}
|
|
|
|
match={match}
|
2020-02-08 11:07:55 +03:00
|
|
|
location={location}
|
2020-04-26 11:43:00 +03:00
|
|
|
history={history}
|
2020-09-04 20:33:16 +03:00
|
|
|
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
|
|
|
/>,
|
2018-09-08 14:28:40 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-05-10 18:49:55 +03:00
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
afterEach(jest.resetAllMocks);
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2020-05-10 18:49:55 +03:00
|
|
|
it('renders visit stats and visits header', () => {
|
|
|
|
const visitStats = wrapper.find(VisitsStats);
|
2020-05-10 20:37:00 +03:00
|
|
|
const visitHeader = wrapper.find(ShortUrlVisitsHeader);
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2020-05-10 18:49:55 +03:00
|
|
|
expect(visitStats).toHaveLength(1);
|
|
|
|
expect(visitHeader).toHaveLength(1);
|
2019-01-09 22:11:22 +03:00
|
|
|
});
|
2018-09-08 14:28:40 +03:00
|
|
|
});
|