-
Notifications
You must be signed in to change notification settings - Fork 773
test: add tests for CommentInput #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 33 commits
fe8be54
282f475
4498f9a
f09824a
7f5695c
a0c70b9
2b1c630
71396d4
6a19b1f
f51d206
1153feb
3415486
f89eabb
07b4d63
d32c703
9c4a23b
b347424
8f5baf4
742aca3
d39759e
1d35709
43814b6
b5eaf4e
29a1281
482af68
e31a1ab
a5b49d0
d0b8584
f478de0
dd56954
13ac053
d379786
59fc4de
9f79d23
d138748
2619666
25cf771
75e45fd
cd7f497
156285b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,3 +63,5 @@ haste-map-react-native-packager* | |
| # editors | ||
| .vscode | ||
| .idea | ||
|
|
||
| coverage/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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", () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 3rd person. |
||
|
|
||
| const wrapper = shallow( | ||
| <CommentInput | ||
| {...defaultProps} | ||
| userHasPushPermission={false} | ||
| issueLocked={true}/> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we separate as 2 cases? For
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dyesseyumba Yes, there are 2 kinds of results. But we have 4 kinds of inputs,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'm on it. |
||
| ); | ||
|
|
||
| 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', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dyesseyumba |
||
| const wrapper = shallow( | ||
| <CommentInput {...defaultProps}/> | ||
| ); | ||
|
|
||
| const handleSubmitEditingSpy = jest.spyOn(wrapper.instance(), 'handleSubmitEditing'); | ||
|
|
||
| wrapper | ||
| .instance() | ||
| .forceUpdate(); | ||
|
|
||
| Platform.OS = 'android'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should mock this instead of modifying it directly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I failed to import the mocked CommentInput import the Do you have any idea?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this line for me? I am curious about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an instruction for the platform Android in the method About |
||
|
|
||
| wrapper | ||
| .find('TextInput') | ||
| .simulate('submitEditing', { | ||
| nativeEvent: { | ||
| text: 'Changed by submitEditing' | ||
| } | ||
| }); | ||
|
|
||
| expect(handleSubmitEditingSpy).toHaveBeenCalled(); | ||
|
|
||
| expect(wrapper.state('text')).toEqual('Changed by submitEditing\n'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, why does it end with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
| }); | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 3rd person.
'should render TextInput and TouchableOpacity if user has post permissions'