diff --git a/test/common/AsideMenu.test.tsx b/test/common/AsideMenu.test.tsx index 01ad26b1..6ebc0a31 100644 --- a/test/common/AsideMenu.test.tsx +++ b/test/common/AsideMenu.test.tsx @@ -1,32 +1,41 @@ -import { shallow, ShallowWrapper } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import { Mock } from 'ts-mockery'; +import { MemoryRouter } from 'react-router-dom'; import asideMenuCreator from '../../src/common/AsideMenu'; import { ReachableServer } from '../../src/servers/data'; - -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useLocation: jest.fn().mockReturnValue({ pathname: '' }), -})); +import { SemVer } from '../../src/utils/helpers/version'; describe('', () => { - let wrapped: ShallowWrapper; - const DeleteServerButton = () => null; + const AsideMenu = asideMenuCreator(() => <>DeleteServerButton); + const setUp = (version: SemVer, id: string | false = 'abc123') => render( + + ({ id: id || undefined, version })} /> + , + ); - beforeEach(() => { - const AsideMenu = asideMenuCreator(DeleteServerButton); + it.each([ + ['2.7.0' as SemVer, 5], + ['2.8.0' as SemVer, 6], + ])('contains links to different sections', (version, expectedAmountOfLinks) => { + setUp(version); - wrapped = shallow(({ id: 'abc123' })} />); - }); - afterEach(() => wrapped.unmount()); + const links = screen.getAllByRole('link'); - it('contains links to different sections', () => { - const links = wrapped.find('[to]'); - - expect(links).toHaveLength(5); - links.forEach((link) => expect(link.prop('to')).toContain('abc123')); + expect.assertions(links.length + 1); + expect(links).toHaveLength(expectedAmountOfLinks); + links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123')); }); - it('contains a button to delete server', () => { - expect(wrapped.find(DeleteServerButton)).toHaveLength(1); + it.each([ + ['abc', true], + [false, false], + ])('contains a button to delete server if appropriate', (id, shouldHaveBtn) => { + setUp('2.8.0', id as string | false); + + if (shouldHaveBtn) { + expect(screen.getByText('DeleteServerButton')).toBeInTheDocument(); + } else { + expect(screen.queryByText('DeleteServerButton')).not.toBeInTheDocument(); + } }); });