@@ -32,33 +32,56 @@ const INITIAL_STATE = {
32
32
price : 125.36
33
33
}
34
34
] ,
35
- } ,
35
+ } ,
36
36
categories : {
37
37
currentId : 3 ,
38
38
}
39
39
} ;
40
40
41
+ const STATE_WITHOUT_ITEMS = {
42
+ products : {
43
+ items : [ ] ,
44
+ } ,
45
+ categories : {
46
+ currentId : 3 ,
47
+ }
48
+ }
49
+
41
50
const navigation = { navigate : jest . fn ( ) } ;
51
+
42
52
let wrapper ;
53
+ let wrapperWithoutItems ;
43
54
44
55
beforeEach ( ( ) => {
45
56
wrapper = ReactTestRender . create (
46
57
< Provider store = { mockStore ( INITIAL_STATE ) } >
47
58
< ProductsList navigation = { navigation } />
48
59
</ Provider > ,
49
60
) ;
61
+
62
+ wrapperWithoutItems = ReactTestRender . create (
63
+ < Provider store = { mockStore ( STATE_WITHOUT_ITEMS ) } >
64
+ < ProductsList navigation = { navigation } />
65
+ </ Provider > ,
66
+ ) ;
50
67
} ) ;
51
68
52
69
describe ( 'ProductsList Component' , ( ) => {
53
70
describe ( 'Smoke tests' , ( ) => {
54
71
it ( 'Should render ProductsList component correctly' , ( ) => {
55
72
expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
56
- } ) ;
73
+ } ) ;
57
74
} ) ;
58
75
59
- describe ( 'Component strucuture ' , ( ) => {
76
+ describe ( 'Component structure ' , ( ) => {
60
77
it ( 'Should render 3 items' , ( ) => {
61
78
expect ( wrapper . root . findAllByType ( 'TouchableOpacity' ) . length ) . toBe ( 3 ) ;
79
+ expect ( wrapper . root . findAllByType ( 'Image' ) . length ) . toBe ( 3 ) ;
80
+ expect ( wrapper . root . findAllByType ( 'Text' ) . length ) . toBe ( 9 ) ;
62
81
} ) ;
63
- } ) ;
82
+
83
+ it ( 'Should render no items' , ( ) => {
84
+ expect ( wrapperWithoutItems . root . findAllByType ( 'TouchableOpacity' ) . length ) . toBe ( 0 ) ;
85
+ } ) ;
86
+ } ) ;
64
87
} ) ;
0 commit comments