@@ -2,27 +2,19 @@ import linkFiberInitialization from '../routers/linkFiber';
2
2
import { Snapshot , Status , FiberRoot } from '../types/backendTypes' ;
3
3
import Tree from '../models/tree' ;
4
4
import { DevTools } from '../types/linkFiberTypes' ;
5
- import updateAndSendSnapShotTree from '../routers/snapShot' ;
6
- import throttle from '../controllers/throttle' ;
7
- import createTree from '../controllers/createTree/createTree' ;
8
- import routes from '../models/routes' ;
5
+
9
6
import { JSDOM } from 'jsdom' ;
10
7
import path from 'path' ;
11
8
import fs from 'fs' ;
12
9
import componentActionsRecord from '../models/masterState' ;
13
10
import {
14
- functionalComponent ,
15
11
classComponent ,
16
12
root ,
17
13
rootPayload ,
18
14
classPayload ,
19
15
updateClassPayload ,
20
16
} from './linkFiber-testcases' ;
21
17
import timeJumpInitialization from '../controllers/timeJump' ;
22
- // import Increment from './Increment'; // functional component
23
- // import React from 'react';
24
- // import { createRoot } from 'react-dom/client';
25
- // import { FunctionComponent } from '../types/backendTypes';
26
18
27
19
describe ( 'linkFiber' , ( ) => {
28
20
let snapshot : Snapshot ;
@@ -42,15 +34,6 @@ describe('linkFiber', () => {
42
34
global . window = dom . window ;
43
35
global . document = dom . window . _document ;
44
36
45
- // Append functional component on browser:
46
- // const domNode = document.getElementById('root');
47
- // const root = await createRoot(domNode);
48
- // root.render(<Increment />);
49
-
50
- // Get the fiber root object
51
- // fiberRoot = root._internalRoot;
52
-
53
- // fiberRoot.current = { ...fiberRoot.current, elementType: Increment, tag: FunctionComponent };
54
37
// Initialize Fiber Root:
55
38
fiberRoot = { current : root } ;
56
39
} ) ;
@@ -60,12 +43,6 @@ describe('linkFiber', () => {
60
43
dom . window . close ( ) ;
61
44
} ) ;
62
45
63
- beforeEach ( ( ) => {
64
- // routes = new Routes();
65
- // window.history.replaceState = jest.fn();
66
- // window.history.pushState = jest.fn();
67
- } ) ;
68
-
69
46
beforeEach ( ( ) => {
70
47
// Create snapshot and mode objects
71
48
snapshot = {
@@ -231,6 +208,21 @@ describe('linkFiber', () => {
231
208
} ) ;
232
209
233
210
describe ( 'mode unit tests' , ( ) => {
211
+ it ( 'should not send snapshot if mode is jumping & not navigating' , async ( ) => {
212
+ // When first initialize linkFiber, should not have the update class payload
213
+ fiberRoot = { current : classComponent } ;
214
+ await new Promise ( linkFiberDelayed ) ;
215
+ mockPostMessage . mockClear ( ) ;
216
+
217
+ // Simulate jumping and navigating
218
+ mode . jumping = true ;
219
+ await new Promise ( ( resolve ) =>
220
+ setTimeout ( async ( ) => resolve ( await devTools . onCommitFiberRoot ( 0 , fiberRoot , 'high' ) ) , 75 ) ,
221
+ ) ;
222
+ // During jumping &/or navigating, should not post any message/snapshot to front end
223
+ expect ( mockPostMessage ) . not . toHaveBeenCalled ( ) ;
224
+ } ) ;
225
+
234
226
it ( 'should update react fiber tree based on the payload from frontend when mode is navigating' , async ( ) => {
235
227
// When first initialize linkFiber, should not have the update class payload
236
228
fiberRoot = { current : classComponent } ;
@@ -246,28 +238,26 @@ describe('linkFiber', () => {
246
238
247
239
// Simulate jumping and navigating
248
240
mode . jumping = true ;
249
- console . log ( updateClassPayload . children [ 0 ] ) ;
250
241
mode . navigating = ( ) => timeJump ( updateClassPayload ) ;
251
242
await new Promise ( ( resolve ) =>
252
243
setTimeout ( async ( ) => resolve ( await devTools . onCommitFiberRoot ( 0 , fiberRoot , 'high' ) ) , 75 ) ,
253
244
) ;
254
- console . log ( 'MODE UNIT TEST' , componentActionsRecord . getAllComponents ( ) [ 0 ] . state . toString ( ) ) ;
255
245
// During jumping &/or navigating, should not post any message/snapshot to front end
256
246
expect ( mockPostMessage ) . not . toHaveBeenCalled ( ) ;
257
247
258
248
// After navigate, react application should have updateClassPayload
259
- // mode.jumping = false;
260
- // await new Promise((resolve) =>
261
- // setTimeout(async () => resolve(await devTools.onCommitFiberRoot(0, fiberRoot, 'high')), 75),
262
- // );
263
- // expect(mockPostMessage).toHaveBeenCalledTimes(1);
264
- // expect(mockPostMessage).toHaveBeenCalledWith(
265
- // {
266
- // action: 'recordSnap',
267
- // payload: updateClassPayload,
268
- // },
269
- // '*',
270
- // );
249
+ mode . jumping = false ;
250
+ await new Promise ( ( resolve ) =>
251
+ setTimeout ( async ( ) => resolve ( await devTools . onCommitFiberRoot ( 0 , fiberRoot , 'high' ) ) , 75 ) ,
252
+ ) ;
253
+ expect ( mockPostMessage ) . toHaveBeenCalledTimes ( 1 ) ;
254
+ expect ( mockPostMessage ) . toHaveBeenCalledWith (
255
+ {
256
+ action : 'recordSnap' ,
257
+ payload : updateClassPayload ,
258
+ } ,
259
+ '*' ,
260
+ ) ;
271
261
} ) ;
272
262
} ) ;
273
263
} ) ;
0 commit comments