Moved logic to dynamically render components based on server version to a separated component

This commit is contained in:
Alejandro Celaya
2020-01-28 19:46:36 +01:00
parent 3adcaef455
commit c53520ae56
13 changed files with 135 additions and 131 deletions

View File

@@ -1,7 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { ButtonDropdown, DropdownItem } from 'reactstrap';
import each from 'jest-each';
import createShortUrlsRowMenu from '../../../src/short-urls/helpers/ShortUrlsRowMenu';
import PreviewModal from '../../../src/short-urls/helpers/PreviewModal';
import QrCodeModal from '../../../src/short-urls/helpers/QrCodeModal';
@@ -17,12 +16,12 @@ describe('<ShortUrlsRowMenu />', () => {
shortCode: 'abc123',
shortUrl: 'https://doma.in/abc123',
};
const createWrapper = (serverVersion = '1.21.1') => {
const createWrapper = () => {
const ShortUrlsRowMenu = createShortUrlsRowMenu(DeleteShortUrlModal, EditTagsModal, EditMetaModal);
wrapper = shallow(
<ShortUrlsRowMenu
selectedServer={{ ...selectedServer, version: serverVersion }}
selectedServer={selectedServer}
shortUrl={shortUrl}
onCopyToClipboard={onCopyToClipboard}
/>
@@ -46,24 +45,12 @@ describe('<ShortUrlsRowMenu />', () => {
expect(qrCodeModal).toHaveLength(1);
});
each([
[ '1.17.0', 6, 2 ],
[ '1.17.2', 6, 2 ],
[ '1.18.0', 7, 2 ],
[ '1.18.1', 7, 2 ],
[ '1.19.0', 7, 2 ],
[ '1.20.3', 7, 2 ],
[ '1.21.0', 7, 2 ],
[ '1.21.1', 7, 2 ],
[ '2.0.0', 6, 1 ],
[ '2.0.1', 6, 1 ],
[ '2.1.0', 6, 1 ],
]).it('renders correct amount of menu items depending on the version', (version, expectedNonDividerItems, expectedDividerItems) => {
const wrapper = createWrapper(version);
it('renders correct amount of menu items', () => {
const wrapper = createWrapper();
const items = wrapper.find(DropdownItem);
expect(items).toHaveLength(expectedNonDividerItems + expectedDividerItems);
expect(items.find('[divider]')).toHaveLength(expectedDividerItems);
expect(items).toHaveLength(9);
expect(items.find('[divider]')).toHaveLength(2);
});
describe('toggles state when toggling modal windows', () => {