Skip to content

Commit 1d60bef

Browse files
Co-authored-by: Ngoc Zwolinski <[email protected]>
Co-authored-by: Ngoc Zwolinski <[email protected]>
1 parent bb60f71 commit 1d60bef

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed

src/backend/__tests__/routes.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ describe('Route class testing', () => {
1414

1515
afterAll(() => {
1616
// Clean up the fake DOM environment
17-
global.window = undefined;
18-
global.document = undefined;
1917
dom.window.close();
2018
});
2119
beforeEach(() => {

src/backend/treeOLDTest.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import Tree from './models/tree';
2+
import { serializeState, scrubUnserializableMembers } from './models/tree';
3+
4+
xdescribe('Serialize state unit test', () => {
5+
const dummyState = {
6+
counter: 1,
7+
playerOne: 'X',
8+
board: [
9+
['', 'O', 'X'],
10+
['', 'O', 'X'],
11+
['O', 'X', ''],
12+
],
13+
};
14+
15+
const circularState: { [key: string]: any } = {};
16+
circularState.circ = circularState;
17+
18+
const serializedState = serializeState(dummyState);
19+
const serializedCircularState = serializeState(circularState);
20+
21+
it('should create a deep copy of state', () => {
22+
expect(dummyState).toEqual(serializedState);
23+
expect(dummyState).not.toBe(serializedState);
24+
});
25+
26+
it('should detect circular state', () => {
27+
expect(serializedCircularState).toEqual('circularState');
28+
});
29+
});
30+
31+
xdescribe('Scrub unserialized members unit test', () => {
32+
const dummyState = {
33+
counter: 1,
34+
playerOne: 'X',
35+
board: [
36+
['', 'O', 'X'],
37+
['', 'O', 'X'],
38+
['O', 'X', ''],
39+
],
40+
increment: function () {
41+
this.counter++;
42+
},
43+
};
44+
const newTree = new Tree(dummyState);
45+
const scrubbedTree = scrubUnserializableMembers(newTree);
46+
// make sure return type is tree
47+
it('should be instance of tree', () => {
48+
expect(newTree).toBeInstanceOf(Tree);
49+
});
50+
// make sure function is scrubbed
51+
});
52+
53+
xdescribe('Tree unit test', () => {
54+
const newTree = new Tree({});
55+
describe('Constructor', () => {
56+
it('should be able to create a newTree', () => {
57+
expect(newTree.state).toEqual({});
58+
});
59+
60+
it('should have 7 properties', () => {
61+
expect(newTree).toHaveProperty('state');
62+
expect(newTree).toHaveProperty('name');
63+
expect(newTree).toHaveProperty('componentData');
64+
expect(newTree).toHaveProperty('children');
65+
expect(newTree).toHaveProperty('parent');
66+
expect(newTree).toHaveProperty('isExpanded');
67+
expect(newTree).toHaveProperty('rtid');
68+
});
69+
70+
it('has name default value as stateless', () => {
71+
expect(newTree.name).toBe('nameless');
72+
});
73+
});
74+
75+
xdescribe('Adding children', () => {
76+
const returnChild: Tree = newTree.addChild('stateful', 'child', {}, null);
77+
78+
it("should have the child be in the children's array property", () => {
79+
// check if returnChild is in the children array property of tree that invoked addChild
80+
expect(newTree.children).toContain(returnChild);
81+
});
82+
83+
it("should have the object that invoked it be it's parent", () => {
84+
// checking parent to be the tree that invoked addChild
85+
expect(returnChild.parent).toEqual(newTree);
86+
});
87+
88+
it('parent now contains an array of children and each children is a valid tree', () => {
89+
expect(newTree.children[0]).toHaveProperty('state');
90+
expect(newTree.children[0]).toHaveProperty('name');
91+
expect(newTree.children[0]).toHaveProperty('componentData');
92+
});
93+
});
94+
95+
xdescribe('Adding sibling', () => {
96+
const newTreeCopy = new Tree({});
97+
const returnChild = newTreeCopy.addChild('stateful', 'child', {}, null);
98+
const returnSibling = returnChild.addSibling('stateful', 'child', {}, null);
99+
100+
it('the tree now has 2 children', () => {
101+
expect(newTreeCopy.children.length).toBe(2);
102+
});
103+
104+
it('both of the children has the parent as this tree', () => {
105+
expect(returnChild.parent).toEqual(newTreeCopy);
106+
expect(returnSibling.parent).toEqual(newTreeCopy);
107+
});
108+
});
109+
110+
xdescribe('Copy & clean tree', () => {});
111+
});

0 commit comments

Comments
 (0)