2022-07-15 23:11:13 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2022-07-15 23:11:13 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-07-24 21:14:59 +03:00
|
|
|
import type { ShortUrl } from '../../../shlink-web-component/short-urls/data';
|
|
|
|
import { ShortUrlsRowMenu as createShortUrlsRowMenu } from '../../../shlink-web-component/short-urls/helpers/ShortUrlsRowMenu';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ReachableServer } from '../../../src/servers/data';
|
2022-07-15 23:11:13 +03:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2019-01-13 15:08:47 +03:00
|
|
|
|
|
|
|
describe('<ShortUrlsRowMenu />', () => {
|
2022-07-15 23:11:13 +03:00
|
|
|
const ShortUrlsRowMenu = createShortUrlsRowMenu(() => <i>DeleteShortUrlModal</i>, () => <i>QrCodeModal</i>);
|
2023-04-13 22:48:29 +03:00
|
|
|
const selectedServer = fromPartial<ReachableServer>({ id: 'abc123' });
|
|
|
|
const shortUrl = fromPartial<ShortUrl>({
|
2019-01-13 15:08:47 +03:00
|
|
|
shortCode: 'abc123',
|
2023-01-18 00:53:49 +03:00
|
|
|
shortUrl: 'https://s.test/abc123',
|
2020-08-30 10:59:14 +03:00
|
|
|
});
|
2022-07-15 23:11:13 +03:00
|
|
|
const setUp = () => renderWithEvents(
|
|
|
|
<MemoryRouter>
|
|
|
|
<ShortUrlsRowMenu selectedServer={selectedServer} shortUrl={shortUrl} />
|
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
2019-01-13 15:08:47 +03:00
|
|
|
|
|
|
|
it('renders modal windows', () => {
|
2022-07-15 23:11:13 +03:00
|
|
|
setUp();
|
2019-01-13 15:08:47 +03:00
|
|
|
|
2022-07-15 23:11:13 +03:00
|
|
|
expect(screen.getByText('DeleteShortUrlModal')).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('QrCodeModal')).toBeInTheDocument();
|
2019-01-13 15:08:47 +03:00
|
|
|
});
|
|
|
|
|
2022-07-15 23:11:13 +03:00
|
|
|
it('renders correct amount of menu items', async () => {
|
|
|
|
const { user } = setUp();
|
2019-01-13 15:08:47 +03:00
|
|
|
|
2022-07-15 23:11:13 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
expect(screen.getAllByRole('menuitem')).toHaveLength(4);
|
2019-01-13 15:08:47 +03:00
|
|
|
});
|
|
|
|
});
|