@@ -3,6 +3,7 @@ import { Fiber } from '../types/backendTypes';
3
3
import componentActionsRecord from '../models/masterState' ;
4
4
import createTree from '../controllers/createTree/createTree' ;
5
5
import Tree from '../models/tree' ;
6
+ import React , { useState } from 'react' ;
6
7
import {
7
8
allowedComponentTypes ,
8
9
nextJSDefaultComponent ,
@@ -14,6 +15,17 @@ describe('master tree tests', () => {
14
15
let mockFiberNode : Fiber ;
15
16
let mockSiblingNode : Fiber ;
16
17
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
+
17
29
beforeEach ( ( ) => {
18
30
// create a mock Fiber node with relevant properties
19
31
mockFiberNode = {
@@ -31,23 +43,26 @@ describe('master tree tests', () => {
31
43
_debugHookTypes : [ ] ,
32
44
} ;
33
45
46
+ // create a mock child Fiber node with relevant properties for class component
34
47
mockChildNode = {
35
48
...mockFiberNode ,
36
49
tag : 1 ,
37
50
elementType : { name : 'child' } ,
38
51
stateNode : { state : { counter : 0 } , props : { start : 0 } } ,
39
52
} ;
53
+
54
+ // create a mock sibling Fiber node with relevant properties for class component
40
55
mockSiblingNode = {
41
56
...mockFiberNode ,
42
57
tag : 0 ,
43
- elementType : { name : 'sibling' } ,
58
+ elementType : MockFunctionalComponent ,
44
59
memoizedState : { memoizedState : 1 , queue : [ { } , { state : { value : 'test' } } ] , next : null } ,
45
60
} ;
46
61
// clear the saved component actions record
47
62
componentActionsRecord . clear ( ) ;
48
63
} ) ;
49
64
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' , ( ) => {
51
66
const tree = createTree ( mockFiberNode ) ;
52
67
const children = tree . children ;
53
68
@@ -58,7 +73,7 @@ describe('master tree tests', () => {
58
73
expect ( children [ 0 ] . state ) . toEqual ( 'stateless' ) ;
59
74
} ) ;
60
75
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' , ( ) => {
62
77
for ( let name of nextJSDefaultComponent ) {
63
78
mockFiberNode . elementType . name = name ;
64
79
const tree = createTree ( mockFiberNode ) ;
@@ -76,19 +91,22 @@ describe('master tree tests', () => {
76
91
const children = tree . children ;
77
92
const firstChild = children [ 0 ] ;
78
93
const secondChild = children [ 1 ] ;
94
+ console . log ( 'First Child' , firstChild ) ;
95
+ console . log ( 'Second Child' , secondChild ) ;
79
96
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 ) ;
81
99
}
82
100
} ) ;
83
101
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' , ( ) => {
85
103
for ( let name of remixDefaultComponents ) {
86
104
mockFiberNode . elementType . name = name ;
87
105
const tree = createTree ( mockFiberNode ) ;
88
106
}
89
107
} ) ;
90
108
91
- it ( 'should only traverse allowed components' , ( ) => {
109
+ xit ( 'should only traverse allowed components' , ( ) => {
92
110
for ( let tag of allowedComponentTypes ) {
93
111
mockFiberNode . elementType . tag = tag ;
94
112
const tree = createTree ( mockFiberNode ) ;
@@ -102,11 +120,11 @@ describe('master tree tests', () => {
102
120
} ) ;
103
121
} ) ;
104
122
105
- describe ( 'add sibling' , ( ) => { } ) ;
123
+ xdescribe ( 'add sibling' , ( ) => { } ) ;
106
124
107
- describe ( 'add children' , ( ) => { } ) ;
125
+ xdescribe ( 'add children' , ( ) => { } ) ;
108
126
109
- describe ( 'createComponentActionsRecord' , ( ) => {
127
+ xdescribe ( 'createComponentActionsRecord' , ( ) => {
110
128
it ( 'should save a new component action record if the Fiber node is a stateful class component' , ( ) => {
111
129
mockFiberNode . tag = 1 ; // ClassComponent
112
130
mockFiberNode . stateNode = {
0 commit comments