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

74 lines
2.5 KiB
TypeScript
Raw Normal View History

import { shallow, ShallowWrapper } from 'enzyme';
2019-01-13 15:08:47 +03:00
import { ButtonDropdown, DropdownItem } from 'reactstrap';
import { Mock } from 'ts-mockery';
2019-01-13 15:08:47 +03:00
import createShortUrlsRowMenu from '../../../src/short-urls/helpers/ShortUrlsRowMenu';
import { ReachableServer } from '../../../src/servers/data';
import { ShortUrl } from '../../../src/short-urls/data';
2019-01-13 15:08:47 +03:00
describe('<ShortUrlsRowMenu />', () => {
let wrapper: ShallowWrapper;
const DeleteShortUrlModal = () => null;
const EditTagsModal = () => null;
const EditMetaModal = () => null;
const EditShortUrlModal = () => null;
const QrCodeModal = () => null;
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 createWrapper = () => {
2020-03-30 21:50:31 +03:00
const ShortUrlsRowMenu = createShortUrlsRowMenu(
DeleteShortUrlModal,
EditTagsModal,
EditMetaModal,
EditShortUrlModal,
QrCodeModal,
() => null,
2020-03-30 21:50:31 +03:00
);
2019-01-13 15:08:47 +03:00
wrapper = shallow(<ShortUrlsRowMenu selectedServer={selectedServer} shortUrl={shortUrl} />);
2019-01-13 15:08:47 +03:00
return wrapper;
};
afterEach(() => wrapper?.unmount());
2019-01-13 15:08:47 +03:00
it('renders modal windows', () => {
const wrapper = createWrapper();
2019-01-13 15:08:47 +03:00
const deleteShortUrlModal = wrapper.find(DeleteShortUrlModal);
const editTagsModal = wrapper.find(EditTagsModal);
const qrCodeModal = wrapper.find(QrCodeModal);
2020-03-30 21:50:31 +03:00
const editModal = wrapper.find(EditShortUrlModal);
2019-01-13 15:08:47 +03:00
expect(deleteShortUrlModal).toHaveLength(1);
expect(editTagsModal).toHaveLength(1);
expect(qrCodeModal).toHaveLength(1);
2020-03-30 21:50:31 +03:00
expect(editModal).toHaveLength(1);
2019-01-13 15:08:47 +03:00
});
it('renders correct amount of menu items', () => {
const wrapper = createWrapper();
2019-01-13 15:08:47 +03:00
const items = wrapper.find(DropdownItem);
2020-12-12 15:33:21 +03:00
expect(items).toHaveLength(7);
expect(items.find('[divider]')).toHaveLength(1);
2019-01-13 15:08:47 +03:00
});
describe('toggles state when toggling modals or the dropdown', () => {
const assert = (modalComponent: Function) => {
const wrapper = createWrapper();
2019-01-13 15:08:47 +03:00
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(false);
(wrapper.find(modalComponent).prop('toggle') as Function)();
expect(wrapper.find(modalComponent).prop('isOpen')).toEqual(true);
2019-01-13 15:08:47 +03:00
};
it('DeleteShortUrlModal', () => assert(DeleteShortUrlModal));
it('EditTagsModal', () => assert(EditTagsModal));
it('QrCodeModal', () => assert(QrCodeModal));
it('EditShortUrlModal', () => assert(EditShortUrlModal));
it('EditShortUrlModal', () => assert(ButtonDropdown));
2019-01-13 15:08:47 +03:00
});
});