1
|
|
|
import React from 'react'; |
2
|
|
|
import { shallow } from 'enzyme'; |
3
|
|
|
import { BrowserRouter } from 'react-router-dom'; |
4
|
|
|
import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError'; |
5
|
|
|
|
6
|
|
|
describe('<ServerError />', () => { |
7
|
|
|
let wrapper; |
8
|
|
|
const selectedServer = { id: '' }; |
9
|
|
|
const ServerError = createServerError(() => ''); |
10
|
|
|
|
11
|
|
|
afterEach(() => wrapper && wrapper.unmount()); |
12
|
|
|
|
13
|
|
|
it.each([ |
14
|
|
|
[ |
15
|
|
|
'not-found', |
16
|
|
|
{ |
17
|
|
|
'Could not find this Shlink server.': true, |
18
|
|
|
'Oops! Could not connect to this Shlink server.': false, |
19
|
|
|
'Make sure you have internet connection, and the server is properly configured and on-line.': false, |
20
|
|
|
'Alternatively, if you think you may have miss-configured this server': false, |
21
|
|
|
}, |
22
|
|
|
], |
23
|
|
|
[ |
24
|
|
|
'not-reachable', |
25
|
|
|
{ |
26
|
|
|
'Could not find this Shlink server.': false, |
27
|
|
|
'Oops! Could not connect to this Shlink server.': true, |
28
|
|
|
'Make sure you have internet connection, and the server is properly configured and on-line.': true, |
29
|
|
|
'Alternatively, if you think you may have miss-configured this server': true, |
30
|
|
|
}, |
31
|
|
|
], |
32
|
|
|
])('renders expected information for type "%s"', (type, textsToFind) => { |
33
|
|
|
wrapper = shallow( |
34
|
|
|
<BrowserRouter> |
35
|
|
|
<ServerError type={type} servers={{}} selectedServer={selectedServer} /> |
36
|
|
|
</BrowserRouter> |
37
|
|
|
); |
38
|
|
|
const wrapperText = wrapper.html(); |
39
|
|
|
const textPairs = Object.entries(textsToFind); |
40
|
|
|
|
41
|
|
|
textPairs.forEach(([ text, shouldBeFound ]) => { |
42
|
|
|
if (shouldBeFound) { |
43
|
|
|
expect(wrapperText).toContain(text); |
44
|
|
|
} else { |
45
|
|
|
expect(wrapperText).not.toContain(text); |
46
|
|
|
} |
47
|
|
|
}); |
48
|
|
|
}); |
49
|
|
|
}); |
50
|
|
|
|