2022-06-04 10:59:19 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2024-12-09 13:52:58 +03:00
|
|
|
import { MemoryRouter } from 'react-router';
|
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';
|
2023-09-30 11:45:52 +03:00
|
|
|
import { checkAccessibility } from '../__helpers__/accessibility';
|
2020-03-08 13:16:57 +03:00
|
|
|
|
|
|
|
describe('<ServersListGroup />', () => {
|
2023-04-13 22:48:29 +03:00
|
|
|
const servers: ServerWithId[] = [
|
|
|
|
fromPartial({ name: 'foo', id: '123' }),
|
|
|
|
fromPartial({ name: 'bar', id: '456' }),
|
2020-12-20 14:17:12 +03:00
|
|
|
];
|
2023-09-30 11:45:52 +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
|
|
|
};
|
|
|
|
|
2023-09-30 11:45:52 +03:00
|
|
|
it('passes a11y checks', () => checkAccessibility(setUp()));
|
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
it('renders title', () => {
|
2022-06-04 10:59:19 +03:00
|
|
|
setUp({});
|
2023-09-30 11:45:52 +03:00
|
|
|
expect(screen.getByTestId('title')).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 });
|
2023-09-30 11:45:52 +03:00
|
|
|
expect(screen.queryByTestId('title')).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
|
|
|
|
2023-09-30 11:45:52 +03:00
|
|
|
expect(screen.queryAllByTestId('list')).toHaveLength(servers.length ? 1 : 0);
|
2022-06-04 10:59:19 +03:00
|
|
|
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 });
|
2023-09-30 11:45:52 +03:00
|
|
|
expect(screen.getByTestId('list')).toHaveAttribute('class', `${expectedClasses} list-group`);
|
2020-12-20 14:17:12 +03:00
|
|
|
});
|
2020-03-08 13:16:57 +03:00
|
|
|
});
|