|
1 | 1 | import React from 'react'; |
2 | | -import { shallow } from 'enzyme'; |
| 2 | +import { shallow, render } from 'enzyme'; |
3 | 3 | 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 | +}; |
4 | 15 |
|
5 | 16 | 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 | + |
11 | 60 | it.skip('should return the correct icon name'); |
12 | 61 | }); |
0 commit comments