shlink-web-client/test/servers/helpers/ServerError.test.tsx

51 lines
2 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
2023-09-30 11:45:52 +03:00
import type { NonReachableServer, NotFoundServer, SelectedServer } from '../../../src/servers/data';
2023-09-05 10:08:42 +03:00
import { ServerErrorFactory } from '../../../src/servers/helpers/ServerError';
2023-09-30 11:45:52 +03:00
import { checkAccessibility } from '../../__helpers__/accessibility';
2020-03-08 15:04:21 +03:00
describe('<ServerError />', () => {
2023-09-05 10:08:42 +03:00
const ServerError = ServerErrorFactory(fromPartial({ DeleteServerButton: () => null }));
2023-09-30 11:45:52 +03:00
const setUp = (selectedServer: SelectedServer) => render(
<MemoryRouter>
<ServerError servers={{}} selectedServer={selectedServer} />
</MemoryRouter>,
);
it.each([
[fromPartial<NotFoundServer>({})],
[fromPartial<NonReachableServer>({ id: 'abc123' })],
])('passes a11y checks', (selectedServer) => checkAccessibility(setUp(selectedServer)));
2020-03-08 15:04:21 +03:00
it.each([
[
fromPartial<NotFoundServer>({}),
2020-03-15 11:56:16 +03:00
{
found: ['Could not find this Shlink server.'],
notFound: [
'Oops! Could not connect to this Shlink server.',
'Make sure you have internet connection, and the server is properly configured and on-line.',
/^Alternatively, if you think you may have miss-configured this server/,
],
2020-03-15 11:56:16 +03:00
},
2020-03-08 15:04:21 +03:00
],
[
fromPartial<NonReachableServer>({ id: 'abc123' }),
2020-03-15 11:56:16 +03:00
{
found: [
'Oops! Could not connect to this Shlink server.',
'Make sure you have internet connection, and the server is properly configured and on-line.',
/^Alternatively, if you think you may have miss-configured this server/,
],
notFound: ['Could not find this Shlink server.'],
2020-03-15 11:56:16 +03:00
},
2020-03-08 15:04:21 +03:00
],
])('renders expected information based on provided server type', (selectedServer, { found, notFound }) => {
2023-09-30 11:45:52 +03:00
setUp(selectedServer);
2020-03-08 15:04:21 +03:00
found.forEach((text) => expect(screen.getByText(text)).toBeInTheDocument());
notFound.forEach((text) => expect(screen.queryByText(text)).not.toBeInTheDocument());
2020-03-08 15:04:21 +03:00
});
});