Skip to content

Commit 6beabd0

Browse files
feat(test) add more test
1 parent 0791603 commit 6beabd0

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,61 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, render } from 'enzyme';
33
import { NotificationListItem } from 'components';
4+
import { View, TouchableOpacity } from 'react-native';
5+
6+
const defaultProps = {
7+
notification: {
8+
subject: {
9+
type: 'Commit',
10+
},
11+
},
12+
iconAction() {},
13+
navigationAction() {},
14+
};
415

516
describe('<NotificationListItem />', () => {
6-
it.skip("should render a View component if notification type is 'Commit'");
7-
it.skip(
8-
"should render a TouchableOpacity component if notification type is not 'Commit'"
9-
);
10-
it.skip('should call navigation when user press TitleComponent');
17+
it("should render a View component if notification type is 'Commit'", () => {
18+
const wrapper = shallow(<NotificationListItem {...defaultProps} />);
19+
20+
const result = wrapper.instance().getComponentType();
21+
22+
expect(result).toBe(View);
23+
});
24+
25+
it("should render a TouchableOpacity component if notification type is not 'Commit'", () => {
26+
const notification = {
27+
subject: {
28+
type: 'not a commit',
29+
},
30+
};
31+
const wrapper = shallow(
32+
<NotificationListItem {...defaultProps} notification={notification} />
33+
);
34+
35+
const result = wrapper.instance().getComponentType();
36+
37+
expect(result).toBe(TouchableOpacity);
38+
});
39+
40+
it('should call navigation when user press TitleComponent', () => {
41+
const notification = {
42+
subject: {
43+
type: 'not a commit',
44+
},
45+
};
46+
const navigationActionMock = jest.fn();
47+
const wrapper = shallow(
48+
<NotificationListItem
49+
{...defaultProps}
50+
notification={notification}
51+
navigationAction={navigationActionMock}
52+
/>
53+
);
54+
55+
wrapper.find({ nativeId: 'TitleComponent' }).simulate('press');
56+
57+
expect(navigationActionMock).toHaveBeenCalledWith(notification);
58+
});
59+
1160
it.skip('should return the correct icon name');
1261
});

src/components/notification-list-item.component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class NotificationListItem extends Component {
8080
<View style={styles.container}>
8181
<View style={styles.wrapper}>
8282
<TitleComponent
83+
nativeId="TitleComponent"
8384
style={styles.notificationInfo}
8485
onPress={() => navigationAction(notification)}
8586
>

0 commit comments

Comments
 (0)