2022-05-01 17:52:33 +03:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2022-02-05 18:37:01 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-01 17:52:33 +03:00
|
|
|
import { formatISO } from 'date-fns';
|
2022-02-05 18:37:01 +03:00
|
|
|
import { NonOrphanVisits as createNonOrphanVisits } from '../../src/visits/NonOrphanVisits';
|
|
|
|
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
2022-05-01 17:52:33 +03:00
|
|
|
import { Visit, VisitsInfo } from '../../src/visits/types';
|
2022-02-05 18:37:01 +03:00
|
|
|
import { Settings } from '../../src/settings/reducers/settings';
|
2022-03-13 20:56:42 +03:00
|
|
|
import { ReportExporter } from '../../src/common/services/ReportExporter';
|
2022-02-05 18:37:01 +03:00
|
|
|
import { SelectedServer } from '../../src/servers/data';
|
|
|
|
|
2022-02-08 00:17:57 +03:00
|
|
|
jest.mock('react-router-dom', () => ({
|
|
|
|
...jest.requireActual('react-router-dom'),
|
|
|
|
useNavigate: jest.fn().mockReturnValue(jest.fn()),
|
|
|
|
useParams: jest.fn().mockReturnValue({}),
|
|
|
|
}));
|
|
|
|
|
2022-02-05 18:37:01 +03:00
|
|
|
describe('<NonOrphanVisits />', () => {
|
2022-05-01 17:52:33 +03:00
|
|
|
const exportVisits = jest.fn();
|
|
|
|
const getNonOrphanVisits = jest.fn();
|
|
|
|
const cancelGetNonOrphanVisits = jest.fn();
|
|
|
|
const nonOrphanVisits = Mock.of<VisitsInfo>({ visits: [Mock.of<Visit>({ date: formatISO(new Date()) })] });
|
|
|
|
const NonOrphanVisits = createNonOrphanVisits(Mock.of<ReportExporter>({ exportVisits }));
|
2022-02-05 18:37:01 +03:00
|
|
|
|
2022-05-01 17:52:33 +03:00
|
|
|
beforeEach(() => render(
|
|
|
|
<MemoryRouter>
|
2022-02-05 18:37:01 +03:00
|
|
|
<NonOrphanVisits
|
|
|
|
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
|
|
|
getNonOrphanVisits={getNonOrphanVisits}
|
|
|
|
cancelGetNonOrphanVisits={cancelGetNonOrphanVisits}
|
2022-05-01 17:52:33 +03:00
|
|
|
nonOrphanVisits={nonOrphanVisits}
|
2022-02-05 18:37:01 +03:00
|
|
|
settings={Mock.all<Settings>()}
|
|
|
|
selectedServer={Mock.all<SelectedServer>()}
|
2022-05-01 17:52:33 +03:00
|
|
|
/>
|
|
|
|
</MemoryRouter>,
|
|
|
|
));
|
|
|
|
|
|
|
|
it('wraps visits stats and header', () => {
|
|
|
|
expect(screen.getByRole('heading', { name: 'Non-orphan visits' })).toBeInTheDocument();
|
|
|
|
expect(getNonOrphanVisits).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('exports visits when clicking the button', () => {
|
|
|
|
const btn = screen.getByRole('button', { name: 'Export (1)' });
|
|
|
|
|
|
|
|
expect(exportVisits).not.toHaveBeenCalled();
|
|
|
|
expect(btn).toBeInTheDocument();
|
2022-02-05 18:37:01 +03:00
|
|
|
|
2022-05-01 17:52:33 +03:00
|
|
|
fireEvent.click(btn);
|
|
|
|
expect(exportVisits).toHaveBeenCalledWith('non_orphan_visits.csv', expect.anything());
|
2022-02-05 18:37:01 +03:00
|
|
|
});
|
|
|
|
});
|