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
152 lines (114 loc) · 4.8 KB
/
Copy pathCommentInput.js
File metadata and controls
152 lines (114 loc) · 4.8 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 styled TextInput and styled TouchableOpacity if user has push permissions and issue is not locked', () => {
const wrapper = shallow(<CommentInput {...defaultProps} />);
expect(wrapper.find('Styled(TextInput)').length).toEqual(1);
expect(wrapper.find('Styled(TouchableOpacity)').length).toEqual(1);
});
it('should not render styled Text and Icon if user has push permissions and issue is not locked', () => {
const wrapper = shallow(<CommentInput {...defaultProps} />);
expect(wrapper.find('Styled(Text)').length).toEqual(0);
expect(wrapper.find('Icon').length).toEqual(0);
});
it('should not render styled TextInput and styled TouchableOpacity if user does not have push permissions and issue is locked', () => {
const wrapper = shallow(
<CommentInput
{...defaultProps}
userHasPushPermission={false}
issueLocked={true}
/>
);
expect(wrapper.find('Styled(TextInput)').length).toEqual(0);
expect(wrapper.find('Styled(TouchableOpacity)').length).toEqual(0);
});
it('should render styled Text and Icon if user does not have push permissions and issue is locked', () => {
const wrapper = shallow(
<CommentInput
{...defaultProps}
userHasPushPermission={false}
issueLocked={true}
/>
);
expect(wrapper.find('Styled(Text)').length).toEqual(1);
expect(wrapper.find('Icon').length).toEqual(1);
});
it('should render styled TextInput and styled TouchableOpacity if user has push permissions and issue is locked', () => {
const wrapper = shallow(
<CommentInput {...defaultProps} issueLocked={true} />
);
expect(wrapper.find('Styled(TextInput)').length).toEqual(1);
expect(wrapper.find('Styled(TouchableOpacity)').length).toEqual(1);
});
it('should not render styled Text and Icon if user has push permissions and issue is locked', () => {
const wrapper = shallow(
<CommentInput {...defaultProps} issueLocked={true} />
);
expect(wrapper.find('Styled(Text)').length).toEqual(0);
expect(wrapper.find('Icon').length).toEqual(0);
});
it('should not render styled Text and Icon if user does not have push permissions and issue is not locked', () => {
const wrapper = shallow(
<CommentInput {...defaultProps} userHasPushPermission={false} />
);
expect(wrapper.find('Styled(Text)').length).toEqual(0);
expect(wrapper.find('Icon').length).toEqual(0);
});
it('should render styled TextInput and styled TouchableOpacity if user does not have push permissions and issue is not locked', () => {
const wrapper = shallow(
<CommentInput {...defaultProps} userHasPushPermission={false} />
);
expect(wrapper.find('Styled(TextInput)').length).toEqual(1);
expect(wrapper.find('Styled(TouchableOpacity)').length).toEqual(1);
});
it('should update the state text if value is changed', () => {
const wrapper = shallow(<CommentInput {...defaultProps} />);
const input = wrapper.find('Styled(TextInput)');
input.simulate('changeText', 'Changed text');
expect(wrapper.state('text')).toEqual('Changed text');
});
it('should call handleSubmit method when submitted', () => {
const wrapper = shallow(<CommentInput {...defaultProps} />);
const handleSubmitSpy = jest.spyOn(wrapper.instance(), 'handleSubmit');
wrapper.instance().forceUpdate();
wrapper.find('Styled(TextInput)').simulate('changeText', 'Changed text');
wrapper.find('Styled(TouchableOpacity)').simulate('press');
expect(handleSubmitSpy).toHaveBeenCalled();
});
it('should change the content size', () => {
const wrapper = shallow(<CommentInput {...defaultProps} />);
wrapper.find('Styled(TextInput)').simulate('contentSizeChange', {
nativeEvent: {
contentSize: {
height: 10,
},
},
});
expect(wrapper.state('height')).toBe(10);
});
it('should call handleSubmitEditing method in Android when onSubmitEditing event is raised', () => {
const wrapper = shallow(<CommentInput {...defaultProps} />);
const handleSubmitEditingSpy = jest.spyOn(
wrapper.instance(),
'handleSubmitEditing'
);
wrapper.instance().forceUpdate();
Platform.OS = 'android';
wrapper.find('Styled(TextInput)').simulate('submitEditing', {
nativeEvent: {
text: 'Changed by submitEditing',
},
});
expect(handleSubmitEditingSpy).toHaveBeenCalled();
expect(wrapper.state('text')).toEqual('Changed by submitEditing\n');
});
});