@@ -55,7 +55,7 @@ describe('master tree tests', () => {
55
55
let mockSiblingNode : Fiber ;
56
56
let mockSiblingTree : Tree ;
57
57
58
- beforeEach ( ( ) => {
58
+ beforeEach ( ( ) => {
59
59
// create tree root:
60
60
treeRoot = new Tree ( 'root' , 'root' ) ;
61
61
// create a mock Fiber node with relevant properties
@@ -77,7 +77,6 @@ describe('master tree tests', () => {
77
77
componentActionsRecord . clear ( ) ;
78
78
} ) ;
79
79
80
-
81
80
describe ( 'createTree Unit test' , ( ) => {
82
81
describe ( 'Filter components that are from NextJS, Remix or not from allowed component types' , ( ) => {
83
82
it ( 'should return a Tree if we pass in a empty fiber node' , ( ) => {
@@ -113,7 +112,7 @@ describe('master tree tests', () => {
113
112
}
114
113
}
115
114
} ) ;
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' , ( ) => {
117
116
( mockChildTree . componentData as ComponentData ) . index = 0 ;
118
117
( mockSiblingTree . componentData as ComponentData ) . hooksIndex = [ 1 ] ;
119
118
treeRoot . children . push ( mockChildTree ) ;
@@ -167,22 +166,22 @@ describe('master tree tests', () => {
167
166
// Assign mock properties to the child node
168
167
mockChildNode . memoizedProps = memoizedProps ;
169
168
( mockChildTree . componentData as ComponentData ) . props = props ;
170
-
169
+
171
170
// Set up an isolated copy of the root tree
172
171
const isolatedTreeRoot = deepCopy ( treeRoot ) ;
173
172
isolatedTreeRoot . children . push ( mockChildTree ) ;
174
-
173
+
175
174
// Generate the tree
176
175
const tree = createTree ( mockChildNode ) ;
177
-
176
+
178
177
// Debugging: Log actual and expected tree for comparison
179
178
console . log ( 'Generated Tree:' , JSON . stringify ( tree , null , 2 ) ) ;
180
179
console . log ( 'Expected Tree:' , JSON . stringify ( isolatedTreeRoot , null , 2 ) ) ;
181
-
180
+
182
181
// Perform the assertion
183
182
expect ( tree ) . toEqual ( isolatedTreeRoot ) ;
184
183
} ) ;
185
-
184
+
186
185
it ( 'should display React router props information' , ( ) => {
187
186
( mockSiblingTree . componentData as ComponentData ) = {
188
187
...( mockSiblingTree . componentData as ComponentData ) ,
@@ -249,41 +248,40 @@ describe('master tree tests', () => {
249
248
mockSiblingNode . memoizedProps = memoizedProps ;
250
249
const sibling1 = deepCopy ( mockSiblingNode ) ;
251
250
sibling1 . memoizedProps . name = 'sibling1' ;
252
-
251
+
253
252
// Link nodes
254
253
mockFiberNode . child = child1 ;
255
254
child1 . child = child2 ;
256
255
child2 . sibling = sibling1 ;
257
-
256
+
258
257
// Set up expected tree structure
259
258
const isolatedMockFiberTree = deepCopy ( mockFiberTree ) ;
260
259
( mockChildTree . componentData as ComponentData ) . props = props ;
261
-
260
+
262
261
const childTree1 = deepCopy ( mockChildTree ) ;
263
262
childTree1 . name = 'IncrementClass1' ;
264
263
( childTree1 . componentData as ComponentData ) . props . name = 'child1' ;
265
264
( childTree1 . componentData as ComponentData ) . index = 0 ;
266
-
265
+
267
266
const childTree2 = deepCopy ( mockChildTree ) ;
268
267
childTree2 . name = 'IncrementClass2' ;
269
268
( childTree2 . componentData as ComponentData ) . props . name = 'child2' ;
270
269
( childTree2 . componentData as ComponentData ) . index = 1 ;
271
-
270
+
272
271
const siblingTree1 = deepCopy ( mockSiblingTree ) ;
273
272
siblingTree1 . name = 'IncrementFunc' ;
274
273
( siblingTree1 . componentData as ComponentData ) . props . name = 'sibling1' ;
275
274
( siblingTree1 . componentData as ComponentData ) . hooksIndex = [ 2 ] ;
276
-
275
+
277
276
isolatedMockFiberTree . children [ 0 ] . children = [ childTree1 ] ;
278
277
childTree1 . children . push ( childTree2 , siblingTree1 ) ;
279
-
278
+
280
279
// Generate the actual tree
281
280
const tree = createTree ( mockFiberNode ) ;
282
-
281
+
283
282
// Assertions
284
283
expect ( tree ) . toEqual ( isolatedMockFiberTree ) ;
285
284
} ) ;
286
-
287
285
} ) ;
288
286
describe ( 'Display component states information' , ( ) => {
289
287
const stateNode = {
@@ -340,20 +338,19 @@ describe('master tree tests', () => {
340
338
queue : { } , // Required for useState hooks
341
339
next : null ,
342
340
} ;
343
-
341
+
344
342
// Generate the tree
345
343
const tree = createTree ( mockSiblingNode ) ;
346
-
344
+
347
345
// Set up expected tree structure
348
346
mockSiblingTree . state = functionalState ;
349
347
( mockSiblingTree . componentData as ComponentData ) . hooksState = functionalState ;
350
348
( mockSiblingTree . componentData as ComponentData ) . hooksIndex = [ 0 ] ;
351
349
treeRoot . children . push ( mockSiblingTree ) ;
352
-
350
+
353
351
// Assertions
354
352
expect ( tree ) . toBe ( treeRoot ) ;
355
353
} ) ;
356
-
357
354
358
355
it ( 'should keep track of class state index' , ( ) => {
359
356
// Construct Fiber Node (root => FiberNode => child1 => child 2 & 3)
@@ -400,30 +397,29 @@ describe('master tree tests', () => {
400
397
expect ( tree ) . toEqual ( treeRoot ) ;
401
398
} ) ;
402
399
403
- xit ( 'should display functional state information' , ( ) => {
400
+ it ( 'should display functional state information' , ( ) => {
404
401
// Set up mock Fiber node for functional state
405
402
mockSiblingNode . memoizedState = {
406
403
memoizedState : { dummy : 'dummy' } ,
407
404
queue : { } , // Required for useState hooks
408
405
next : null ,
409
406
} ;
410
-
407
+
411
408
// Create tree
412
409
const tree = createTree ( mockSiblingNode ) ;
413
-
410
+
414
411
// Set up expected tree structure
415
412
mockSiblingTree . state = functionalState ;
416
413
( mockSiblingTree . componentData as ComponentData ) . hooksState = functionalState ;
417
414
( mockSiblingTree . componentData as ComponentData ) . hooksIndex = [ 0 ] ; // Single hook index
418
415
mockSiblingTree . name = 'IncrementFunc' ; // Ensure name matches
419
416
treeRoot . children . push ( mockSiblingTree ) ;
420
-
417
+
421
418
// Compare the actual tree with the expected tree
422
419
expect ( tree ) . toEqual ( treeRoot ) ;
423
420
} ) ;
424
-
425
421
426
- xit ( 'should keep track of functional state index' , ( ) => {
422
+ it ( 'should keep track of functional state index' , ( ) => {
427
423
// Construct Fiber Node (root => FiberNode => sibling1 => sibling 2 & 3)
428
424
// sibling 3 will have 2 states
429
425
mockSiblingNode . memoizedState = memoizedState ;
@@ -459,10 +455,6 @@ describe('master tree tests', () => {
459
455
expect ( tree ) . toEqual ( mockFiberTree ) ;
460
456
} ) ;
461
457
} ) ;
462
-
463
- describe ( 'Replace fromLinkFiber class value' , ( ) => {
464
- xit ( 'NEED UNDERSTANDING THE PURPOSE OF FROMLINKFIBER FOR FRONTEND, currently unable to replicate DOMTokenList instance' , ( ) => { } ) ;
465
- } ) ;
466
458
} ) ;
467
459
468
460
describe ( 'Tree unit test' , ( ) => {
@@ -567,100 +559,50 @@ describe('master tree tests', () => {
567
559
expect ( nextChild1 . name ) . toBe ( 'child2' ) ;
568
560
expect ( nextChild2 . name ) . toBe ( 'child3' ) ;
569
561
} ) ;
570
-
571
- xit ( 'should be able to add multiple children and sibilings' , ( ) => { } ) ;
572
562
} ) ;
573
- } ) ;
574
563
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
+ } ) ;
585
574
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
+ } ) ;
598
588
} ) ;
599
- } ) ;
600
589
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
+ } ) ;
609
600
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
+ } ) ;
614
606
} ) ;
615
607
} ) ;
616
608
} ) ;
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