|
1 |
| -import timeJumpRequire from '../timeJump'; |
2 |
| -import componentActionsRecord from '../masterState'; |
3 |
| - |
4 |
| -class Component { |
5 |
| - mockfn: (state) => void; |
6 |
| - |
7 |
| - state: Record<string, unknown>; |
8 |
| - |
9 |
| - componentData: {}; |
10 |
| - |
11 |
| - constructor(mockfn) { |
12 |
| - this.mockfn = mockfn; |
13 |
| - } |
14 |
| - |
15 |
| - setState(state, func = () => {}) { |
16 |
| - this.mockfn(state); |
17 |
| - func(); |
18 |
| - } |
19 |
| -} |
20 |
| - |
21 |
| -class FiberNode { |
22 |
| - private state: Record<null, unknown>; |
23 |
| - |
24 |
| - children: FiberNode[]; |
25 |
| - |
26 |
| - component: Component; |
27 |
| - |
28 |
| - componentData: { |
29 |
| - index?: number; |
30 |
| - }; |
31 |
| - |
32 |
| - constructor(mockfn, state) { |
33 |
| - this.state = state; |
34 |
| - this.children = []; |
35 |
| - this.component = new Component(mockfn); |
36 |
| - this.componentData = { index: 0 }; |
37 |
| - } |
38 |
| -} |
39 |
| - |
40 |
| -describe('unit testing for timeJump.ts', () => { |
41 |
| - let timeJump: (target) => void; |
42 |
| - let snapShot: Record<string, FiberNode>; |
43 |
| - let mode; |
44 |
| - let mockFuncs; |
45 |
| - |
46 |
| - beforeEach(() => { |
47 |
| - const mockFunc = jest.fn(); |
48 |
| - mode = { jumping: false }; |
49 |
| - mockFuncs = []; |
50 |
| - for (let i = 0; i < 4; i += 1) mockFuncs.push(mockFunc); |
51 |
| - |
52 |
| - const tree: FiberNode = new FiberNode(mockFuncs[0], '*'); |
53 |
| - tree.children = [ |
54 |
| - new FiberNode(mockFuncs[1], '*'), |
55 |
| - new FiberNode(mockFuncs[2], '*'), |
56 |
| - new FiberNode(mockFuncs[3], '*'), |
57 |
| - ]; |
58 |
| - |
59 |
| - snapShot = { tree }; |
60 |
| - timeJump = timeJumpRequire(mode); |
61 |
| - }); |
62 |
| - test('calling the initial require should return a function', () => { |
63 |
| - const funcDef = timeJumpRequire; |
64 |
| - expect(typeof funcDef).toBe('function'); |
65 |
| - }); |
66 |
| - |
67 |
| - // xdescribe('testing iteration through snapshot tree', () => { |
68 |
| - // const states = ['root', 'firstChild', 'secondChild', 'thirdChild']; |
69 |
| - // const target = new FiberNode(null, states[0]); |
70 |
| - // target.children = [ |
71 |
| - // new FiberNode(null, states[1]), |
72 |
| - // new FiberNode(null, states[2]), |
73 |
| - // new FiberNode(null, states[3]), |
74 |
| - // ]; |
75 |
| - |
76 |
| - // target.componentData = {index: 0} |
77 |
| - |
78 |
| - // beforeEach((): void => { |
79 |
| - // timeJump(target); |
80 |
| - // }); |
81 |
| - // test('timeJump should call setState on each state in origin', () => { |
82 |
| - // mockFuncs.forEach(mockFunc => expect(mockFunc.mock.calls.length).toBe(1)); |
83 |
| - // }); |
84 |
| - |
85 |
| - // test('timeJump should pass target state to origin setState', () => { |
86 |
| - // mockFuncs.forEach((mockFunc, i) => expect(mockFunc.mock.calls[0][0]).toBe(states[i])); |
87 |
| - // }); |
88 |
| - // }); |
89 |
| - |
90 |
| - test('jumping mode should be set while timeJumping', () => { |
91 |
| - mode = { jumping: true }; |
92 |
| - const logMode = jest.fn(); |
93 |
| - logMode.mockImplementation(() => expect(mode.jumping).toBe(true)); |
94 |
| - |
95 |
| - snapShot.tree = new FiberNode(logMode, null); |
96 |
| - const target = new FiberNode(null, 'test'); |
97 |
| - logMode(target); |
98 |
| - expect(logMode).toHaveBeenCalled(); |
99 |
| - }); |
100 |
| -}); |
| 1 | +// import timeJumpRequire from '../timeJump'; |
| 2 | +// import componentActionsRecord from '../masterState'; |
| 3 | + |
| 4 | +// class Component { |
| 5 | +// mockfn: (state) => void; |
| 6 | + |
| 7 | +// state: Record<string, unknown>; |
| 8 | + |
| 9 | +// componentData: {}; |
| 10 | + |
| 11 | +// constructor(mockfn) { |
| 12 | +// this.mockfn = mockfn; |
| 13 | +// } |
| 14 | + |
| 15 | +// setState(state, func = () => {}) { |
| 16 | +// this.mockfn(state); |
| 17 | +// func(); |
| 18 | +// } |
| 19 | +// } |
| 20 | + |
| 21 | +// class FiberNode { |
| 22 | +// private state: Record<null, unknown>; |
| 23 | + |
| 24 | +// children: FiberNode[]; |
| 25 | + |
| 26 | +// component: Component; |
| 27 | + |
| 28 | +// componentData: { |
| 29 | +// index?: number; |
| 30 | +// }; |
| 31 | + |
| 32 | +// constructor(mockfn, state) { |
| 33 | +// this.state = state; |
| 34 | +// this.children = []; |
| 35 | +// this.component = new Component(mockfn); |
| 36 | +// this.componentData = { index: 0 }; |
| 37 | +// } |
| 38 | +// } |
| 39 | + |
| 40 | +// describe('unit testing for timeJump.ts', () => { |
| 41 | +// let timeJump: (target) => void; |
| 42 | +// let snapShot: Record<string, FiberNode>; |
| 43 | +// let mode; |
| 44 | +// let mockFuncs; |
| 45 | + |
| 46 | +// beforeEach(() => { |
| 47 | +// const mockFunc = jest.fn(); |
| 48 | +// mode = { jumping: false }; |
| 49 | +// mockFuncs = []; |
| 50 | +// for (let i = 0; i < 4; i += 1) mockFuncs.push(mockFunc); |
| 51 | + |
| 52 | +// const tree: FiberNode = new FiberNode(mockFuncs[0], '*'); |
| 53 | +// tree.children = [ |
| 54 | +// new FiberNode(mockFuncs[1], '*'), |
| 55 | +// new FiberNode(mockFuncs[2], '*'), |
| 56 | +// new FiberNode(mockFuncs[3], '*'), |
| 57 | +// ]; |
| 58 | + |
| 59 | +// snapShot = { tree }; |
| 60 | +// timeJump = timeJumpRequire(mode); |
| 61 | +// }); |
| 62 | +// test('calling the initial require should return a function', () => { |
| 63 | +// const funcDef = timeJumpRequire; |
| 64 | +// expect(typeof funcDef).toBe('function'); |
| 65 | +// }); |
| 66 | + |
| 67 | +// // xdescribe('testing iteration through snapshot tree', () => { |
| 68 | +// // const states = ['root', 'firstChild', 'secondChild', 'thirdChild']; |
| 69 | +// // const target = new FiberNode(null, states[0]); |
| 70 | +// // target.children = [ |
| 71 | +// // new FiberNode(null, states[1]), |
| 72 | +// // new FiberNode(null, states[2]), |
| 73 | +// // new FiberNode(null, states[3]), |
| 74 | +// // ]; |
| 75 | + |
| 76 | +// // target.componentData = {index: 0} |
| 77 | + |
| 78 | +// // beforeEach((): void => { |
| 79 | +// // timeJump(target); |
| 80 | +// // }); |
| 81 | +// // test('timeJump should call setState on each state in origin', () => { |
| 82 | +// // mockFuncs.forEach(mockFunc => expect(mockFunc.mock.calls.length).toBe(1)); |
| 83 | +// // }); |
| 84 | + |
| 85 | +// // test('timeJump should pass target state to origin setState', () => { |
| 86 | +// // mockFuncs.forEach((mockFunc, i) => expect(mockFunc.mock.calls[0][0]).toBe(states[i])); |
| 87 | +// // }); |
| 88 | +// // }); |
| 89 | + |
| 90 | +// test('jumping mode should be set while timeJumping', () => { |
| 91 | +// mode = { jumping: true }; |
| 92 | +// const logMode = jest.fn(); |
| 93 | +// logMode.mockImplementation(() => expect(mode.jumping).toBe(true)); |
| 94 | + |
| 95 | +// snapShot.tree = new FiberNode(logMode, null); |
| 96 | +// const target = new FiberNode(null, 'test'); |
| 97 | +// logMode(target); |
| 98 | +// expect(logMode).toHaveBeenCalled(); |
| 99 | +// }); |
| 100 | +// }); |
0 commit comments