2022-07-10 00:03:21 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2023-04-13 23:47:13 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { formatISO } from 'date-fns';
|
2022-06-10 22:31:13 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-07-24 21:14:59 +03:00
|
|
|
import type { MercureBoundProps } from '../../shlink-web-component/mercure/helpers/boundToMercureHub';
|
|
|
|
import { OrphanVisits as createOrphanVisits } from '../../shlink-web-component/visits/OrphanVisits';
|
|
|
|
import type { VisitsInfo } from '../../shlink-web-component/visits/reducers/types';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2022-02-08 00:17:57 +03:00
|
|
|
|
2021-02-28 12:36:56 +03:00
|
|
|
describe('<OrphanVisits />', () => {
|
2023-05-27 12:57:26 +03:00
|
|
|
const getOrphanVisits = vi.fn();
|
|
|
|
const exportVisits = vi.fn();
|
2023-04-13 23:47:13 +03:00
|
|
|
const orphanVisits = fromPartial<VisitsInfo>({ visits: [{ date: formatISO(new Date()) }] });
|
|
|
|
const OrphanVisits = createOrphanVisits(fromPartial({ exportVisits }));
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = () => renderWithEvents(
|
|
|
|
<MemoryRouter>
|
|
|
|
<OrphanVisits
|
2023-04-13 23:47:13 +03:00
|
|
|
{...fromPartial<MercureBoundProps>({ mercureInfo: {} })}
|
2022-07-10 00:03:21 +03:00
|
|
|
getOrphanVisits={getOrphanVisits}
|
|
|
|
orphanVisits={orphanVisits}
|
2023-05-27 12:57:26 +03:00
|
|
|
cancelGetOrphanVisits={vi.fn()}
|
2023-04-13 23:47:13 +03:00
|
|
|
settings={fromPartial({})}
|
2022-07-10 00:03:21 +03:00
|
|
|
/>
|
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
2022-06-10 22:31:13 +03:00
|
|
|
|
2021-02-28 12:36:56 +03:00
|
|
|
it('wraps visits stats and header', () => {
|
2022-06-10 22:31:13 +03:00
|
|
|
setUp();
|
|
|
|
expect(screen.getByRole('heading', { name: 'Orphan visits' })).toBeInTheDocument();
|
|
|
|
expect(getOrphanVisits).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('exports visits when clicking the button', async () => {
|
|
|
|
const { user } = setUp();
|
|
|
|
const btn = screen.getByRole('button', { name: 'Export (1)' });
|
2021-02-28 12:36:56 +03:00
|
|
|
|
2022-06-10 22:31:13 +03:00
|
|
|
expect(exportVisits).not.toHaveBeenCalled();
|
|
|
|
expect(btn).toBeInTheDocument();
|
2021-02-28 12:36:56 +03:00
|
|
|
|
2022-06-10 22:31:13 +03:00
|
|
|
await user.click(btn);
|
|
|
|
expect(exportVisits).toHaveBeenCalledWith('orphan_visits.csv', expect.anything());
|
2021-02-28 12:36:56 +03:00
|
|
|
});
|
|
|
|
});
|