mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-13 19:13:46 +00:00
Replaced firEvent with userEvent as much as possible
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { formatISO } from 'date-fns';
|
||||
@@ -15,32 +16,36 @@ describe('<NonOrphanVisits />', () => {
|
||||
const cancelGetNonOrphanVisits = jest.fn();
|
||||
const nonOrphanVisits = Mock.of<VisitsInfo>({ visits: [Mock.of<Visit>({ date: formatISO(new Date()) })] });
|
||||
const NonOrphanVisits = createNonOrphanVisits(Mock.of<ReportExporter>({ exportVisits }));
|
||||
|
||||
beforeEach(() => render(
|
||||
<MemoryRouter>
|
||||
<NonOrphanVisits
|
||||
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
||||
getNonOrphanVisits={getNonOrphanVisits}
|
||||
cancelGetNonOrphanVisits={cancelGetNonOrphanVisits}
|
||||
nonOrphanVisits={nonOrphanVisits}
|
||||
settings={Mock.all<Settings>()}
|
||||
selectedServer={Mock.all<SelectedServer>()}
|
||||
/>
|
||||
</MemoryRouter>,
|
||||
));
|
||||
const setUp = () => ({
|
||||
user: userEvent.setup(),
|
||||
...render(
|
||||
<MemoryRouter>
|
||||
<NonOrphanVisits
|
||||
{...Mock.of<MercureBoundProps>({ mercureInfo: {} })}
|
||||
getNonOrphanVisits={getNonOrphanVisits}
|
||||
cancelGetNonOrphanVisits={cancelGetNonOrphanVisits}
|
||||
nonOrphanVisits={nonOrphanVisits}
|
||||
settings={Mock.all<Settings>()}
|
||||
selectedServer={Mock.all<SelectedServer>()}
|
||||
/>
|
||||
</MemoryRouter>,
|
||||
),
|
||||
});
|
||||
|
||||
it('wraps visits stats and header', () => {
|
||||
setUp();
|
||||
expect(screen.getByRole('heading', { name: 'Non-orphan visits' })).toBeInTheDocument();
|
||||
expect(getNonOrphanVisits).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('exports visits when clicking the button', () => {
|
||||
it('exports visits when clicking the button', async () => {
|
||||
const { user } = setUp();
|
||||
const btn = screen.getByRole('button', { name: 'Export (1)' });
|
||||
|
||||
expect(exportVisits).not.toHaveBeenCalled();
|
||||
expect(btn).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(btn);
|
||||
await user.click(btn);
|
||||
expect(exportVisits).toHaveBeenCalledWith('non_orphan_visits.csv', expect.anything());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user