2022-06-10 22:31:13 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2021-02-28 12:36:56 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-06-10 22:31:13 +03:00
|
|
|
import { formatISO } from 'date-fns';
|
2021-03-14 14:49:12 +03:00
|
|
|
import { OrphanVisits as createOrphanVisits } from '../../src/visits/OrphanVisits';
|
2021-02-28 12:36:56 +03:00
|
|
|
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
2022-06-10 22:31:13 +03:00
|
|
|
import { Visit, VisitsInfo } from '../../src/visits/types';
|
2021-03-06 18:54:43 +03:00
|
|
|
import { Settings } from '../../src/settings/reducers/settings';
|
2022-03-13 20:56:42 +03:00
|
|
|
import { ReportExporter } from '../../src/common/services/ReportExporter';
|
2021-06-13 12:54:51 +03:00
|
|
|
import { SelectedServer } from '../../src/servers/data';
|
2022-02-08 00:17:57 +03:00
|
|
|
|
2021-02-28 12:36:56 +03:00
|
|
|
describe('<OrphanVisits />', () => {
|
2022-06-10 22:31:13 +03:00
|
|
|
const getOrphanVisits = jest.fn();
|
|
|
|
const exportVisits = jest.fn();
|
|
|
|
const orphanVisits = Mock.of<VisitsInfo>({ visits: [Mock.of<Visit>({ date: formatISO(new Date()) })] });
|
|
|
|
const OrphanVisits = createOrphanVisits(Mock.of<ReportExporter>({ exportVisits }));
|
|
|
|
const setUp = () => ({
|
|
|
|
user: userEvent.setup(),
|
|
|
|
...render(
|
|
|
|
<MemoryRouter>
|
|
|
|
<OrphanVisits
|
|
|
|
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
|
|
|
getOrphanVisits={getOrphanVisits}
|
|
|
|
orphanVisits={orphanVisits}
|
|
|
|
cancelGetOrphanVisits={jest.fn()}
|
|
|
|
settings={Mock.all<Settings>()}
|
|
|
|
selectedServer={Mock.all<SelectedServer>()}
|
|
|
|
/>
|
|
|
|
</MemoryRouter>,
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|