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

50 lines
2 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';
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
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: jest.fn().mockReturnValue(jest.fn()),
useLocation: jest.fn().mockReturnValue({ search: '' }),
useParams: jest.fn().mockReturnValue({ shortCode: 'abc123' }),
}));
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();
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}
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(jest.clearAllMocks);
afterEach(() => wrapper.unmount());
it('renders visit stats and visits header', () => {
const visitStats = wrapper.find(VisitsStats);
const visitHeader = wrapper.find(ShortUrlVisitsHeader);
expect(visitStats).toHaveLength(1);
expect(visitStats.prop('isOrphanVisits')).not.toBeDefined();
expect(visitHeader).toHaveLength(1);
});
2018-09-08 14:28:40 +03:00
});