2019-01-13 15:08:47 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { ButtonDropdown, DropdownItem } from 'reactstrap';
|
2020-01-11 16:12:58 +03:00
|
|
|
import each from 'jest-each';
|
2019-01-13 15:08:47 +03:00
|
|
|
import createShortUrlsRowMenu from '../../../src/short-urls/helpers/ShortUrlsRowMenu';
|
|
|
|
import PreviewModal from '../../../src/short-urls/helpers/PreviewModal';
|
|
|
|
import QrCodeModal from '../../../src/short-urls/helpers/QrCodeModal';
|
|
|
|
|
|
|
|
describe('<ShortUrlsRowMenu />', () => {
|
|
|
|
let wrapper;
|
|
|
|
const DeleteShortUrlModal = () => '';
|
|
|
|
const EditTagsModal = () => '';
|
2019-04-19 13:41:59 +03:00
|
|
|
const onCopyToClipboard = jest.fn();
|
2019-01-13 15:08:47 +03:00
|
|
|
const selectedServer = { id: 'abc123' };
|
|
|
|
const shortUrl = {
|
|
|
|
shortCode: 'abc123',
|
|
|
|
shortUrl: 'https://doma.in/abc123',
|
|
|
|
};
|
2020-01-11 16:12:58 +03:00
|
|
|
const createWrapper = (serverVersion = '1.21.1') => {
|
2019-01-13 15:08:47 +03:00
|
|
|
const ShortUrlsRowMenu = createShortUrlsRowMenu(DeleteShortUrlModal, EditTagsModal);
|
|
|
|
|
|
|
|
wrapper = shallow(
|
2020-01-11 16:12:58 +03:00
|
|
|
<ShortUrlsRowMenu
|
|
|
|
selectedServer={{ ...selectedServer, version: serverVersion }}
|
|
|
|
shortUrl={shortUrl}
|
|
|
|
onCopyToClipboard={onCopyToClipboard}
|
|
|
|
/>
|
2019-01-13 15:08:47 +03:00
|
|
|
);
|
|
|
|
|
2020-01-11 16:12:58 +03:00
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => wrapper && wrapper.unmount());
|
2019-01-13 15:08:47 +03:00
|
|
|
|
|
|
|
it('renders modal windows', () => {
|
2020-01-11 16:12:58 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-01-13 15:08:47 +03:00
|
|
|
const deleteShortUrlModal = wrapper.find(DeleteShortUrlModal);
|
|
|
|
const editTagsModal = wrapper.find(EditTagsModal);
|
|
|
|
const previewModal = wrapper.find(PreviewModal);
|
|
|
|
const qrCodeModal = wrapper.find(QrCodeModal);
|
|
|
|
|
|
|
|
expect(deleteShortUrlModal).toHaveLength(1);
|
|
|
|
expect(editTagsModal).toHaveLength(1);
|
|
|
|
expect(previewModal).toHaveLength(1);
|
|
|
|
expect(qrCodeModal).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-01-11 16:12:58 +03:00
|
|
|
each([
|
|
|
|
[ '1.20.3', 6, 2 ],
|
|
|
|
[ '1.21.0', 6, 2 ],
|
|
|
|
[ '1.21.1', 6, 2 ],
|
|
|
|
[ '2.0.0', 5, 1 ],
|
|
|
|
[ '2.0.1', 5, 1 ],
|
|
|
|
[ '2.1.0', 5, 1 ],
|
|
|
|
]).it('renders correct amount of menu items depending on the version', (version, expectedNonDividerItems, expectedDividerItems) => {
|
|
|
|
const wrapper = createWrapper(version);
|
2019-01-13 15:08:47 +03:00
|
|
|
const items = wrapper.find(DropdownItem);
|
|
|
|
|
|
|
|
expect(items).toHaveLength(expectedNonDividerItems + expectedDividerItems);
|
|
|
|
expect(items.find('[divider]')).toHaveLength(expectedDividerItems);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggles state when toggling modal windows', () => {
|
|
|
|
const assert = (modalComponent, stateProp, done) => {
|
2020-01-11 16:12:58 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-01-13 15:08:47 +03:00
|
|
|
const modal = wrapper.find(modalComponent);
|
|
|
|
|
|
|
|
expect(wrapper.state(stateProp)).toEqual(false);
|
|
|
|
modal.prop('toggle')();
|
|
|
|
setImmediate(() => {
|
|
|
|
expect(wrapper.state(stateProp)).toEqual(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
it('DeleteShortUrlModal', (done) => assert(DeleteShortUrlModal, 'isDeleteModalOpen', done));
|
|
|
|
it('EditTagsModal', (done) => assert(EditTagsModal, 'isTagsModalOpen', done));
|
|
|
|
it('PreviewModal', (done) => assert(PreviewModal, 'isPreviewModalOpen', done));
|
|
|
|
it('QrCodeModal', (done) => assert(QrCodeModal, 'isQrModalOpen', done));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles dropdown state when toggling dropdown', (done) => {
|
2020-01-11 16:12:58 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-01-13 15:08:47 +03:00
|
|
|
const dropdown = wrapper.find(ButtonDropdown);
|
|
|
|
|
|
|
|
expect(wrapper.state('isOpen')).toEqual(false);
|
|
|
|
dropdown.prop('toggle')();
|
|
|
|
setImmediate(() => {
|
|
|
|
expect(wrapper.state('isOpen')).toEqual(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|