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';
|
2021-03-14 14:49:12 +03:00
|
|
|
import createShortUrlVisits, { 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';
|
2021-03-05 18:04:02 +03:00
|
|
|
import { ShortUrlDetail } from '../../src/short-urls/reducers/shortUrlDetail';
|
2020-09-05 09:49:18 +03:00
|
|
|
import VisitsStats from '../../src/visits/VisitsStats';
|
2020-09-06 20:41:15 +03:00
|
|
|
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
2022-03-13 20:56:42 +03:00
|
|
|
import { ReportExporter } from '../../src/common/services/ReportExporter';
|
2018-09-08 14:28:40 +03:00
|
|
|
|
2022-02-08 00:17:57 +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 />', () => {
|
2020-09-04 20:33:16 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2019-04-19 13:41:59 +03:00
|
|
|
const getShortUrlVisitsMock = jest.fn();
|
2022-03-13 20:56:42 +03:00
|
|
|
const ShortUrlVisits = createShortUrlVisits(Mock.all<ReportExporter>());
|
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>()}
|
2020-09-12 09:52:03 +03:00
|
|
|
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
2018-09-08 14:28:40 +03:00
|
|
|
getShortUrlDetail={identity}
|
|
|
|
getShortUrlVisits={getShortUrlVisitsMock}
|
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
|
|
|
/>,
|
2020-09-06 20:41:15 +03:00
|
|
|
).dive(); // Dive is needed as this component is wrapped in a HOC
|
2018-09-08 14:28:40 +03:00
|
|
|
});
|
|
|
|
|
2022-02-08 00:17:57 +03:00
|
|
|
afterEach(jest.clearAllMocks);
|
2020-05-10 18:49:55 +03:00
|
|
|
afterEach(() => wrapper.unmount());
|
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);
|
2022-02-05 18:37:01 +03:00
|
|
|
expect(visitStats.prop('isOrphanVisits')).not.toBeDefined();
|
2020-05-10 18:49:55 +03:00
|
|
|
expect(visitHeader).toHaveLength(1);
|
2019-01-09 22:11:22 +03:00
|
|
|
});
|
2018-09-08 14:28:40 +03:00
|
|
|
});
|