1
+ import React from 'react' ;
2
+ import { shallow } from 'enzyme' ;
3
+ import { IssueListItem } from 'components' ;
4
+
5
+ const defaultProps = {
6
+ type : 'issue' ,
7
+ issue : {
8
+ state : 'open' ,
9
+ number : 101 ,
10
+ title : 'My Issue' ,
11
+ user : {
12
+ login : 'gitpoint'
13
+ } ,
14
+ comments : 5 ,
15
+ created_at : new Date ( ) ,
16
+ } ,
17
+ navigation : { } ,
18
+ locale : 'en'
19
+ } ;
20
+
21
+ describe ( '<IssueListItem />' , ( ) => {
22
+ it ( 'should render open issue info' , ( ) => {
23
+ const props = { ...defaultProps , issue : { ...defaultProps . issue , state : 'open' } } ;
24
+ const wrapper = shallow ( < IssueListItem { ...props } /> ) ;
25
+ const infoWrapper = wrapper . find ( 'ListItem' ) ;
26
+
27
+ expect ( infoWrapper . prop ( 'leftIcon' ) . name ) . toEqual ( 'issue-opened' ) ;
28
+ expect ( infoWrapper . prop ( 'title' ) ) . toEqual ( props . issue . title ) ;
29
+ expect ( infoWrapper . prop ( 'subtitle' ) ) . toEqual (
30
+ expect . stringContaining ( `#${ props . issue . number } ` )
31
+ ) ;
32
+ } ) ;
33
+
34
+ it ( 'should render closed issue info' , ( ) => {
35
+ const props = {
36
+ ...defaultProps ,
37
+ issue : { ...defaultProps . issue , state : 'closed' , closed_at : new Date ( ) }
38
+ } ;
39
+ const wrapper = shallow ( < IssueListItem { ...props } /> ) ;
40
+ const infoWrapper = wrapper . find ( 'ListItem' ) ;
41
+
42
+ expect ( infoWrapper . prop ( 'leftIcon' ) . name ) . toEqual ( 'issue-closed' ) ;
43
+ expect ( infoWrapper . prop ( 'title' ) ) . toEqual ( props . issue . title ) ;
44
+ expect ( infoWrapper . prop ( 'subtitle' ) ) . toEqual (
45
+ expect . stringContaining ( `#${ props . issue . number } by ${ props . issue . user . login } was closed 1m ago` )
46
+ ) ;
47
+ } ) ;
48
+
49
+ it ( 'should render merged pull request info' , ( ) => {
50
+ const props = {
51
+ ...defaultProps ,
52
+ type : undefined ,
53
+ issue : { ...defaultProps . issue , state : 'merged' , closed_at : new Date ( ) }
54
+ } ;
55
+ const wrapper = shallow ( < IssueListItem { ...props } /> ) ;
56
+ const infoWrapper = wrapper . find ( 'ListItem' ) ;
57
+
58
+ expect ( infoWrapper . prop ( 'leftIcon' ) . name ) . toEqual ( 'git-pull-request' ) ;
59
+ expect ( infoWrapper . prop ( 'title' ) ) . toEqual ( props . issue . title ) ;
60
+ expect ( infoWrapper . prop ( 'subtitle' ) ) . toEqual (
61
+ expect . stringContaining ( `#${ props . issue . number } by ${ props . issue . user . login } was closed 1m ago` )
62
+ ) ;
63
+ } ) ;
64
+
65
+ it ( 'should render comments icon and counter' , ( ) => {
66
+ const wrapper = shallow ( < IssueListItem { ...defaultProps } /> ) ;
67
+
68
+ expect ( wrapper . find ( 'Icon' ) ) . toHaveLength ( 1 ) ;
69
+ expect ( wrapper . find ( 'Text' ) . contains ( defaultProps . issue . comments ) ) . toBe ( true ) ;
70
+ } ) ;
71
+
72
+ it ( 'should open issue when pressing' , ( ) => {
73
+ const navigation = { navigate : jest . fn ( ) } ;
74
+ const wrapper = shallow ( < IssueListItem { ...defaultProps } navigation = { navigation } /> ) ;
75
+
76
+ wrapper . simulate ( 'press' ) ;
77
+
78
+ expect ( navigation . navigate ) . toHaveBeenCalledTimes ( 1 ) ;
79
+ expect ( navigation . navigate ) . toHaveBeenCalledWith ( 'Issue' , expect . anything ( ) ) ;
80
+ } ) ;
81
+ } ) ;
0 commit comments