shlink-web-client/test/short-urls/helpers/ShortUrlsRowMenu.test.tsx

36 lines
1.3 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/react';
import { Mock } from 'ts-mockery';
import { MemoryRouter } from 'react-router-dom';
import { ShortUrlsRowMenu as createShortUrlsRowMenu } from '../../../src/short-urls/helpers/ShortUrlsRowMenu';
import { ReachableServer } from '../../../src/servers/data';
import { ShortUrl } from '../../../src/short-urls/data';
import { renderWithEvents } from '../../__helpers__/setUpTest';
2019-01-13 15:08:47 +03:00
describe('<ShortUrlsRowMenu />', () => {
const ShortUrlsRowMenu = createShortUrlsRowMenu(() => <i>DeleteShortUrlModal</i>, () => <i>QrCodeModal</i>);
const selectedServer = Mock.of<ReachableServer>({ id: 'abc123' });
const shortUrl = Mock.of<ShortUrl>({
2019-01-13 15:08:47 +03:00
shortCode: 'abc123',
shortUrl: 'https://doma.in/abc123',
});
const setUp = () => renderWithEvents(
<MemoryRouter>
<ShortUrlsRowMenu selectedServer={selectedServer} shortUrl={shortUrl} />
</MemoryRouter>,
);
2019-01-13 15:08:47 +03:00
it('renders modal windows', () => {
setUp();
2019-01-13 15:08:47 +03:00
expect(screen.getByText('DeleteShortUrlModal')).toBeInTheDocument();
expect(screen.getByText('QrCodeModal')).toBeInTheDocument();
2019-01-13 15:08:47 +03:00
});
it('renders correct amount of menu items', async () => {
const { user } = setUp();
2019-01-13 15:08:47 +03:00
await user.click(screen.getByRole('button'));
expect(screen.getAllByRole('menuitem')).toHaveLength(4);
2019-01-13 15:08:47 +03:00
});
});