@@ -83,10 +83,12 @@ suite('Parser Test Suite', () => {
8383 tree = parser . parse ( ) ;
8484 } ) ;
8585
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 ) ;
8888 expect ( tree . children [ 0 ] ) . to . have . own . property ( 'name' ) . that . is . oneOf ( [ 'Switch' , 'Route' ] ) ;
8989 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+
9092 } ) ;
9193
9294 test ( 'reactRouter should be designated as third party and reactRouter' , ( ) => {
@@ -97,10 +99,28 @@ suite('Parser Test Suite', () => {
9799 expect ( tree . children [ 1 ] ) . to . have . own . property ( 'reactRouter' ) . to . be . true ;
98100 } ) ;
99101
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+ } ) ;
101106 } ) ;
102107
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+ } ) ;
104124
105125 // TEST 4: ALIASED IMPORTS
106126 describe ( 'It works for aliases' , ( ) => {
@@ -156,7 +176,7 @@ suite('Parser Test Suite', () => {
156176 } ) ;
157177 } ) ;
158178
159- // TEST 6: Bad import of App2 from App1 Component
179+ // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
160180 describe ( 'It works for badly imported children nodes' , ( ) => {
161181 before ( ( ) => {
162182 file = path . join ( __dirname , '../../../src/test/test_apps/test_6/index.js' ) ;
@@ -170,7 +190,7 @@ suite('Parser Test Suite', () => {
170190 } ) ;
171191 } ) ;
172192
173- // TEST 7: Syntax error in app file causes parser error
193+ // TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
174194 describe ( 'It should log an error when the parser encounters a javascript syntax error' , ( ) => {
175195 before ( ( ) => {
176196 file = path . join ( __dirname , '../../../src/test/test_apps/test_7/index.js' ) ;
@@ -185,14 +205,33 @@ suite('Parser Test Suite', () => {
185205 } ) ;
186206 } ) ;
187207
188- // Test 8: Props check
208+ // TEST 8: MULTIPLE PROPS ON ONE COMPONENT
189209 describe ( 'It should properly count repeat components and consolidate and grab their props' , ( ) => {
190210 before ( ( ) => {
191211 file = path . join ( __dirname , '../../../src/test/test_apps/test_8/index.js' ) ;
192212 parser = new SaplingParser ( file ) ;
193213 tree = parser . parse ( ) ;
194214 } ) ;
195215
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+
196235 test ( 'Grandchild should have a count of 2' , ( ) => {
197236 expect ( tree . children [ 0 ] . children [ 0 ] ) . to . have . own . property ( 'count' ) . that . equals ( 2 ) ;
198237 } ) ;
@@ -203,7 +242,7 @@ suite('Parser Test Suite', () => {
203242 } ) ;
204243 } ) ;
205244
206- // Test 10: check children works and component works
245+ // TEST 10: CHECK CHILDREN WORKS AND COMPONENTS WORK
207246 describe ( 'It should render children when children are rendered as values of prop called component' , ( ) => {
208247 before ( ( ) => {
209248 file = path . join ( __dirname , '../../../src/test/test_apps/test_10/index.jsx' ) ;
@@ -219,4 +258,28 @@ suite('Parser Test Suite', () => {
219258 expect ( tree . children [ 1 ] . children [ 4 ] ) . to . have . own . property ( 'name' ) . that . is . equal ( 'HistoryDisplay' ) ;
220259 } ) ;
221260 } ) ;
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+ } ) ;
222285} ) ;
0 commit comments