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

65 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

import { render, screen } from '@testing-library/react';
2023-09-05 10:08:42 +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-09-05 10:08:42 +03:00
import { ManageServersRowFactory } from '../../src/servers/ManageServersRow';
2023-09-30 11:45:52 +03:00
import { checkAccessibility } from '../__helpers__/accessibility';
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
2023-09-30 11:45:52 +03:00
it('passes a11y checks', () => checkAccessibility(setUp()));
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
});
});