@@ -83,10 +83,12 @@ suite('Parser Test Suite', () => {
83
83
tree = parser . parse ( ) ;
84
84
} ) ;
85
85
86
- test ( 'Should parse destructured imports' , ( ) => {
87
- expect ( tree . children ) . to . have . lengthOf ( 2 ) ;
86
+ test ( 'Should parse destructured and third party imports' , ( ) => {
87
+ expect ( tree . children ) . to . have . lengthOf ( 3 ) ;
88
88
expect ( tree . children [ 0 ] ) . to . have . own . property ( 'name' ) . that . is . oneOf ( [ 'Switch' , 'Route' ] ) ;
89
89
expect ( tree . children [ 1 ] ) . to . have . own . property ( 'name' ) . that . is . oneOf ( [ 'Switch' , 'Route' ] ) ;
90
+ expect ( tree . children [ 2 ] ) . to . have . own . property ( 'name' ) . that . is . equal ( 'Tippy' ) ;
91
+
90
92
} ) ;
91
93
92
94
test ( 'reactRouter should be designated as third party and reactRouter' , ( ) => {
@@ -97,10 +99,28 @@ suite('Parser Test Suite', () => {
97
99
expect ( tree . children [ 1 ] ) . to . have . own . property ( 'reactRouter' ) . to . be . true ;
98
100
} ) ;
99
101
100
- //test for third party without reactRouter
102
+ test ( 'Tippy should be designated as third party and not reactRouter' , ( ) => {
103
+ expect ( tree . children [ 2 ] ) . to . have . own . property ( 'thirdParty' ) . to . be . true ;
104
+ expect ( tree . children [ 2 ] ) . to . have . own . property ( 'reactRouter' ) . to . be . false ;
105
+ } ) ;
101
106
} ) ;
102
107
103
- // TEST 3: WOBBEGAINZ
108
+ // TEST 3: IDENTIFIES REDUX STORE CONNECTION
109
+ describe ( 'It identifies a Redux store connection and designates the component as such' , ( ) => {
110
+ before ( ( ) => {
111
+ file = path . join ( __dirname , '../../../src/test/test_apps/test_3/index.js' ) ;
112
+ parser = new SaplingParser ( file ) ;
113
+ tree = parser . parse ( ) ;
114
+ } ) ;
115
+
116
+ test ( 'The reduxConnect properties of the connected component and the unconnected component should be true and false, respectively' , ( ) => {
117
+ expect ( tree . children [ 1 ] . children [ 0 ] . name ) . to . equal ( 'ConnectedContainer' ) ;
118
+ expect ( tree . children [ 1 ] . children [ 0 ] ) . to . have . own . property ( 'reduxConnect' ) . that . is . true ;
119
+
120
+ expect ( tree . children [ 1 ] . children [ 1 ] . name ) . to . equal ( 'UnconnectedContainer' ) ;
121
+ expect ( tree . children [ 1 ] . children [ 1 ] ) . to . have . own . property ( 'reduxConnect' ) . that . is . false ;
122
+ } ) ;
123
+ } ) ;
104
124
105
125
// TEST 4: ALIASED IMPORTS
106
126
describe ( 'It works for aliases' , ( ) => {
@@ -156,7 +176,7 @@ suite('Parser Test Suite', () => {
156
176
} ) ;
157
177
} ) ;
158
178
159
- // TEST 6: Bad import of App2 from App1 Component
179
+ // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
160
180
describe ( 'It works for badly imported children nodes' , ( ) => {
161
181
before ( ( ) => {
162
182
file = path . join ( __dirname , '../../../src/test/test_apps/test_6/index.js' ) ;
@@ -170,7 +190,7 @@ suite('Parser Test Suite', () => {
170
190
} ) ;
171
191
} ) ;
172
192
173
- // TEST 7: Syntax error in app file causes parser error
193
+ // TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
174
194
describe ( 'It should log an error when the parser encounters a javascript syntax error' , ( ) => {
175
195
before ( ( ) => {
176
196
file = path . join ( __dirname , '../../../src/test/test_apps/test_7/index.js' ) ;
@@ -185,14 +205,33 @@ suite('Parser Test Suite', () => {
185
205
} ) ;
186
206
} ) ;
187
207
188
- // Test 8: Props check
208
+ // TEST 8: MULTIPLE PROPS ON ONE COMPONENT
189
209
describe ( 'It should properly count repeat components and consolidate and grab their props' , ( ) => {
190
210
before ( ( ) => {
191
211
file = path . join ( __dirname , '../../../src/test/test_apps/test_8/index.js' ) ;
192
212
parser = new SaplingParser ( file ) ;
193
213
tree = parser . parse ( ) ;
194
214
} ) ;
195
215
216
+ test ( 'Grandchild should have a count of 1' , ( ) => {
217
+ expect ( tree . children [ 0 ] . children [ 0 ] ) . to . have . own . property ( 'count' ) . that . equals ( 1 ) ;
218
+ } ) ;
219
+
220
+ test ( 'Grandchild should have the correct three props' , ( ) => {
221
+ expect ( tree . children [ 0 ] . children [ 0 ] . props ) . has . own . property ( 'prop1' ) . that . is . true ;
222
+ expect ( tree . children [ 0 ] . children [ 0 ] . props ) . has . own . property ( 'prop2' ) . that . is . true ;
223
+ expect ( tree . children [ 0 ] . children [ 0 ] . props ) . has . own . property ( 'prop3' ) . that . is . true ;
224
+ } ) ;
225
+ } ) ;
226
+
227
+ // TEST 9: FINDING DIFFERENT PROPS ACROSS TWO OR MORE IDENTICAL COMPONENTS
228
+ describe ( 'It should properly count repeat components and consolidate and grab their props' , ( ) => {
229
+ before ( ( ) => {
230
+ file = path . join ( __dirname , '../../../src/test/test_apps/test_9/index.js' ) ;
231
+ parser = new SaplingParser ( file ) ;
232
+ tree = parser . parse ( ) ;
233
+ } ) ;
234
+
196
235
test ( 'Grandchild should have a count of 2' , ( ) => {
197
236
expect ( tree . children [ 0 ] . children [ 0 ] ) . to . have . own . property ( 'count' ) . that . equals ( 2 ) ;
198
237
} ) ;
@@ -203,7 +242,7 @@ suite('Parser Test Suite', () => {
203
242
} ) ;
204
243
} ) ;
205
244
206
- // Test 10: check children works and component works
245
+ // TEST 10: CHECK CHILDREN WORKS AND COMPONENTS WORK
207
246
describe ( 'It should render children when children are rendered as values of prop called component' , ( ) => {
208
247
before ( ( ) => {
209
248
file = path . join ( __dirname , '../../../src/test/test_apps/test_10/index.jsx' ) ;
@@ -219,4 +258,28 @@ suite('Parser Test Suite', () => {
219
258
expect ( tree . children [ 1 ] . children [ 4 ] ) . to . have . own . property ( 'name' ) . that . is . equal ( 'HistoryDisplay' ) ;
220
259
} ) ;
221
260
} ) ;
261
+
262
+ // TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS
263
+ describe ( 'It should render the second call of mutually recursive components, but no further' , ( ) => {
264
+ before ( ( ) => {
265
+ file = path . join ( __dirname , '../../../src/test/test_apps/test_11/index.js' ) ;
266
+ parser = new SaplingParser ( file ) ;
267
+ tree = parser . parse ( ) ;
268
+ } ) ;
269
+
270
+ test ( 'Tree should not be undefined' , ( ) => {
271
+ expect ( tree ) . to . not . be . undefined ;
272
+ } ) ;
273
+
274
+ test ( 'Tree should have an index component while child App1, grandchild App2, great-grandchild App1' , ( ) => {
275
+ expect ( tree ) . to . have . own . property ( 'name' ) . that . is . equal ( 'index' ) ;
276
+ expect ( tree . children ) . to . have . lengthOf ( 1 ) ;
277
+ expect ( tree . children [ 0 ] ) . to . have . own . property ( 'name' ) . that . is . equal ( 'App1' ) ;
278
+ expect ( tree . children [ 0 ] . children ) . to . have . lengthOf ( 1 ) ;
279
+ expect ( tree . children [ 0 ] . children [ 0 ] ) . to . have . own . property ( 'name' ) . that . is . equal ( 'App2' ) ;
280
+ expect ( tree . children [ 0 ] . children [ 0 ] . children ) . to . have . lengthOf ( 1 ) ;
281
+ expect ( tree . children [ 0 ] . children [ 0 ] . children [ 0 ] ) . to . have . own . property ( 'name' ) . that . is . equal ( 'App1' ) ;
282
+ expect ( tree . children [ 0 ] . children [ 0 ] . children [ 0 ] . children ) . to . have . lengthOf ( 0 ) ;
283
+ } ) ;
284
+ } ) ;
222
285
} ) ;
0 commit comments