@@ -55,7 +55,7 @@ describe('master tree tests', () => {
5555 let mockSiblingNode : Fiber ;
5656 let mockSiblingTree : Tree ;
5757
58- beforeEach ( ( ) => {
58+ beforeEach ( ( ) => {
5959 // create tree root:
6060 treeRoot = new Tree ( 'root' , 'root' ) ;
6161 // create a mock Fiber node with relevant properties
@@ -77,7 +77,6 @@ describe('master tree tests', () => {
7777 componentActionsRecord . clear ( ) ;
7878 } ) ;
7979
80-
8180 describe ( 'createTree Unit test' , ( ) => {
8281 describe ( 'Filter components that are from NextJS, Remix or not from allowed component types' , ( ) => {
8382 it ( 'should return a Tree if we pass in a empty fiber node' , ( ) => {
@@ -113,7 +112,7 @@ describe('master tree tests', () => {
113112 }
114113 }
115114 } ) ;
116- xit ( 'should filter out NextJS & Remix default components with children and/or siblings' , ( ) => {
115+ it ( 'should filter out NextJS & Remix default components with children and/or siblings' , ( ) => {
117116 ( mockChildTree . componentData as ComponentData ) . index = 0 ;
118117 ( mockSiblingTree . componentData as ComponentData ) . hooksIndex = [ 1 ] ;
119118 treeRoot . children . push ( mockChildTree ) ;
@@ -167,22 +166,22 @@ describe('master tree tests', () => {
167166 // Assign mock properties to the child node
168167 mockChildNode . memoizedProps = memoizedProps ;
169168 ( mockChildTree . componentData as ComponentData ) . props = props ;
170-
169+
171170 // Set up an isolated copy of the root tree
172171 const isolatedTreeRoot = deepCopy ( treeRoot ) ;
173172 isolatedTreeRoot . children . push ( mockChildTree ) ;
174-
173+
175174 // Generate the tree
176175 const tree = createTree ( mockChildNode ) ;
177-
176+
178177 // Debugging: Log actual and expected tree for comparison
179178 console . log ( 'Generated Tree:' , JSON . stringify ( tree , null , 2 ) ) ;
180179 console . log ( 'Expected Tree:' , JSON . stringify ( isolatedTreeRoot , null , 2 ) ) ;
181-
180+
182181 // Perform the assertion
183182 expect ( tree ) . toEqual ( isolatedTreeRoot ) ;
184183 } ) ;
185-
184+
186185 it ( 'should display React router props information' , ( ) => {
187186 ( mockSiblingTree . componentData as ComponentData ) = {
188187 ...( mockSiblingTree . componentData as ComponentData ) ,
@@ -249,41 +248,40 @@ describe('master tree tests', () => {
249248 mockSiblingNode . memoizedProps = memoizedProps ;
250249 const sibling1 = deepCopy ( mockSiblingNode ) ;
251250 sibling1 . memoizedProps . name = 'sibling1' ;
252-
251+
253252 // Link nodes
254253 mockFiberNode . child = child1 ;
255254 child1 . child = child2 ;
256255 child2 . sibling = sibling1 ;
257-
256+
258257 // Set up expected tree structure
259258 const isolatedMockFiberTree = deepCopy ( mockFiberTree ) ;
260259 ( mockChildTree . componentData as ComponentData ) . props = props ;
261-
260+
262261 const childTree1 = deepCopy ( mockChildTree ) ;
263262 childTree1 . name = 'IncrementClass1' ;
264263 ( childTree1 . componentData as ComponentData ) . props . name = 'child1' ;
265264 ( childTree1 . componentData as ComponentData ) . index = 0 ;
266-
265+
267266 const childTree2 = deepCopy ( mockChildTree ) ;
268267 childTree2 . name = 'IncrementClass2' ;
269268 ( childTree2 . componentData as ComponentData ) . props . name = 'child2' ;
270269 ( childTree2 . componentData as ComponentData ) . index = 1 ;
271-
270+
272271 const siblingTree1 = deepCopy ( mockSiblingTree ) ;
273272 siblingTree1 . name = 'IncrementFunc' ;
274273 ( siblingTree1 . componentData as ComponentData ) . props . name = 'sibling1' ;
275274 ( siblingTree1 . componentData as ComponentData ) . hooksIndex = [ 2 ] ;
276-
275+
277276 isolatedMockFiberTree . children [ 0 ] . children = [ childTree1 ] ;
278277 childTree1 . children . push ( childTree2 , siblingTree1 ) ;
279-
278+
280279 // Generate the actual tree
281280 const tree = createTree ( mockFiberNode ) ;
282-
281+
283282 // Assertions
284283 expect ( tree ) . toEqual ( isolatedMockFiberTree ) ;
285284 } ) ;
286-
287285 } ) ;
288286 describe ( 'Display component states information' , ( ) => {
289287 const stateNode = {
@@ -340,20 +338,19 @@ describe('master tree tests', () => {
340338 queue : { } , // Required for useState hooks
341339 next : null ,
342340 } ;
343-
341+
344342 // Generate the tree
345343 const tree = createTree ( mockSiblingNode ) ;
346-
344+
347345 // Set up expected tree structure
348346 mockSiblingTree . state = functionalState ;
349347 ( mockSiblingTree . componentData as ComponentData ) . hooksState = functionalState ;
350348 ( mockSiblingTree . componentData as ComponentData ) . hooksIndex = [ 0 ] ;
351349 treeRoot . children . push ( mockSiblingTree ) ;
352-
350+
353351 // Assertions
354352 expect ( tree ) . toBe ( treeRoot ) ;
355353 } ) ;
356-
357354
358355 it ( 'should keep track of class state index' , ( ) => {
359356 // Construct Fiber Node (root => FiberNode => child1 => child 2 & 3)
@@ -400,30 +397,29 @@ describe('master tree tests', () => {
400397 expect ( tree ) . toEqual ( treeRoot ) ;
401398 } ) ;
402399
403- xit ( 'should display functional state information' , ( ) => {
400+ it ( 'should display functional state information' , ( ) => {
404401 // Set up mock Fiber node for functional state
405402 mockSiblingNode . memoizedState = {
406403 memoizedState : { dummy : 'dummy' } ,
407404 queue : { } , // Required for useState hooks
408405 next : null ,
409406 } ;
410-
407+
411408 // Create tree
412409 const tree = createTree ( mockSiblingNode ) ;
413-
410+
414411 // Set up expected tree structure
415412 mockSiblingTree . state = functionalState ;
416413 ( mockSiblingTree . componentData as ComponentData ) . hooksState = functionalState ;
417414 ( mockSiblingTree . componentData as ComponentData ) . hooksIndex = [ 0 ] ; // Single hook index
418415 mockSiblingTree . name = 'IncrementFunc' ; // Ensure name matches
419416 treeRoot . children . push ( mockSiblingTree ) ;
420-
417+
421418 // Compare the actual tree with the expected tree
422419 expect ( tree ) . toEqual ( treeRoot ) ;
423420 } ) ;
424-
425421
426- xit ( 'should keep track of functional state index' , ( ) => {
422+ it ( 'should keep track of functional state index' , ( ) => {
427423 // Construct Fiber Node (root => FiberNode => sibling1 => sibling 2 & 3)
428424 // sibling 3 will have 2 states
429425 mockSiblingNode . memoizedState = memoizedState ;
@@ -459,10 +455,6 @@ describe('master tree tests', () => {
459455 expect ( tree ) . toEqual ( mockFiberTree ) ;
460456 } ) ;
461457 } ) ;
462-
463- describe ( 'Replace fromLinkFiber class value' , ( ) => {
464- xit ( 'NEED UNDERSTANDING THE PURPOSE OF FROMLINKFIBER FOR FRONTEND, currently unable to replicate DOMTokenList instance' , ( ) => { } ) ;
465- } ) ;
466458 } ) ;
467459
468460 describe ( 'Tree unit test' , ( ) => {
@@ -567,100 +559,50 @@ describe('master tree tests', () => {
567559 expect ( nextChild1 . name ) . toBe ( 'child2' ) ;
568560 expect ( nextChild2 . name ) . toBe ( 'child3' ) ;
569561 } ) ;
570-
571- xit ( 'should be able to add multiple children and sibilings' , ( ) => { } ) ;
572562 } ) ;
573- } ) ;
574563
575- describe ( 'createComponentActionsRecord unit test' , ( ) => {
576- it ( 'should save a new component action record if the Fiber node is a stateful class component' , ( ) => {
577- mockFiberNode . tag = ClassComponent ;
578- mockFiberNode . stateNode = {
579- state : { counter : 0 } , // a mock state object
580- setState : jest . fn ( ) , // a mock setState method
581- } ;
582- createComponentActionsRecord ( mockFiberNode ) ;
583- expect ( componentActionsRecord . getComponentByIndex ( 0 ) ) . toBe ( mockFiberNode . stateNode ) ;
584- } ) ;
564+ describe ( 'createComponentActionsRecord unit test' , ( ) => {
565+ it ( 'should save a new component action record if the Fiber node is a stateful class component' , ( ) => {
566+ mockFiberNode . tag = ClassComponent ;
567+ mockFiberNode . stateNode = {
568+ state : { counter : 0 } , // a mock state object
569+ setState : jest . fn ( ) , // a mock setState method
570+ } ;
571+ createComponentActionsRecord ( mockFiberNode ) ;
572+ expect ( componentActionsRecord . getComponentByIndex ( 0 ) ) . toBe ( mockFiberNode . stateNode ) ;
573+ } ) ;
585574
586- it ( 'should save a new component action record if the Fiber node is a stateful class component with props' , ( ) => {
587- mockFiberNode . tag = ClassComponent ;
588- // a mock state object
589- mockFiberNode . stateNode = {
590- state : { counter : 0 } ,
591- props : { start : 0 } ,
592- setState : jest . fn ( ) , // a mock setState method
593- } ;
594- createComponentActionsRecord ( mockFiberNode ) ;
595- expect ( componentActionsRecord . getComponentByIndex ( 0 ) ) . toMatchObject ( {
596- props : mockFiberNode . stateNode . props ,
597- state : mockFiberNode . stateNode . state ,
575+ it ( 'should save a new component action record if the Fiber node is a stateful class component with props' , ( ) => {
576+ mockFiberNode . tag = ClassComponent ;
577+ // a mock state object
578+ mockFiberNode . stateNode = {
579+ state : { counter : 0 } ,
580+ props : { start : 0 } ,
581+ setState : jest . fn ( ) , // a mock setState method
582+ } ;
583+ createComponentActionsRecord ( mockFiberNode ) ;
584+ expect ( componentActionsRecord . getComponentByIndex ( 0 ) ) . toMatchObject ( {
585+ props : mockFiberNode . stateNode . props ,
586+ state : mockFiberNode . stateNode . state ,
587+ } ) ;
598588 } ) ;
599- } ) ;
600589
601- it ( 'should save a new component action record if the Fiber node is a functional component with state' , ( ) => {
602- mockFiberNode . tag = FunctionComponent ;
603- mockFiberNode . memoizedState = {
604- queue : [ { } , { state : { value : 'test' } } ] , // a mock memoizedState object
605- } ;
606- createComponentActionsRecord ( mockFiberNode ) ;
607- expect ( componentActionsRecord . getComponentByIndex ( 0 ) ) . toBe ( mockFiberNode . memoizedState . queue ) ;
608- } ) ;
590+ it ( 'should save a new component action record if the Fiber node is a functional component with state' , ( ) => {
591+ mockFiberNode . tag = FunctionComponent ;
592+ mockFiberNode . memoizedState = {
593+ queue : [ { } , { state : { value : 'test' } } ] , // a mock memoizedState object
594+ } ;
595+ createComponentActionsRecord ( mockFiberNode ) ;
596+ expect ( componentActionsRecord . getComponentByIndex ( 0 ) ) . toBe (
597+ mockFiberNode . memoizedState . queue ,
598+ ) ;
599+ } ) ;
609600
610- it ( 'should not save a new component action record if the Fiber node is not a relevant component type' , ( ) => {
611- mockFiberNode . tag = 4 ; // HostRoot
612- createComponentActionsRecord ( mockFiberNode ) ;
613- expect ( componentActionsRecord . getAllComponents ( ) ) . toHaveLength ( 0 ) ;
601+ it ( 'should not save a new component action record if the Fiber node is not a relevant component type' , ( ) => {
602+ mockFiberNode . tag = 4 ; // HostRoot
603+ createComponentActionsRecord ( mockFiberNode ) ;
604+ expect ( componentActionsRecord . getAllComponents ( ) ) . toHaveLength ( 0 ) ;
605+ } ) ;
614606 } ) ;
615607 } ) ;
616608} ) ;
617-
618- // WE DONT HAVE PROPS IN STATENODE AND WE DON"T STORE PROPS IN COMPONENT ACTIONS RECORD
619- // it('should save multiple component action records when called multiple times with different Fiber nodes', () => {
620- // mockFiberNode.tag = 1; // ClassComponent
621- // mockFiberNode.stateNode = {
622- // state: { counter: 0 },
623- // props: { start: 0 }, // a mock state object
624- // setState: jest.fn(), // a mock setState method
625- // };
626- // createComponentActionsRecord(mockFiberNode);
627- // expect(componentActionsRecord.getComponentByIndex(0)).toMatchObject({
628- // state: mockFiberNode.stateNode.state,
629- // props: mockFiberNode.stateNode.props,
630- // });
631-
632- // const mockFiberNode2: Fiber = { ...mockFiberNode };
633- // mockFiberNode2.stateNode.props = { start: 1 }; // a different mock memoizedProps object
634- // createComponentActionsRecord(mockFiberNode2);
635- // expect(componentActionsRecord.getComponentByIndex(1)).toMatchObject({
636- // state: mockFiberNode2.stateNode.state,
637- // props: mockFiberNode2.stateNode.props,
638- // });
639- // });
640-
641- // it('should return the correct hooks array for a given component index', () => {
642- // // create a mock component action record
643- // });
644-
645-
646- // beforeEach(() => {
647- // // create tree root:
648- // treeRoot = new Tree('root', 'root');
649- // // create a mock Fiber node with relevant properties
650- // mockFiberNode = { ...root, tag: IndeterminateComponent };
651- // mockFiberTree = new Tree('root', 'root');
652- // mockFiberTree.addChild('stateless', 'nameless', mockComponentData, null);
653-
654- // // create a mock child Fiber node with relevant properties for class component
655- // mockChildNode = deepCopy(classComponent);
656- // // Since payload will have a root then the component, need to extract the child component
657- // mockChildTree = deepCopy(classPayload.children[0]);
658-
659- // // create a mock sibling Fiber node with relevant properties for class component
660- // mockSiblingNode = deepCopy(functionalComponent);
661- // // Since payload will have a root then the component, need to extract the child component
662- // mockSiblingTree = deepCopy(functionalPayload.children[0]);
663-
664- // // clear the saved component actions record
665- // componentActionsRecord.clear();
666- // });
0 commit comments