shlink-web-client/test/servers/ManageServersRow.test.tsx

59 lines
1.7 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
2023-02-18 12:40:37 +03:00
import type { ServerWithId } from '../../src/servers/data';
2023-02-18 13:11:01 +03:00
import { ManageServersRow as createManageServersRow } from '../../src/servers/ManageServersRow';
2021-10-23 11:34:20 +03:00
describe('<ManageServersRow />', () => {
const ManageServersRow = createManageServersRow(() => <span>ManageServersRowDropdown</span>);
2021-10-23 11:34:20 +03:00
const server: ServerWithId = {
name: 'My server',
url: 'https://example.com',
apiKey: '123',
id: 'abc',
};
const setUp = (hasAutoConnect = false, autoConnect = false) => render(
<MemoryRouter>
<table>
<tbody>
<ManageServersRow server={{ ...server, autoConnect }} hasAutoConnect={hasAutoConnect} />
</tbody>
</table>
</MemoryRouter>,
);
2021-10-23 11:34:20 +03:00
it.each([
2022-03-26 14:17:42 +03:00
[true, 4],
[false, 3],
2021-10-23 11:34:20 +03:00
])('renders expected amount of columns', (hasAutoConnect, expectedCols) => {
setUp(hasAutoConnect);
const td = screen.getAllByRole('cell');
const th = screen.getAllByRole('columnheader');
2021-10-23 11:34:20 +03:00
expect(td.length + th.length).toEqual(expectedCols);
});
it('renders a dropdown', () => {
setUp();
expect(screen.getByText('ManageServersRowDropdown')).toBeInTheDocument();
2021-10-23 11:34:20 +03:00
});
it.each([
[true],
[false],
])('renders auto-connect icon only if server is autoConnect', (autoConnect) => {
const { container } = setUp(true, autoConnect);
expect(container).toMatchSnapshot();
2021-10-23 11:34:20 +03:00
});
it('renders server props where appropriate', () => {
setUp();
const link = screen.getByRole('link');
2021-10-23 11:34:20 +03:00
expect(link).toHaveAttribute('href', `/server/${server.id}`);
expect(link).toHaveTextContent(server.name);
expect(screen.getByText(server.url)).toBeInTheDocument();
2021-10-23 11:34:20 +03:00
});
});