shlink-web-client/test/common/AsideMenu.test.tsx
2022-02-07 22:17:57 +01:00

32 lines
1,018 B
TypeScript

import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
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: '' }),
}));
describe('<AsideMenu />', () => {
let wrapped: ShallowWrapper;
const DeleteServerButton = () => null;
beforeEach(() => {
const AsideMenu = asideMenuCreator(DeleteServerButton);
wrapped = shallow(<AsideMenu selectedServer={Mock.of<ReachableServer>({ id: 'abc123' })} />);
});
afterEach(() => wrapped.unmount());
it('contains links to different sections', () => {
const links = wrapped.find('[to]');
expect(links).toHaveLength(5);
links.forEach((link) => expect(link.prop('to')).toContain('abc123'));
});
it('contains a button to delete server', () => {
expect(wrapped.find(DeleteServerButton)).toHaveLength(1);
});
});