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

38 lines
1.2 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
2023-02-18 13:11:01 +03:00
import { Mock } from 'ts-mockery';
2022-05-28 11:47:39 +03:00
import { AsideMenu as createAsideMenu } from '../../src/common/AsideMenu';
2023-02-18 12:40:37 +03:00
import type { ReachableServer } from '../../src/servers/data';
2018-08-12 09:49:08 +03:00
describe('<AsideMenu />', () => {
2022-05-28 11:47:39 +03:00
const AsideMenu = createAsideMenu(() => <>DeleteServerButton</>);
const setUp = (id: string | false = 'abc123') => render(
<MemoryRouter>
<AsideMenu selectedServer={Mock.of<ReachableServer>({ id: id || undefined, version: '2.8.0' })} />
</MemoryRouter>,
);
2018-12-18 00:32:51 +03:00
it('contains links to different sections', () => {
setUp();
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(6);
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(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
});
});