2020-08-29 14:51:53 +03:00
|
|
|
import { mount, ReactWrapper } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
2020-01-28 21:46:36 +03:00
|
|
|
import ForServerVersion from '../../../src/servers/helpers/ForServerVersion';
|
2020-08-29 14:51:53 +03:00
|
|
|
import { ReachableServer, SelectedServer } from '../../../src/servers/data';
|
2021-03-06 11:38:48 +03:00
|
|
|
import { SemVer, SemVerPattern } from '../../../src/utils/helpers/version';
|
2020-01-28 21:46:36 +03:00
|
|
|
|
|
|
|
describe('<ForServerVersion />', () => {
|
2020-08-29 14:51:53 +03:00
|
|
|
let wrapped: ReactWrapper;
|
2020-01-28 21:46:36 +03:00
|
|
|
|
2021-03-06 11:38:48 +03:00
|
|
|
const renderComponent = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => {
|
2020-01-28 21:46:36 +03:00
|
|
|
wrapped = mount(
|
|
|
|
<ForServerVersion minVersion={minVersion} maxVersion={maxVersion} selectedServer={selectedServer}>
|
|
|
|
<span>Hello</span>
|
2020-08-22 09:10:31 +03:00
|
|
|
</ForServerVersion>,
|
2020-01-28 21:46:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
return wrapped;
|
|
|
|
};
|
|
|
|
|
2020-08-29 14:51:53 +03:00
|
|
|
afterEach(() => wrapped?.unmount());
|
2020-01-28 21:46:36 +03:00
|
|
|
|
|
|
|
it('does not render children when current server is empty', () => {
|
2021-03-06 11:38:48 +03:00
|
|
|
const wrapped = renderComponent(null, '1.*.*');
|
2020-01-28 21:46:36 +03:00
|
|
|
|
|
|
|
expect(wrapped.html()).toBeNull();
|
|
|
|
});
|
|
|
|
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([
|
2021-03-06 11:38:48 +03:00
|
|
|
[ '2.0.0' as SemVer, undefined, '1.8.3' as SemVer ],
|
|
|
|
[ undefined, '1.8.0' as SemVer, '1.8.3' as SemVer ],
|
|
|
|
[ '1.7.0' as SemVer, '1.8.0' as SemVer, '1.8.3' as SemVer ],
|
2020-02-17 20:21:52 +03:00
|
|
|
])('does not render children when current version does not match requirements', (min, max, version) => {
|
2020-08-29 14:51:53 +03:00
|
|
|
const wrapped = renderComponent(Mock.of<ReachableServer>({ version, printableVersion: version }), min, max);
|
2020-01-28 21:46:36 +03:00
|
|
|
|
|
|
|
expect(wrapped.html()).toBeNull();
|
|
|
|
});
|
|
|
|
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([
|
2021-03-06 11:38:48 +03:00
|
|
|
[ '2.0.0' as SemVer, undefined, '2.8.3' as SemVer ],
|
|
|
|
[ '2.0.0' as SemVer, undefined, '2.0.0' as SemVer ],
|
|
|
|
[ undefined, '1.8.0' as SemVer, '1.8.0' as SemVer ],
|
|
|
|
[ undefined, '1.8.0' as SemVer, '1.7.1' as SemVer ],
|
|
|
|
[ '1.7.0' as SemVer, '1.8.0' as SemVer, '1.7.3' as SemVer ],
|
2020-02-17 20:21:52 +03:00
|
|
|
])('renders children when current version matches requirements', (min, max, version) => {
|
2020-08-29 14:51:53 +03:00
|
|
|
const wrapped = renderComponent(Mock.of<ReachableServer>({ version, printableVersion: version }), min, max);
|
2020-01-28 21:46:36 +03:00
|
|
|
|
|
|
|
expect(wrapped.html()).toContain('<span>Hello</span>');
|
|
|
|
});
|
|
|
|
});
|