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

62 lines
1.8 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
2023-09-05 10:08:42 +03:00
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
2023-02-18 12:40:37 +03:00
import type { ServerWithId } from '../../src/servers/data';
2023-09-05 10:08:42 +03:00
import { ManageServersRowFactory } from '../../src/servers/ManageServersRow';
2021-10-23 11:34:20 +03:00
describe('<ManageServersRow />', () => {
2023-09-05 10:08:42 +03:00
const ManageServersRow = ManageServersRowFactory(fromPartial({
ManageServersRowDropdown: () => <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
});
});