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

37 lines
1.2 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
2023-05-27 12:57:26 +03:00
import { MemoryRouter } from 'react-router';
2022-05-28 11:47:39 +03:00
import { AsideMenu as createAsideMenu } from '../../src/common/AsideMenu';
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={fromPartial({ 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
});
});