shlink-web-client/test/servers/helpers/ForServerVersion.test.tsx

50 lines
2 KiB
TypeScript
Raw Normal View History

2020-08-29 14:51:53 +03:00
import { mount, ReactWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
import ForServerVersion from '../../../src/servers/helpers/ForServerVersion';
2020-08-29 14:51:53 +03:00
import { ReachableServer, SelectedServer } from '../../../src/servers/data';
import { SemVer, SemVerPattern } from '../../../src/utils/helpers/version';
describe('<ForServerVersion />', () => {
2020-08-29 14:51:53 +03:00
let wrapped: ReactWrapper;
const renderComponent = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => {
wrapped = mount(
<ForServerVersion minVersion={minVersion} maxVersion={maxVersion} selectedServer={selectedServer}>
<span>Hello</span>
2020-08-22 09:10:31 +03:00
</ForServerVersion>,
);
return wrapped;
};
2020-08-29 14:51:53 +03:00
afterEach(() => wrapped?.unmount());
it('does not render children when current server is empty', () => {
const wrapped = renderComponent(null, '1.*.*');
expect(wrapped.html()).toBeNull();
});
it.each([
2022-03-26 14:17:42 +03:00
['2.0.0' as SemVerPattern, undefined, '1.8.3' as SemVer],
[undefined, '1.8.0' as SemVerPattern, '1.8.3' as SemVer],
['1.7.0' as SemVerPattern, '1.8.0' as SemVerPattern, '1.8.3' as SemVer],
])('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);
expect(wrapped.html()).toBeNull();
});
it.each([
2022-03-26 14:17:42 +03:00
['2.0.0' as SemVerPattern, undefined, '2.8.3' as SemVer],
['2.0.0' as SemVerPattern, undefined, '2.0.0' as SemVer],
[undefined, '1.8.0' as SemVerPattern, '1.8.0' as SemVer],
[undefined, '1.8.0' as SemVerPattern, '1.7.1' as SemVer],
['1.7.0' as SemVerPattern, '1.8.0' as SemVerPattern, '1.7.3' as SemVer],
])('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);
expect(wrapped.html()).toContain('<span>Hello</span>');
});
});