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

50 lines
1.8 KiB
TypeScript
Raw Normal View History

import { shallow, ShallowWrapper } from 'enzyme';
2020-03-08 15:04:21 +03:00
import { BrowserRouter } 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 />', () => {
let wrapper: ShallowWrapper;
const ServerError = createServerError(() => null);
2020-03-08 15:04:21 +03:00
afterEach(() => wrapper?.unmount());
2020-03-08 15:04:21 +03:00
it.each([
[
Mock.all<NotFoundServer>(),
2020-03-15 11:56:16 +03:00
{
'Could not find this Shlink server.': true,
'Oops! Could not connect to this Shlink server.': false,
'Make sure you have internet connection, and the server is properly configured and on-line.': false,
'Alternatively, if you think you may have miss-configured this server': false,
},
2020-03-08 15:04:21 +03:00
],
[
Mock.of<NonReachableServer>({ id: 'abc123' }),
2020-03-15 11:56:16 +03:00
{
'Could not find this Shlink server.': false,
'Oops! Could not connect to this Shlink server.': true,
'Make sure you have internet connection, and the server is properly configured and on-line.': true,
'Alternatively, if you think you may have miss-configured this server': true,
},
2020-03-08 15:04:21 +03:00
],
])('renders expected information based on provided server type', (selectedServer, textsToFind) => {
2020-03-15 11:56:16 +03:00
wrapper = shallow(
<BrowserRouter>
<ServerError servers={{}} selectedServer={selectedServer} />
2020-08-22 09:10:31 +03:00
</BrowserRouter>,
2020-03-15 11:56:16 +03:00
);
2020-03-08 15:04:21 +03:00
const wrapperText = wrapper.html();
2020-03-15 11:56:16 +03:00
const textPairs = Object.entries(textsToFind);
2020-03-08 15:04:21 +03:00
2022-03-26 14:17:42 +03:00
textPairs.forEach(([text, shouldBeFound]) => {
2020-03-15 11:56:16 +03:00
if (shouldBeFound) {
expect(wrapperText).toContain(text);
} else {
expect(wrapperText).not.toContain(text);
}
2020-03-08 15:04:21 +03:00
});
});
});