Skip to content

Commit cf5e006

Browse files
feat: add tests. coverage 100%
1 parent 6beabd0 commit cf5e006

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ haste-map-react-native-packager*
6363
# editors
6464
.vscode
6565
.idea
66+
67+
coverage

__tests__/tests/components/NotificationListItem.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NotificationListItem } from 'components';
44
import { View, TouchableOpacity } from 'react-native';
55

66
const defaultProps = {
7+
id: 1,
78
notification: {
89
subject: {
910
type: 'Commit',
@@ -57,5 +58,38 @@ describe('<NotificationListItem />', () => {
5758
expect(navigationActionMock).toHaveBeenCalledWith(notification);
5859
});
5960

60-
it.skip('should return the correct icon name');
61+
it('should return the correct icon name', () => {
62+
const wrapper = shallow(<NotificationListItem {...defaultProps} />);
63+
64+
expect(wrapper.instance().getIconName('commit')).toEqual('git-commit');
65+
expect(wrapper.instance().getIconName('pullRequest')).toEqual(
66+
'git-pull-request'
67+
);
68+
expect(wrapper.instance().getIconName('wrong data')).toEqual(
69+
'issue-opened'
70+
);
71+
});
72+
73+
it('should call iconAction on press and notification is unread', () => {
74+
const notification = {
75+
id: 1,
76+
subject: {
77+
type: 'Commit',
78+
},
79+
unread: true,
80+
};
81+
const iconActionMock = jest.fn();
82+
const wrapper = shallow(
83+
<NotificationListItem
84+
{...defaultProps}
85+
notification={notification}
86+
iconAction={iconActionMock}
87+
/>
88+
);
89+
90+
wrapper.find({ nativeId: 'notification-unread' }).simulate('press');
91+
92+
expect(iconActionMock).toHaveBeenCalledWith(1);
93+
expect(iconActionMock).toHaveBeenCalledTimes(1);
94+
});
6195
});

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ export class NotificationListItem extends Component {
5757
return notification.subject.type === 'Commit' ? View : TouchableOpacity;
5858
};
5959

60-
getIconName = () => {
61-
const { notification } = this.props;
62-
63-
switch (notification.subject.type) {
60+
getIconName = type => {
61+
switch (type) {
6462
case 'commit':
6563
return 'git-commit';
6664
case 'pullRequest':
@@ -74,7 +72,7 @@ export class NotificationListItem extends Component {
7472
const { notification, iconAction, navigationAction } = this.props;
7573

7674
const TitleComponent = this.getComponentType();
77-
const iconName = this.getIconName();
75+
const iconName = this.getIconName(notification.subject.type);
7876

7977
return (
8078
<View style={styles.container}>
@@ -98,6 +96,7 @@ export class NotificationListItem extends Component {
9896

9997
{notification.unread && (
10098
<TouchableOpacity
99+
nativeId="notification-unread"
101100
style={styles.iconContainer}
102101
onPress={() => iconAction(notification.id)}
103102
>

0 commit comments

Comments
 (0)