mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-08-02 00:51:52 +00:00
Move shlink-web-component tests to their own folder
This commit is contained in:
43
shlink-web-component/test/visits/OrphanVisits.test.tsx
Normal file
43
shlink-web-component/test/visits/OrphanVisits.test.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import { formatISO } from 'date-fns';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import type { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
|
||||
import { OrphanVisits as createOrphanVisits } from '../../src/visits/OrphanVisits';
|
||||
import type { VisitsInfo } from '../../src/visits/reducers/types';
|
||||
import { renderWithEvents } from '../__helpers__/setUpTest';
|
||||
|
||||
describe('<OrphanVisits />', () => {
|
||||
const getOrphanVisits = vi.fn();
|
||||
const exportVisits = vi.fn();
|
||||
const orphanVisits = fromPartial<VisitsInfo>({ visits: [{ date: formatISO(new Date()) }] });
|
||||
const OrphanVisits = createOrphanVisits(fromPartial({ exportVisits }));
|
||||
const setUp = () => renderWithEvents(
|
||||
<MemoryRouter>
|
||||
<OrphanVisits
|
||||
{...fromPartial<MercureBoundProps>({ mercureInfo: {} })}
|
||||
getOrphanVisits={getOrphanVisits}
|
||||
orphanVisits={orphanVisits}
|
||||
cancelGetOrphanVisits={vi.fn()}
|
||||
settings={fromPartial({})}
|
||||
/>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
it('wraps visits stats and header', () => {
|
||||
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)' });
|
||||
|
||||
expect(exportVisits).not.toHaveBeenCalled();
|
||||
expect(btn).toBeInTheDocument();
|
||||
|
||||
await user.click(btn);
|
||||
expect(exportVisits).toHaveBeenCalledWith('orphan_visits.csv', expect.anything());
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user