forked from gitpoint/git-point
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentInput.js
More file actions
119 lines (90 loc) · 2.78 KB
/
Copy pathCommentInput.js
File metadata and controls
119 lines (90 loc) · 2.78 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React from 'react';
import {shallow} from 'enzyme';
import {Platform} from 'react-native';
import {CommentInput} from 'components';
describe('<CommentInput />', () => {
const defaultProps = {
users: [],
userHasPushPermission: true,
issueLocked: false,
locale: '',
onSubmit: () => {},
};
it('should render TextInput and TouchableOpacity if I can post', () => {
const wrapper = shallow(
<CommentInput {...defaultProps}/>
);
expect(wrapper.find('TextInput').length).toEqual(1);
expect(wrapper.find('TouchableOpacity').length).toEqual(1);
expect(wrapper.find('Text').length).toEqual(0);
});
it("should not render TextInput and TouchableOpacity if I can't post", () => {
const wrapper = shallow(
<CommentInput
{...defaultProps}
userHasPushPermission={false}
issueLocked={true}/>
);
expect(wrapper.find('TextInput').length).toEqual(0);
expect(wrapper.find('TouchableOpacity').length).toEqual(0);
expect(wrapper.find('Text').length).toEqual(1);
});
it('should update the state text if value changed', () => {
const wrapper = shallow(
<CommentInput {...defaultProps}/>
);
const input = wrapper.find('TextInput');
input.simulate('changeText', 'Changed text');
expect(wrapper.state('text')).toEqual('Changed text');
});
it('should call handleSubmit methods when submitted', () => {
const wrapper = shallow(
<CommentInput {...defaultProps}/>
);
const handleSubmitSpy = jest.spyOn(wrapper.instance(), 'handleSubmit');
wrapper
.instance()
.forceUpdate();
wrapper
.find('TextInput')
.simulate('changeText', 'Changed text');
wrapper
.find('TouchableOpacity')
.simulate('press');
expect(handleSubmitSpy).toHaveBeenCalled();
});
it('should change the content size', () => {
const wrapper = shallow(
<CommentInput {...defaultProps}/>
);
wrapper
.find('TextInput')
.simulate('contentSizeChange', {
nativeEvent: {
contentSize: {
height: 10
}
}
});
expect(wrapper.state('height')).toBe(10);
});
it('should call handleSubmitEditing methods when onSubmitEditing event raised', () => {
const wrapper = shallow(
<CommentInput {...defaultProps}/>
);
const handleSubmitEditingSpy = jest.spyOn(wrapper.instance(), 'handleSubmitEditing');
wrapper
.instance()
.forceUpdate();
Platform.OS = 'android';
wrapper
.find('TextInput')
.simulate('submitEditing', {
nativeEvent: {
text: 'Changed by submitEditing'
}
});
expect(handleSubmitEditingSpy).toHaveBeenCalled();
expect(wrapper.state('text')).toEqual('Changed by submitEditing\n');
});
});