@@ -3,6 +3,7 @@ import { Fiber } from '../types/backendTypes';
33import componentActionsRecord from '../models/masterState' ;
44import createTree from '../controllers/createTree/createTree' ;
55import Tree from '../models/tree' ;
6+ import React , { useState } from 'react' ;
67import {
78 allowedComponentTypes ,
89 nextJSDefaultComponent ,
@@ -14,6 +15,17 @@ describe('master tree tests', () => {
1415 let mockFiberNode : Fiber ;
1516 let mockSiblingNode : Fiber ;
1617 let mockChildNode : Fiber ;
18+ function MockFunctionalComponent ( ) {
19+ const [ count , setCount ] = useState ( 0 ) ;
20+ return (
21+ < div >
22+ < button className = 'increment' onClick = { ( ) => setCount ( count + 1 ) } >
23+ You clicked me { count } times.
24+ </ button >
25+ </ div >
26+ ) ;
27+ }
28+
1729 beforeEach ( ( ) => {
1830 // create a mock Fiber node with relevant properties
1931 mockFiberNode = {
@@ -31,23 +43,26 @@ describe('master tree tests', () => {
3143 _debugHookTypes : [ ] ,
3244 } ;
3345
46+ // create a mock child Fiber node with relevant properties for class component
3447 mockChildNode = {
3548 ...mockFiberNode ,
3649 tag : 1 ,
3750 elementType : { name : 'child' } ,
3851 stateNode : { state : { counter : 0 } , props : { start : 0 } } ,
3952 } ;
53+
54+ // create a mock sibling Fiber node with relevant properties for class component
4055 mockSiblingNode = {
4156 ...mockFiberNode ,
4257 tag : 0 ,
43- elementType : { name : 'sibling' } ,
58+ elementType : MockFunctionalComponent ,
4459 memoizedState : { memoizedState : 1 , queue : [ { } , { state : { value : 'test' } } ] , next : null } ,
4560 } ;
4661 // clear the saved component actions record
4762 componentActionsRecord . clear ( ) ;
4863 } ) ;
4964 describe ( 'create tree tests' , ( ) => {
50- it ( 'should return a Tree if we pass in a empty fiber node' , ( ) => {
65+ xit ( 'should return a Tree if we pass in a empty fiber node' , ( ) => {
5166 const tree = createTree ( mockFiberNode ) ;
5267 const children = tree . children ;
5368
@@ -58,7 +73,7 @@ describe('master tree tests', () => {
5873 expect ( children [ 0 ] . state ) . toEqual ( 'stateless' ) ;
5974 } ) ;
6075
61- it ( 'should filter out NextJS default components with no children or siblings' , ( ) => {
76+ xit ( 'should filter out NextJS default components with no children or siblings' , ( ) => {
6277 for ( let name of nextJSDefaultComponent ) {
6378 mockFiberNode . elementType . name = name ;
6479 const tree = createTree ( mockFiberNode ) ;
@@ -76,19 +91,22 @@ describe('master tree tests', () => {
7691 const children = tree . children ;
7792 const firstChild = children [ 0 ] ;
7893 const secondChild = children [ 1 ] ;
94+ console . log ( 'First Child' , firstChild ) ;
95+ console . log ( 'Second Child' , secondChild ) ;
7996 expect ( children . length ) . toEqual ( 2 ) ;
80- // expect(firstChild.componentData?.state).toEqual(2);
97+ expect ( firstChild . componentData . state ) . toEqual ( { counter : 0 } ) ;
98+ expect ( secondChild . componentData . hooksState ) ;
8199 }
82100 } ) ;
83101
84- it ( 'should filter out remix default components with no children or siblings' , ( ) => {
102+ xit ( 'should filter out remix default components with no children or siblings' , ( ) => {
85103 for ( let name of remixDefaultComponents ) {
86104 mockFiberNode . elementType . name = name ;
87105 const tree = createTree ( mockFiberNode ) ;
88106 }
89107 } ) ;
90108
91- it ( 'should only traverse allowed components' , ( ) => {
109+ xit ( 'should only traverse allowed components' , ( ) => {
92110 for ( let tag of allowedComponentTypes ) {
93111 mockFiberNode . elementType . tag = tag ;
94112 const tree = createTree ( mockFiberNode ) ;
@@ -102,11 +120,11 @@ describe('master tree tests', () => {
102120 } ) ;
103121 } ) ;
104122
105- describe ( 'add sibling' , ( ) => { } ) ;
123+ xdescribe ( 'add sibling' , ( ) => { } ) ;
106124
107- describe ( 'add children' , ( ) => { } ) ;
125+ xdescribe ( 'add children' , ( ) => { } ) ;
108126
109- describe ( 'createComponentActionsRecord' , ( ) => {
127+ xdescribe ( 'createComponentActionsRecord' , ( ) => {
110128 it ( 'should save a new component action record if the Fiber node is a stateful class component' , ( ) => {
111129 mockFiberNode . tag = 1 ; // ClassComponent
112130 mockFiberNode . stateNode = {
0 commit comments