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

44 lines
1.6 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { Mock } from 'ts-mockery';
2020-03-15 11:56:16 +03:00
import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError';
import { NonReachableServer, NotFoundServer } from '../../../src/servers/data';
2020-03-08 15:04:21 +03:00
describe('<ServerError />', () => {
const ServerError = createServerError(() => null);
2020-03-08 15:04:21 +03:00
it.each([
[
Mock.all<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
],
[
Mock.of<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 }) => {
render(
<MemoryRouter>
<ServerError servers={{}} selectedServer={selectedServer} />
</MemoryRouter>,
2020-03-15 11:56:16 +03:00
);
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
});
});