Skip to content

Commit dd4f6a0

Browse files
committed
adding test for tree and masterState
1 parent e14cf7d commit dd4f6a0

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"scripts": {
1616
"build": "webpack --mode production",
1717
"dev": "webpack --mode development --watch",
18-
"test": "jest --verbose --coverage --watchAll --runInBand --detectOpenHandles",
18+
"test": "jest --verbose --coverage --watchAll --runInBand --detectOpenHandles --forceExit",
1919
"docker-test-lint": "eslint --ext .js --ext .jsx src",
2020
"docs": "typedoc --json docs --inputFiles src/app --inputFiles src/backend --readme docs/readme.md"
2121
},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import masterState from '../masterState'
2+
import {
3+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4+
HookStateItem,
5+
HookStates
6+
} from '../types/backendTypes';
7+
8+
describe('Testing masterState functionality', () => {
9+
let hookOne : HookStateItem = {state: 'A', component: 'counter1'};
10+
let hookTwo : HookStateItem = {state: 'B', component: 'counter2'};
11+
let allHooks : HookStates = [hookOne, hookTwo];
12+
masterState.saveNew(hookOne.state, hookOne.component);
13+
masterState.saveNew(hookTwo.state, hookTwo.component);
14+
15+
describe('Save new', () => {
16+
masterState.saveNew(hookOne.state, hookOne.component);
17+
masterState.saveNew(hookTwo.state, hookTwo.component);
18+
})
19+
20+
describe('getComponentByIndex', () => {
21+
it('should be able to get both hook states component', () => {
22+
expect(masterState.getComponentByIndex(0)).toEqual(hookOne.component);
23+
expect(masterState.getComponentByIndex(1)).toEqual(hookTwo.component);
24+
})
25+
})
26+
27+
describe('getRecordByIndex', () => {
28+
it('should be able to get both hook states', () => {
29+
expect(masterState.getRecordByIndex(0)).toEqual(hookOne);
30+
expect(masterState.getRecordByIndex(1)).toEqual(hookTwo);
31+
})
32+
})
33+
34+
35+
})

src/backend/__tests__/tree.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,40 @@ describe('Tree unit test', () => {
6161
expect(newTree.children[1]).toEqual(returnSibling);
6262
})
6363

64-
it('its children can recognize the parent, () => {
64+
it('both of the children has the parent as this tree', () => {
65+
expect(returnChild.parent).toEqual(newTree);
66+
expect(returnSibling.parent).toEqual(newTree);
67+
})
68+
})
69+
70+
71+
describe('Adding sibling', () => {
72+
let newTree = new Tree({});
73+
let returnChild = newTree.addChild('stateful', 'child', {});
74+
let returnSibling = returnChild.addSibling('stateful', 'child', {});
75+
it('the tree now has 2 children', () => {
76+
expect(newTree.children.length).toBe(2);
77+
})
78+
79+
it('both of the children has the parent as this tree', () => {
80+
expect(newTree.children[0]).toEqual(returnChild);
81+
expect(newTree.children[1]).toEqual(returnSibling);
82+
})
83+
84+
it('both of the children has the parent as this tree', () => {
6585
expect(returnChild.parent).toEqual(newTree);
6686
expect(returnSibling.parent).toEqual(newTree);
87+
})
88+
})
89+
90+
91+
describe('Copy & clean tree', () => {
92+
let newTree = new Tree({});
93+
let returnChild = newTree.addChild('stateful', 'child', {});
94+
let returnSibling = returnChild.addSibling('stateful', 'child', {});
95+
let copy = newTree.cleanTreeCopy();
96+
it('its copy has 2 children', () => {
97+
expect(copy.children.length).toEqual(2);
6798
})
6899
})
69100
})

src/backend/timeJump.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export default (origin, mode) => {
6464
const hookState = Object.values(hook);
6565
console.log('target', target);
6666
if (hooksComponent && hooksComponent.dispatch) {
67-
6867
hooksComponent.dispatch(hookState[0]);
6968
}
7069
});

src/backend/tree.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,13 @@ class Tree {
9797
// copy.children = this.children;
9898

9999
// creates copy of each child of the present node
100-
101100
copy.children = this.children.map((child: Tree): Tree | string => {
102101
if (!circularComponentTable.has(child)) {
103102
return child.cleanTreeCopy();
104103
}
105104
return 'circular';
106105
});
107-
108-
106+
109107
// returns copy
110108
copyInstances--;
111109
return copy;

0 commit comments

Comments
 (0)