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

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-08 15:04:21 +03:00
import React from 'react';
import { shallow } from 'enzyme';
import { BrowserRouter } from 'react-router-dom';
2020-03-15 11:56:16 +03:00
import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError';
2020-03-08 15:04:21 +03:00
describe('<ServerError />', () => {
let wrapper;
2020-03-15 11:56:16 +03:00
const selectedServer = { id: '' };
const ServerError = createServerError(() => '');
2020-03-08 15:04:21 +03:00
afterEach(() => wrapper && wrapper.unmount());
it.each([
[
'not-found',
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
],
[
'not-reachable',
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
],
2020-03-15 11:56:16 +03:00
])('renders expected information for type "%s"', (type, textsToFind) => {
wrapper = shallow(
<BrowserRouter>
2020-04-27 11:49:55 +03:00
<ServerError type={type} servers={{}} selectedServer={selectedServer} />
2020-03-15 11:56:16 +03:00
</BrowserRouter>
);
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
2020-03-15 11:56:16 +03:00
textPairs.forEach(([ text, shouldBeFound ]) => {
if (shouldBeFound) {
expect(wrapperText).toContain(text);
} else {
expect(wrapperText).not.toContain(text);
}
2020-03-08 15:04:21 +03:00
});
});
});