2022-07-09 23:03:21 +02:00
|
|
|
import { screen } from '@testing-library/react';
|
2023-04-13 22:47:13 +02:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-02-18 11:11:01 +01:00
|
|
|
import { formatISO } from 'date-fns';
|
2022-05-01 16:52:33 +02:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-07-24 20:14:59 +02:00
|
|
|
import type { MercureBoundProps } from '../../shlink-web-component/mercure/helpers/boundToMercureHub';
|
|
|
|
import { NonOrphanVisits as createNonOrphanVisits } from '../../shlink-web-component/visits/NonOrphanVisits';
|
|
|
|
import type { VisitsInfo } from '../../shlink-web-component/visits/reducers/types';
|
2023-02-18 11:11:01 +01:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2022-02-05 16:37:01 +01:00
|
|
|
|
|
|
|
describe('<NonOrphanVisits />', () => {
|
2023-05-27 11:57:26 +02:00
|
|
|
const exportVisits = vi.fn();
|
|
|
|
const getNonOrphanVisits = vi.fn();
|
|
|
|
const cancelGetNonOrphanVisits = vi.fn();
|
2023-04-13 22:47:13 +02:00
|
|
|
const nonOrphanVisits = fromPartial<VisitsInfo>({ visits: [{ date: formatISO(new Date()) }] });
|
|
|
|
const NonOrphanVisits = createNonOrphanVisits(fromPartial({ exportVisits }));
|
2022-07-09 23:03:21 +02:00
|
|
|
const setUp = () => renderWithEvents(
|
|
|
|
<MemoryRouter>
|
|
|
|
<NonOrphanVisits
|
2023-04-13 22:47:13 +02:00
|
|
|
{...fromPartial<MercureBoundProps>({ mercureInfo: {} })}
|
2022-07-09 23:03:21 +02:00
|
|
|
getNonOrphanVisits={getNonOrphanVisits}
|
|
|
|
cancelGetNonOrphanVisits={cancelGetNonOrphanVisits}
|
|
|
|
nonOrphanVisits={nonOrphanVisits}
|
2023-04-13 22:47:13 +02:00
|
|
|
settings={fromPartial({})}
|
2022-07-09 23:03:21 +02:00
|
|
|
/>
|
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
2022-05-01 16:52:33 +02:00
|
|
|
|
|
|
|
it('wraps visits stats and header', () => {
|
2022-05-11 19:18:43 +02:00
|
|
|
setUp();
|
2022-05-01 16:52:33 +02:00
|
|
|
expect(screen.getByRole('heading', { name: 'Non-orphan visits' })).toBeInTheDocument();
|
|
|
|
expect(getNonOrphanVisits).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-05-11 19:18:43 +02:00
|
|
|
it('exports visits when clicking the button', async () => {
|
|
|
|
const { user } = setUp();
|
2022-05-01 16:52:33 +02:00
|
|
|
const btn = screen.getByRole('button', { name: 'Export (1)' });
|
|
|
|
|
|
|
|
expect(exportVisits).not.toHaveBeenCalled();
|
|
|
|
expect(btn).toBeInTheDocument();
|
2022-02-05 16:37:01 +01:00
|
|
|
|
2022-05-11 19:18:43 +02:00
|
|
|
await user.click(btn);
|
2022-05-01 16:52:33 +02:00
|
|
|
expect(exportVisits).toHaveBeenCalledWith('non_orphan_visits.csv', expect.anything());
|
2022-02-05 16:37:01 +01:00
|
|
|
});
|
|
|
|
});
|