2022-05-03 19:03:14 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2020-08-29 10:19:15 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-03 19:03:14 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2022-05-28 11:47:39 +03:00
|
|
|
import { AsideMenu as createAsideMenu } from '../../src/common/AsideMenu';
|
2021-08-24 21:26:57 +03:00
|
|
|
import { ReachableServer } from '../../src/servers/data';
|
2022-02-08 00:17:57 +03:00
|
|
|
|
2018-08-12 09:49:08 +03:00
|
|
|
describe('<AsideMenu />', () => {
|
2022-05-28 11:47:39 +03:00
|
|
|
const AsideMenu = createAsideMenu(() => <>DeleteServerButton</>);
|
2022-12-23 22:42:47 +03:00
|
|
|
const setUp = (id: string | false = 'abc123') => render(
|
2022-05-03 19:03:14 +03:00
|
|
|
<MemoryRouter>
|
2022-12-23 22:42:47 +03:00
|
|
|
<AsideMenu selectedServer={Mock.of<ReachableServer>({ id: id || undefined, version: '2.8.0' })} />
|
2022-05-03 19:03:14 +03:00
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
2018-12-18 00:32:51 +03:00
|
|
|
|
2022-12-23 22:42:47 +03:00
|
|
|
it('contains links to different sections', () => {
|
|
|
|
setUp();
|
2018-08-12 09:49:08 +03:00
|
|
|
|
2022-05-03 19:03:14 +03:00
|
|
|
const links = screen.getAllByRole('link');
|
2018-08-12 09:49:08 +03:00
|
|
|
|
2022-05-03 19:03:14 +03:00
|
|
|
expect.assertions(links.length + 1);
|
2022-12-23 22:42:47 +03:00
|
|
|
expect(links).toHaveLength(6);
|
2022-05-03 19:03:14 +03:00
|
|
|
links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123'));
|
2018-08-12 09:49:08 +03:00
|
|
|
});
|
|
|
|
|
2022-05-03 19:03:14 +03:00
|
|
|
it.each([
|
|
|
|
['abc', true],
|
|
|
|
[false, false],
|
|
|
|
])('contains a button to delete server if appropriate', (id, shouldHaveBtn) => {
|
2022-12-23 22:42:47 +03:00
|
|
|
setUp(id as string | false);
|
2022-05-03 19:03:14 +03:00
|
|
|
|
|
|
|
if (shouldHaveBtn) {
|
|
|
|
expect(screen.getByText('DeleteServerButton')).toBeInTheDocument();
|
|
|
|
} else {
|
|
|
|
expect(screen.queryByText('DeleteServerButton')).not.toBeInTheDocument();
|
|
|
|
}
|
2018-08-12 09:49:08 +03:00
|
|
|
});
|
|
|
|
});
|