2022-06-04 10:59:19 +03:00
|
|
|
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';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ServerWithId } from '../../src/servers/data';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { ServersListGroup } from '../../src/servers/ServersListGroup';
|
2020-03-08 13:16:57 +03:00
|
|
|
|
|
|
|
describe('<ServersListGroup />', () => {
|
2020-12-20 14:17:12 +03:00
|
|
|
const servers = [
|
|
|
|
Mock.of<ServerWithId>({ name: 'foo', id: '123' }),
|
|
|
|
Mock.of<ServerWithId>({ name: 'bar', id: '456' }),
|
|
|
|
];
|
2022-06-04 10:59:19 +03:00
|
|
|
const setUp = (params: { servers?: ServerWithId[]; withChildren?: boolean; embedded?: boolean }) => {
|
2020-12-20 14:17:12 +03:00
|
|
|
const { servers = [], withChildren = true, embedded } = params;
|
|
|
|
|
2022-06-04 10:59:19 +03:00
|
|
|
return render(
|
|
|
|
<MemoryRouter>
|
|
|
|
<ServersListGroup servers={servers} embedded={embedded}>
|
|
|
|
{withChildren ? 'The list of servers' : undefined}
|
|
|
|
</ServersListGroup>
|
|
|
|
</MemoryRouter>,
|
2020-12-20 14:17:12 +03:00
|
|
|
);
|
2020-03-08 13:16:57 +03:00
|
|
|
};
|
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
it('renders title', () => {
|
2022-06-04 10:59:19 +03:00
|
|
|
setUp({});
|
|
|
|
expect(screen.getByRole('heading')).toHaveTextContent('The list of servers');
|
2020-03-08 13:16:57 +03:00
|
|
|
});
|
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
it('does not render title when children is not provided', () => {
|
2022-06-04 10:59:19 +03:00
|
|
|
setUp({ withChildren: false });
|
|
|
|
expect(screen.queryByRole('heading')).not.toBeInTheDocument();
|
2020-12-20 14:17:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[servers],
|
2020-12-20 14:17:12 +03:00
|
|
|
[[]],
|
|
|
|
])('shows servers list', (servers) => {
|
2022-06-04 10:59:19 +03:00
|
|
|
setUp({ servers });
|
2020-03-08 13:16:57 +03:00
|
|
|
|
2022-06-04 10:59:19 +03:00
|
|
|
expect(screen.queryAllByRole('list')).toHaveLength(servers.length ? 1 : 0);
|
|
|
|
expect(screen.queryAllByRole('link')).toHaveLength(servers.length);
|
2020-03-08 13:16:57 +03:00
|
|
|
});
|
2020-12-20 14:17:12 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[true, 'servers-list__list-group servers-list__list-group--embedded'],
|
|
|
|
[false, 'servers-list__list-group'],
|
|
|
|
[undefined, 'servers-list__list-group'],
|
2020-12-20 14:17:12 +03:00
|
|
|
])('renders proper classes for embedded', (embedded, expectedClasses) => {
|
2022-06-04 10:59:19 +03:00
|
|
|
setUp({ servers, embedded });
|
|
|
|
expect(screen.getByRole('list')).toHaveAttribute('class', `${expectedClasses} list-group`);
|
2020-12-20 14:17:12 +03:00
|
|
|
});
|
2020-03-08 13:16:57 +03:00
|
|
|
});
|