Skip to content

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

Merged
merged 40 commits into from
Jan 6, 2018
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fe8be54
refactor(fonts): Remove useless fonts in android (#485)
dyesseyumba Oct 19, 2017
282f475
refactor(fonts): Remove MaterialIcons from used fonts in android (#485)
dyesseyumba Oct 19, 2017
4498f9a
Revert "refactor(fonts): Remove MaterialIcons from used fonts in andr…
dyesseyumba Oct 19, 2017
f09824a
fix: Update stateRandom and reset cookies after a successful login (#…
machour Oct 18, 2017
7f5695c
feat(markdown): Add support for quoted emails (#501)
machour Oct 19, 2017
a0c70b9
refactor: Drop rn-app-intro in favor of react-native-swiper (#493)
machour Oct 19, 2017
2b1c630
chore: Hide the commitlint folder (#488)
machour Oct 19, 2017
71396d4
feature(translation): add Spanish translation (#442)
khvilaboa Oct 19, 2017
6a19b1f
feat: Issue Events (#438)
brandly Oct 19, 2017
f51d206
fix(ux): Add back button for AuthProfileScreen (#507)
jouderianjr Oct 19, 2017
1153feb
style(issueeventlistitem, commentlistitem): Slightly shrink issue eve…
Oct 19, 2017
3415486
fix: Remove undefined var & fix typo (#517)
machour Oct 20, 2017
f89eabb
chore: fix `yarn run link` (#513)
chinesedfan Oct 20, 2017
07b4d63
chore(*): convert notification icon styles to styled-component (#510)
pdong Oct 20, 2017
d32c703
chore(*): convert label-list-item component styles to styled componen…
pdong Oct 20, 2017
9c4a23b
chore(*): style view-container.component.js (#508)
pdong Oct 20, 2017
b347424
refactor(auth): get user data after login (#502)
lex111 Oct 20, 2017
8f5baf4
test: begin implementing basic component tests (#407)
andrewda Oct 20, 2017
742aca3
refactor(fonts): Remove useless fonts in android (#485)
dyesseyumba Oct 19, 2017
d39759e
refactor(fonts): Remove MaterialIcons from used fonts in android (#485)
dyesseyumba Oct 19, 2017
1d35709
Revert "refactor(fonts): Remove MaterialIcons from used fonts in andr…
dyesseyumba Oct 19, 2017
43814b6
Merge remote-tracking branch 'origin/master'
dyesseyumba Oct 20, 2017
b5eaf4e
Merge remote-tracking branch 'upstream/master'
dyesseyumba Oct 21, 2017
29a1281
Merge remote-tracking branch 'upstream/master'
dyesseyumba Oct 22, 2017
482af68
Merge remote-tracking branch 'upstream/master'
dyesseyumba Oct 25, 2017
e31a1ab
test: Add tests for CommentInput (#518)
dyesseyumba Oct 25, 2017
a5b49d0
Merge remote-tracking branch 'upstream/master' into componentInput_test
dyesseyumba Oct 25, 2017
d0b8584
Merge remote-tracking branch 'upstream/master' into componentInput_test
dyesseyumba Oct 26, 2017
f478de0
refactor: Beautify the code of CommentInput unit test.
dyesseyumba Oct 27, 2017
dd56954
Merge remote-tracking branch 'upstream/master' into componentInput_test
dyesseyumba Oct 27, 2017
13ac053
refactor: use jest mocks instead of sinon spies.
dyesseyumba Oct 27, 2017
d379786
refactor: Apply @chinesedfan recommendations
dyesseyumba Oct 28, 2017
59fc4de
refactor: Improve test descriptions.
dyesseyumba Oct 28, 2017
9f79d23
Merge branch 'master' into componentInput_test
andrewda Oct 29, 2017
d138748
Merge remote-tracking branch 'upstream/master' into componentInput_test
dyesseyumba Oct 30, 2017
2619666
test: Add two cases of test and integrate styled-components in tests.
dyesseyumba Oct 30, 2017
25cf771
refactor: Remove console.log statement.
dyesseyumba Oct 30, 2017
75e45fd
test: Improve test descriptions and remove useless console.log
dyesseyumba Oct 31, 2017
cd7f497
test: Fix conflicts between descriptions and implementations.
dyesseyumba Nov 2, 2017
156285b
refactor: Runned prettier on CommentInput.js
dyesseyumba Nov 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions __tests__/tests/components/CommentInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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');
});
});