shlink-web-client/test/common/AsideMenu.test.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { Mock } from 'ts-mockery';
import { MemoryRouter } from 'react-router-dom';
2018-12-18 00:32:51 +03:00
import asideMenuCreator from '../../src/common/AsideMenu';
2021-08-24 21:26:57 +03:00
import { ReachableServer } from '../../src/servers/data';
import { SemVer } from '../../src/utils/helpers/version';
2018-08-12 09:49:08 +03:00
describe('<AsideMenu />', () => {
const AsideMenu = asideMenuCreator(() => <>DeleteServerButton</>);
const setUp = (version: SemVer, id: string | false = 'abc123') => render(
<MemoryRouter>
<AsideMenu selectedServer={Mock.of<ReachableServer>({ id: id || undefined, version })} />
</MemoryRouter>,
);
2018-12-18 00:32:51 +03:00
it.each([
['2.7.0' as SemVer, 5],
['2.8.0' as SemVer, 6],
])('contains links to different sections', (version, expectedAmountOfLinks) => {
setUp(version);
2018-08-12 09:49:08 +03:00
const links = screen.getAllByRole('link');
2018-08-12 09:49:08 +03:00
expect.assertions(links.length + 1);
expect(links).toHaveLength(expectedAmountOfLinks);
links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123'));
2018-08-12 09:49:08 +03:00
});
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();
}
2018-08-12 09:49:08 +03:00
});
});