11import Tree from '../../models/tree' ;
22import routes from '../../models/routes' ;
3- import { ComponentData , Fiber } from '../../types/backendTypes' ;
3+ import { ComponentData , Fiber , FiberRoot } from '../../types/backendTypes' ;
44import { FunctionComponent , ClassComponent , HostRoot } from '../../types/backendTypes' ;
55import IncrementFunc from './IncrementFunc' ;
66import IncrementClass from './IncrementClass' ;
7+ import { transformSync } from '@babel/core' ;
78
9+ // ----------------------------TEST CASES FOR ROOT------------------------------
810export const root : Fiber = {
911 tag : HostRoot ,
1012 elementType : null ,
@@ -22,14 +24,15 @@ export const root: Fiber = {
2224export const rootPayload = new Tree ( 'root' , 'root' ) ;
2325rootPayload . route = routes . addRoute ( 'http://localhost/' ) ;
2426
27+ // ----------------------TEST CASE FOR FUNCTIONAL COMPONENT---------------------
2528export const functionalComponent : Fiber = {
2629 tag : FunctionComponent ,
2730 elementType : IncrementFunc ,
2831 sibling : null ,
2932 stateNode : null ,
3033 child : null ,
3134 memoizedState : {
32- memoizeState : 0 ,
35+ memoizedState : 0 ,
3336 queue : {
3437 dispatch : function ( newState ) {
3538 this . memoizedState = newState ;
@@ -44,6 +47,25 @@ export const functionalComponent: Fiber = {
4447 _debugHookTypes : [ 'useState' ] ,
4548} ;
4649
50+ const functionalComponentData : ComponentData = {
51+ actualDuration : 1 ,
52+ actualStartTime : 2 ,
53+ selfBaseDuration : 3 ,
54+ treeBaseDuration : 4 ,
55+ context : { } ,
56+ hooksIndex : [ 0 ] ,
57+ hooksState : { count : 0 } ,
58+ index : null ,
59+ props : { } ,
60+ state : null ,
61+ } ;
62+
63+ export const functionalPayload : Tree = new Tree ( 'root' , 'root' ) ;
64+ functionalPayload . route = rootPayload . route ;
65+ functionalPayload . addChild ( { count : 0 } , 'IncrementFunc' , functionalComponentData , null ) ;
66+
67+ // -----------------------TEST CASE FOR CLASS COMPONENT-------------------------
68+
4769export const classComponent : Fiber = {
4870 tag : ClassComponent ,
4971 elementType : IncrementClass ,
@@ -66,11 +88,7 @@ export const classComponent: Fiber = {
6688 _debugHookTypes : null ,
6789} ;
6890
69- export const classPayload = new Tree ( 'root' , 'root' ) ;
70- classPayload . route = rootPayload . route ;
71-
72- // Append increment child to root
73- const componentData : ComponentData = {
91+ const classComponentData : ComponentData = {
7492 actualDuration : 1 ,
7593 actualStartTime : 2 ,
7694 selfBaseDuration : 3 ,
@@ -82,13 +100,82 @@ const componentData: ComponentData = {
82100 props : { } ,
83101 state : { count : 0 } ,
84102} ;
85- classPayload . addChild ( { count : 0 } , 'IncrementClass' , componentData , null ) ;
103+
104+ export const classPayload = new Tree ( 'root' , 'root' ) ;
105+ classPayload . route = rootPayload . route ;
106+
107+ classPayload . addChild ( { count : 0 } , 'IncrementClass' , classComponentData , null ) ;
86108
87109export const updateClassPayload = new Tree ( 'root' , 'root' ) ;
88110updateClassPayload . route = rootPayload . route ;
89111updateClassPayload . addChild (
90112 { count : 2 } ,
91113 'IncrementClass' ,
92- { ...componentData , state : { count : 2 } } ,
114+ { ...classComponentData , state : { count : 2 } } ,
93115 null ,
94116) ;
117+
118+ // -----------------------TEST CASE FOR MIX OF COMPONENTS-----------------------
119+ export const mixComponents : Fiber = deepCopy ( root ) ;
120+ mixComponents . child = deepCopy ( functionalComponent ) ;
121+ mixComponents . sibling = deepCopy ( classComponent ) ;
122+ mixComponents . child ! . child = deepCopy ( functionalComponent ) ;
123+ mixComponents . child ! . child ! . sibling = deepCopy ( classComponent ) ;
124+ // console.dir(mixComponents, { depth: null });
125+
126+ export const mixPayload = new Tree ( 'root' , 'root' ) ;
127+ mixPayload . route = rootPayload . route ;
128+
129+ // Outer Func Comp
130+ let funcPayloadMix = new Tree ( { count : 0 } , 'IncrementFunc' , functionalComponentData , null ) ;
131+ funcPayloadMix . componentData = {
132+ ...funcPayloadMix . componentData ,
133+ hooksState : { count : 0 } ,
134+ hooksIndex : [ 0 ] ,
135+ } ;
136+ mixPayload . children . push ( deepCopy ( funcPayloadMix ) ) ;
137+
138+ // Outer Class Comp
139+ let classPayloadMix = new Tree ( { count : 0 } , 'IncrementClass' , classComponentData , null ) ;
140+ classPayloadMix . componentData = {
141+ ...classPayloadMix . componentData ,
142+ state : { count : 0 } ,
143+ index : 3 ,
144+ } ;
145+ mixPayload . children . push ( deepCopy ( classPayloadMix ) ) ;
146+
147+ // Inner Func Comp
148+ funcPayloadMix = new Tree ( { count : 0 } , 'IncrementFunc' , functionalComponentData , null ) ;
149+ funcPayloadMix . componentData = {
150+ ...funcPayloadMix . componentData ,
151+ hooksState : { count : 0 } ,
152+ hooksIndex : [ 1 ] ,
153+ } ;
154+ funcPayloadMix . name = 'IncrementFunc1' ;
155+ mixPayload . children [ 0 ] . children . push ( deepCopy ( funcPayloadMix ) ) ;
156+
157+ // Inner Class Comp
158+ classPayloadMix = new Tree ( { count : 0 } , 'IncrementClass' , classComponentData , null ) ;
159+ classPayloadMix . componentData = {
160+ ...classPayloadMix . componentData ,
161+ state : { count : 0 } ,
162+ index : 2 ,
163+ } ;
164+ mixPayload . children [ 0 ] . children . push ( deepCopy ( classPayloadMix ) ) ;
165+
166+ // console.dir(mixPayload, { depth: null });
167+
168+ function deepCopy ( obj ) {
169+ if ( obj === null || typeof obj !== 'object' ) {
170+ return obj ;
171+ }
172+ const copy = Array . isArray ( obj ) ? [ ] : { } ;
173+ Object . keys ( obj ) . forEach ( ( key ) => {
174+ if ( typeof obj [ key ] === 'function' ) {
175+ copy [ key ] = obj [ key ] ;
176+ } else {
177+ copy [ key ] = deepCopy ( obj [ key ] ) ;
178+ }
179+ } ) ;
180+ return copy ;
181+ }
0 commit comments