diff --git a/src/servers/helpers/ForServerVersion.tsx b/src/servers/helpers/ForServerVersion.tsx index abda57f2..f7c8534c 100644 --- a/src/servers/helpers/ForServerVersion.tsx +++ b/src/servers/helpers/ForServerVersion.tsx @@ -8,7 +8,9 @@ interface ForServerVersionConnectProps extends ForServerVersionProps { selectedServer: SelectedServer; } -const ForServerVersion: FC = ({ minVersion, maxVersion, selectedServer, children }) => { +export const ForServerVersion: FC = ( + { minVersion, maxVersion, selectedServer, children }, +) => { if (!isReachableServer(selectedServer)) { return null; } @@ -22,5 +24,3 @@ const ForServerVersion: FC = ({ minVersion, maxVer return <>{children}; }; - -export default ForServerVersion; diff --git a/src/servers/services/provideServices.ts b/src/servers/services/provideServices.ts index a4cbd9db..52c114ec 100644 --- a/src/servers/services/provideServices.ts +++ b/src/servers/services/provideServices.ts @@ -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'; diff --git a/test/servers/helpers/ForServerVersion.test.tsx b/test/servers/helpers/ForServerVersion.test.tsx index 2df01db2..d8865544 100644 --- a/test/servers/helpers/ForServerVersion.test.tsx +++ b/test/servers/helpers/ForServerVersion.test.tsx @@ -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('', () => { - let wrapped: ReactWrapper; - - const renderComponent = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => { - wrapped = mount( - - Hello - , - ); - - return wrapped; - }; - - afterEach(() => wrapped?.unmount()); + const setUp = (selectedServer: SelectedServer, minVersion?: SemVerPattern, maxVersion?: SemVerPattern) => render( + + Hello + , + ); 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('', () => { [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({ version, printableVersion: version }), min, max); - - expect(wrapped.html()).toBeNull(); + setUp(Mock.of({ version, printableVersion: version }), min, max); + expect(screen.queryByText('Hello')).not.toBeInTheDocument(); }); it.each([ @@ -42,8 +32,7 @@ describe('', () => { [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({ version, printableVersion: version }), min, max); - - expect(wrapped.html()).toContain('Hello'); + setUp(Mock.of({ version, printableVersion: version }), min, max); + expect(screen.queryByText('Hello')).toBeInTheDocument(); }); });