1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// @flow
import { expect } from 'chai';
import React from 'react';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import SelectLocation from '../../app/components/SelectLocation';
import type { SettingsReduxState } from '../../app/redux/settings/reducers';
import type { SelectLocationProps } from '../../app/components/SelectLocation';
describe('components/SelectLocation', () => {
const state: SettingsReduxState = {
relaySettings: {
normal: {
location: 'any',
protocol: 'any',
port: 'any',
}
},
};
const makeProps = (state: SettingsReduxState, mergeProps: $Shape<SelectLocationProps>): SelectLocationProps => {
const defaultProps: SelectLocationProps = {
settings: state,
onClose: () => {},
onSelect: (_server) => {}
};
return Object.assign({}, defaultProps, mergeProps);
};
const render = (props: SelectLocationProps): SelectLocation => {
return ReactTestUtils.renderIntoDocument(
<SelectLocation { ...props } />
);
};
it('should call close callback', (done) => {
const props = makeProps(state, {
onClose: () => done()
});
const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'select-location__close');
Simulate.click(domNode);
});
it('should call select callback', (done) => {
const props = makeProps(state, {
onSelect: (_server) => done()
});
const elements = ReactTestUtils.scryRenderedDOMComponentsWithClass(render(props), 'select-location__cell');
expect(elements).to.have.length.greaterThan(1);
Simulate.click(elements[1]);
});
});
|