2020-08-29 11:53:02 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2020-03-08 15:04:21 +03:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2020-08-29 11:53:02 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2020-03-15 11:56:16 +03:00
|
|
|
import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError';
|
2020-08-29 11:53:02 +03:00
|
|
|
import { NonReachableServer, NotFoundServer } from '../../../src/servers/data';
|
2020-03-08 15:04:21 +03:00
|
|
|
|
|
|
|
describe('<ServerError />', () => {
|
2020-08-29 11:53:02 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const ServerError = createServerError(() => null);
|
2020-03-08 15:04:21 +03:00
|
|
|
|
2020-08-29 11:53:02 +03:00
|
|
|
afterEach(() => wrapper?.unmount());
|
2020-03-08 15:04:21 +03:00
|
|
|
|
|
|
|
it.each([
|
|
|
|
[
|
2020-08-29 11:53:02 +03:00
|
|
|
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
|
|
|
],
|
|
|
|
[
|
2020-08-29 11:53:02 +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
|
|
|
],
|
2020-08-29 11:53:02 +03:00
|
|
|
])('renders expected information based on provided server type', (selectedServer, textsToFind) => {
|
2020-03-15 11:56:16 +03:00
|
|
|
wrapper = shallow(
|
|
|
|
<BrowserRouter>
|
2020-08-29 11:53:02 +03:00
|
|
|
<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
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|