Skip to content

Commit 751c65b

Browse files
committed
working on testing display props for multiple components
1 parent be6aa7c commit 751c65b

File tree

6 files changed

+246
-113
lines changed

6 files changed

+246
-113
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function deepCopy<T>(obj: T): T {
2+
if (obj === null || typeof obj !== 'object') {
3+
return obj;
4+
}
5+
const copy = Array.isArray(obj) ? [] : {};
6+
Object.keys(obj).forEach((key) => {
7+
if (typeof obj[key] === 'function') {
8+
copy[key] = obj[key];
9+
} else {
10+
copy[key] = deepCopy(obj[key]);
11+
}
12+
});
13+
return copy as T;
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Fiber } from '../../types/backendTypes';
2+
import { FunctionComponent } from '../../types/backendTypes';
3+
4+
// -------------------TEST CASE FOR COMPONENT WITH PROPS-----------------------
5+
export const Router: Fiber = {
6+
tag: FunctionComponent,
7+
elementType: { name: 'Router' },
8+
sibling: null,
9+
stateNode: null,
10+
child: null,
11+
memoizedState: {
12+
memoizedState: null,
13+
queue: null,
14+
},
15+
memoizedProps: { location: { pathname: '/tictactoe' } },
16+
actualDuration: 1,
17+
actualStartTime: 2,
18+
selfBaseDuration: 3,
19+
treeBaseDuration: 4,
20+
_debugHookTypes: ['useContext', 'useMemo', 'useMemo'],
21+
};
22+
export const RenderedRoute: Fiber = {
23+
tag: FunctionComponent,
24+
elementType: { name: 'RenderedRoute' },
25+
sibling: null,
26+
stateNode: null,
27+
child: null,
28+
memoizedState: null,
29+
memoizedProps: { match: { pathname: '/tictactoe' } },
30+
actualDuration: 1,
31+
actualStartTime: 2,
32+
selfBaseDuration: 3,
33+
treeBaseDuration: 4,
34+
_debugHookTypes: ['useContext'],
35+
};

src/backend/__tests__/ignore/linkFiber-testcases.ts renamed to src/backend/__tests__/ignore/stateComponents-testcases.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import Tree from '../../models/tree';
22
import routes from '../../models/routes';
3-
import { ComponentData, Fiber, FiberRoot } from '../../types/backendTypes';
3+
import { ComponentData, Fiber } from '../../types/backendTypes';
44
import { FunctionComponent, ClassComponent, HostRoot } from '../../types/backendTypes';
55
import IncrementFunc from './IncrementFunc';
66
import IncrementClass from './IncrementClass';
7-
import { transformSync } from '@babel/core';
7+
import componentActionsRecord from '../../models/masterState';
8+
import deepCopy from './deepCopy';
89

910
// ----------------------------TEST CASES FOR ROOT------------------------------
1011
export const root: Fiber = {
@@ -60,6 +61,7 @@ const functionalComponentData: ComponentData = {
6061
state: null,
6162
};
6263

64+
componentActionsRecord.clear();
6365
export const functionalPayload: Tree = new Tree('root', 'root');
6466
functionalPayload.route = rootPayload.route;
6567
functionalPayload.addChild({ count: 0 }, 'IncrementFunc', functionalComponentData, null);
@@ -101,11 +103,12 @@ const classComponentData: ComponentData = {
101103
state: { count: 0 },
102104
};
103105

106+
componentActionsRecord.clear();
104107
export const classPayload = new Tree('root', 'root');
105108
classPayload.route = rootPayload.route;
106-
107109
classPayload.addChild({ count: 0 }, 'IncrementClass', classComponentData, null);
108110

111+
componentActionsRecord.clear();
109112
export const updateClassPayload = new Tree('root', 'root');
110113
updateClassPayload.route = rootPayload.route;
111114
updateClassPayload.addChild(
@@ -116,6 +119,7 @@ updateClassPayload.addChild(
116119
);
117120

118121
// -----------------------TEST CASE FOR MIX OF COMPONENTS-----------------------
122+
componentActionsRecord.clear();
119123
export const mixComponents: Fiber = deepCopy(root);
120124
mixComponents.child = deepCopy(functionalComponent);
121125
mixComponents.sibling = deepCopy(classComponent);
@@ -164,18 +168,3 @@ classPayloadMix.componentData = {
164168
mixPayload.children[0].children.push(deepCopy(classPayloadMix));
165169

166170
// 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-
}

src/backend/__tests__/linkFiber.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
functionalPayload,
1212
mixComponents,
1313
mixPayload,
14-
} from './ignore/linkFiber-testcases';
14+
} from './ignore/stateComponents-testcases';
1515
import { Snapshot, Status, FiberRoot } from '../types/backendTypes';
1616
import Tree from '../models/tree';
1717
import { DevTools } from '../types/linkFiberTypes';

0 commit comments

Comments
 (0)