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

54 lines
2.1 KiB
TypeScript
Raw Normal View History

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
2021-03-14 14:49:12 +03:00
import createShortUrlVisits, { ShortUrlVisitsProps } from '../../src/visits/ShortUrlVisits';
import ShortUrlVisitsHeader from '../../src/visits/ShortUrlVisitsHeader';
import { ShortUrlVisits as ShortUrlVisitsState } from '../../src/visits/reducers/shortUrlVisits';
import { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail';
2020-09-05 09:49:18 +03:00
import VisitsStats from '../../src/visits/VisitsStats';
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
2021-03-14 14:49:12 +03:00
import { VisitsExporter } from '../../src/visits/services/VisitsExporter';
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(),
});
2021-03-14 14:49:12 +03:00
const ShortUrlVisits = createShortUrlVisits(Mock.all<VisitsExporter>());
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
});