diff --git a/__tests__/tests/components/CommentInput.js b/__tests__/tests/components/CommentInput.js new file mode 100644 index 000000000..e2155e067 --- /dev/null +++ b/__tests__/tests/components/CommentInput.js @@ -0,0 +1,152 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import { Platform } from 'react-native'; + +import { CommentInput } from 'components'; + +describe('', () => { + 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(); + + 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(); + + 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( + + ); + + 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( + + ); + + 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( + + ); + + 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( + + ); + + 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( + + ); + + 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( + + ); + + 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(); + + 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(); + + 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(); + + 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(); + + 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'); + }); +});