mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 17:57:26 +03:00
Migrated ShortUrlsRowMenu test to react testing library
This commit is contained in:
parent
6236d36372
commit
90a643761a
1 changed files with 16 additions and 39 deletions
|
@ -1,58 +1,35 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
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 { DropdownBtnMenu } from '../../../src/utils/DropdownBtnMenu';
|
||||
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
||||
|
||||
describe('<ShortUrlsRowMenu />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
const DeleteShortUrlModal = () => null;
|
||||
const QrCodeModal = () => null;
|
||||
const ShortUrlsRowMenu = createShortUrlsRowMenu(() => <i>DeleteShortUrlModal</i>, () => <i>QrCodeModal</i>);
|
||||
const selectedServer = Mock.of<ReachableServer>({ id: 'abc123' });
|
||||
const shortUrl = Mock.of<ShortUrl>({
|
||||
shortCode: 'abc123',
|
||||
shortUrl: 'https://doma.in/abc123',
|
||||
});
|
||||
const createWrapper = () => {
|
||||
const ShortUrlsRowMenu = createShortUrlsRowMenu(DeleteShortUrlModal, QrCodeModal);
|
||||
|
||||
wrapper = shallow(<ShortUrlsRowMenu selectedServer={selectedServer} shortUrl={shortUrl} />);
|
||||
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
afterEach(() => wrapper?.unmount());
|
||||
const setUp = () => renderWithEvents(
|
||||
<MemoryRouter>
|
||||
<ShortUrlsRowMenu selectedServer={selectedServer} shortUrl={shortUrl} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
it('renders modal windows', () => {
|
||||
const wrapper = createWrapper();
|
||||
const deleteShortUrlModal = wrapper.find(DeleteShortUrlModal);
|
||||
const qrCodeModal = wrapper.find(QrCodeModal);
|
||||
setUp();
|
||||
|
||||
expect(deleteShortUrlModal).toHaveLength(1);
|
||||
expect(qrCodeModal).toHaveLength(1);
|
||||
expect(screen.getByText('DeleteShortUrlModal')).toBeInTheDocument();
|
||||
expect(screen.getByText('QrCodeModal')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders correct amount of menu items', () => {
|
||||
const wrapper = createWrapper();
|
||||
const items = wrapper.find(DropdownItem);
|
||||
it('renders correct amount of menu items', async () => {
|
||||
const { user } = setUp();
|
||||
|
||||
expect(items).toHaveLength(5);
|
||||
expect(items.find('[divider]')).toHaveLength(1);
|
||||
});
|
||||
|
||||
describe('toggles state when toggling modals or the dropdown', () => {
|
||||
const assert = (modalComponent: Function) => {
|
||||
const wrapper = createWrapper();
|
||||
|
||||
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(false);
|
||||
(wrapper.find(modalComponent).prop('toggle') as Function)();
|
||||
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(true);
|
||||
};
|
||||
|
||||
it('DeleteShortUrlModal', () => assert(DeleteShortUrlModal));
|
||||
it('QrCodeModal', () => assert(QrCodeModal));
|
||||
it('ShortUrlRowMenu', () => assert(DropdownBtnMenu));
|
||||
await user.click(screen.getByRole('button'));
|
||||
expect(screen.getAllByRole('menuitem')).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue