2022-07-09 23:03:21 +02:00
|
|
|
import { screen } from '@testing-library/react';
|
2020-08-29 20:20:45 +02:00
|
|
|
import { values } from 'ramda';
|
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-17 22:31:02 +02:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
|
|
import { ServersDropdown } from '../../src/servers/ServersDropdown';
|
|
|
|
import { ServersMap, ServerWithId } from '../../src/servers/data';
|
2022-07-10 19:44:49 +02:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2018-06-14 19:42:42 +02:00
|
|
|
|
2018-07-22 22:49:51 +02:00
|
|
|
describe('<ServersDropdown />', () => {
|
2022-05-17 22:31:02 +02:00
|
|
|
const fallbackServers: ServersMap = {
|
2020-08-29 20:20:45 +02:00
|
|
|
'1a': Mock.of<ServerWithId>({ name: 'foo', id: '1a' }),
|
|
|
|
'2b': Mock.of<ServerWithId>({ name: 'bar', id: '2b' }),
|
|
|
|
'3c': Mock.of<ServerWithId>({ name: 'baz', id: '3c' }),
|
2019-10-05 19:51:50 +02:00
|
|
|
};
|
2022-07-09 23:03:21 +02:00
|
|
|
const setUp = (servers: ServersMap = fallbackServers) => renderWithEvents(
|
|
|
|
<MemoryRouter><ServersDropdown servers={servers} selectedServer={null} /></MemoryRouter>,
|
|
|
|
);
|
2018-06-14 19:42:42 +02:00
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
it('contains the list of servers and the "mange servers" button', async () => {
|
|
|
|
const { user } = setUp();
|
|
|
|
|
|
|
|
await user.click(screen.getByText('Servers'));
|
|
|
|
const items = screen.getAllByRole('menuitem');
|
|
|
|
expect(items).toHaveLength(values(fallbackServers).length + 1);
|
|
|
|
expect(items[0]).toHaveTextContent('foo');
|
|
|
|
expect(items[1]).toHaveTextContent('bar');
|
|
|
|
expect(items[2]).toHaveTextContent('baz');
|
|
|
|
expect(items[3]).toHaveTextContent('Manage servers');
|
|
|
|
});
|
2018-08-20 16:53:48 +02:00
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
it('contains a toggle with proper text', () => {
|
|
|
|
setUp();
|
|
|
|
expect(screen.getByRole('link')).toHaveTextContent('Servers');
|
|
|
|
});
|
2018-08-20 16:53:48 +02:00
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
it('contains a button to manage servers', async () => {
|
|
|
|
const { user } = setUp();
|
2018-08-25 23:39:27 +02:00
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
await user.click(screen.getByText('Servers'));
|
|
|
|
expect(screen.getByRole('menuitem', { name: 'Manage servers' })).toHaveAttribute('href', '/manage-servers');
|
2018-06-14 19:42:42 +02:00
|
|
|
});
|
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
it('shows only create link when no servers exist yet', async () => {
|
|
|
|
const { user } = setUp({});
|
2018-08-20 16:53:48 +02:00
|
|
|
|
2022-05-17 22:31:02 +02:00
|
|
|
await user.click(screen.getByText('Servers'));
|
|
|
|
expect(screen.getByRole('menuitem')).toHaveTextContent('Add a server');
|
2018-06-14 19:42:42 +02:00
|
|
|
});
|
|
|
|
});
|