2022-06-04 20:13:00 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2022-06-04 20:13:00 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { NonReachableServer, NotFoundServer } from '../../../src/servers/data';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError';
|
2020-03-08 15:04:21 +03:00
|
|
|
|
|
|
|
describe('<ServerError />', () => {
|
2020-08-29 11:53:02 +03:00
|
|
|
const ServerError = createServerError(() => null);
|
2020-03-08 15:04:21 +03:00
|
|
|
|
|
|
|
it.each([
|
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<NotFoundServer>({}),
|
2020-03-15 11:56:16 +03:00
|
|
|
{
|
2022-06-04 20:13:00 +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
|
|
|
],
|
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<NonReachableServer>({ id: 'abc123' }),
|
2020-03-15 11:56:16 +03:00
|
|
|
{
|
2022-06-04 20:13:00 +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
|
|
|
],
|
2022-06-04 20:13:00 +03:00
|
|
|
])('renders expected information based on provided server type', (selectedServer, { found, notFound }) => {
|
|
|
|
render(
|
|
|
|
<MemoryRouter>
|
2020-08-29 11:53:02 +03:00
|
|
|
<ServerError servers={{}} selectedServer={selectedServer} />
|
2022-06-04 20:13:00 +03:00
|
|
|
</MemoryRouter>,
|
2020-03-15 11:56:16 +03:00
|
|
|
);
|
2020-03-08 15:04:21 +03:00
|
|
|
|
2022-06-04 20:13:00 +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
|
|
|
});
|
|
|
|
});
|