mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Migrated ForServerVersion test from enzyme to react testing library
This commit is contained in:
parent
c00aaa9018
commit
0de8eb1568
3 changed files with 17 additions and 28 deletions
|
@ -8,7 +8,9 @@ interface ForServerVersionConnectProps extends ForServerVersionProps {
|
|||
selectedServer: SelectedServer;
|
||||
}
|
||||
|
||||
const ForServerVersion: FC<ForServerVersionConnectProps> = ({ minVersion, maxVersion, selectedServer, children }) => {
|
||||
export const ForServerVersion: FC<ForServerVersionConnectProps> = (
|
||||
{ minVersion, maxVersion, selectedServer, children },
|
||||
) => {
|
||||
if (!isReachableServer(selectedServer)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -22,5 +24,3 @@ const ForServerVersion: FC<ForServerVersionConnectProps> = ({ minVersion, maxVer
|
|||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default ForServerVersion;
|
||||
|
|
|
@ -8,7 +8,7 @@ import ImportServersBtn from '../helpers/ImportServersBtn';
|
|||
import { resetSelectedServer, selectServer } from '../reducers/selectedServer';
|
||||
import { createServer, createServers, deleteServer, editServer, setAutoConnect } from '../reducers/servers';
|
||||
import { fetchServers } from '../reducers/remoteServers';
|
||||
import ForServerVersion from '../helpers/ForServerVersion';
|
||||
import { ForServerVersion } from '../helpers/ForServerVersion';
|
||||
import { ServerError } from '../helpers/ServerError';
|
||||
import { ConnectDecorator } from '../../container/types';
|
||||
import { withoutSelectedServer } from '../helpers/withoutSelectedServer';
|
||||
|
|
|
@ -1,28 +1,19 @@
|
|||
import { mount, ReactWrapper } from 'enzyme';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import ForServerVersion from '../../../src/servers/helpers/ForServerVersion';
|
||||
import { ForServerVersion } from '../../../src/servers/helpers/ForServerVersion';
|
||||
import { ReachableServer, SelectedServer } from '../../../src/servers/data';
|
||||
import { SemVer, SemVerPattern } from '../../../src/utils/helpers/version';
|
||||
|
||||
describe('<ForServerVersion />', () => {
|
||||
let wrapped: ReactWrapper;
|
||||
|
||||
const renderComponent = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => {
|
||||
wrapped = mount(
|
||||
const setUp = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => render(
|
||||
<ForServerVersion minVersion={minVersion} maxVersion={maxVersion} selectedServer={selectedServer}>
|
||||
<span>Hello</span>
|
||||
</ForServerVersion>,
|
||||
);
|
||||
|
||||
return wrapped;
|
||||
};
|
||||
|
||||
afterEach(() => wrapped?.unmount());
|
||||
|
||||
it('does not render children when current server is empty', () => {
|
||||
const wrapped = renderComponent(null, '1.*.*');
|
||||
|
||||
expect(wrapped.html()).toBeNull();
|
||||
setUp(null, '1.*.*');
|
||||
expect(screen.queryByText('Hello')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
@ -30,9 +21,8 @@ describe('<ForServerVersion />', () => {
|
|||
[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) => {
|
||||
const wrapped = renderComponent(Mock.of<ReachableServer>({ version, printableVersion: version }), min, max);
|
||||
|
||||
expect(wrapped.html()).toBeNull();
|
||||
setUp(Mock.of<ReachableServer>({ version, printableVersion: version }), min, max);
|
||||
expect(screen.queryByText('Hello')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
@ -42,8 +32,7 @@ describe('<ForServerVersion />', () => {
|
|||
[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) => {
|
||||
const wrapped = renderComponent(Mock.of<ReachableServer>({ version, printableVersion: version }), min, max);
|
||||
|
||||
expect(wrapped.html()).toContain('<span>Hello</span>');
|
||||
setUp(Mock.of<ReachableServer>({ version, printableVersion: version }), min, max);
|
||||
expect(screen.queryByText('Hello')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue