11import Tree from '../tree' ;
2- import { networkInterfaces } from 'os' ;
32
43describe ( 'Tree unit test' , ( ) => {
5- describe ( 'Constructor' , ( ) => {
6- let newTree = new Tree ( { } ) ;
4+ const newTree = new Tree ( { } ) ;
75
6+ describe ( 'Constructor' , ( ) => {
87 it ( 'should be able to create a newTree' , ( ) => {
98 expect ( newTree . state ) . toEqual ( { } ) ;
10- } )
9+ } ) ;
1110
12- it ( 'should have 5 properties' , ( ) => {
11+ it ( 'should have 8 properties' , ( ) => {
1312 expect ( newTree ) . toHaveProperty ( 'state' ) ;
1413 expect ( newTree ) . toHaveProperty ( 'name' ) ;
1514 expect ( newTree ) . toHaveProperty ( 'componentData' ) ;
1615 expect ( newTree ) . toHaveProperty ( 'children' ) ;
1716 expect ( newTree ) . toHaveProperty ( 'parent' ) ;
18- } )
17+ expect ( newTree ) . toHaveProperty ( 'isExpanded' ) ;
18+ expect ( newTree ) . toHaveProperty ( 'rtid' ) ;
19+ expect ( newTree ) . toHaveProperty ( 'route' ) ;
20+ } ) ;
1921
2022 it ( 'has name default value as stateless' , ( ) => {
2123 expect ( newTree . name ) . toBe ( 'nameless' ) ;
22- } )
24+ } ) ;
2325
2426 it ( 'has children as an empty array' , ( ) => {
2527 expect ( newTree . children ) . toEqual ( [ ] ) ;
26- } )
27- } )
28-
28+ } ) ;
29+ } ) ;
30+
31+ /**
32+ *
33+ * making sure to adhere to ts practices when goign through tests
34+ *
35+ * ^^
36+ * the tree should have initial values of state,
37+ * name, etc to be default as per newly created tree
38+ * update the add child and add sibling tests
39+ *
40+ * update the clean tree copy test to make it test for deep equaltiy? (note:
41+ * this test may always fail if we make it so because there is no way to have deep equalituy
42+ * with some shit that isn't allowed)
43+ */
2944
3045 describe ( 'Adding children' , ( ) => {
31- let newTree = new Tree ( { } ) ;
32- let returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
33-
34- it ( 'should be able to add a child' , ( ) => {
35- expect ( typeof newTree . children ) . toEqual ( 'object' ) ;
36- expect ( Array . isArray ( newTree . children ) ) . toBeTruthy ;
37- } )
38-
39- it ( `its parent should be newTree` , ( ) => {
46+ const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
47+
48+ it ( 'should have the child be in the children\'s array property' , ( ) => {
49+ // check if returnChild is in the children array property of tree that invoked addChild
50+ expect ( newTree . children ) . toContain ( returnChild ) ;
51+ } ) ;
52+
53+ it ( 'should have the object that invoked it be it\'s parent' , ( ) => {
54+ // checking parent to be the tree that invoked addChild
4055 expect ( returnChild . parent ) . toEqual ( newTree ) ;
41- } )
56+ } ) ;
4257
4358 it ( 'parent now contains an array of children and each children is a valid tree' , ( ) => {
4459 expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'state' ) ;
4560 expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'name' ) ;
4661 expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'componentData' ) ;
47- } )
48- } )
62+ } ) ;
63+ } ) ;
4964
5065 describe ( 'Adding sibling' , ( ) => {
51- let newTree = new Tree ( { } ) ;
52- let returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
53- let returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
54-
55- it ( 'the tree now has 2 children' , ( ) => {
56- expect ( newTree . children . length ) . toBe ( 2 ) ;
57- } )
58-
59- it ( 'both of the children has the parent as this tree' , ( ) => {
60- expect ( newTree . children [ 0 ] ) . toEqual ( returnChild ) ;
61- expect ( newTree . children [ 1 ] ) . toEqual ( returnSibling ) ;
62- } )
66+ // const newTree = new Tree({});
67+ const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
68+ const returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
6369
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' , { } , null ) ;
74- let returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
7570 it ( 'the tree now has 2 children' , ( ) => {
7671 expect ( newTree . children . length ) . toBe ( 2 ) ;
77- } )
72+ } ) ;
7873
7974 it ( 'both of the children has the parent as this tree' , ( ) => {
8075 expect ( newTree . children [ 0 ] ) . toEqual ( returnChild ) ;
8176 expect ( newTree . children [ 1 ] ) . toEqual ( returnSibling ) ;
82- } )
77+ } ) ;
8378
8479 it ( 'both of the children has the parent as this tree' , ( ) => {
8580 expect ( returnChild . parent ) . toEqual ( newTree ) ;
8681 expect ( returnSibling . parent ) . toEqual ( newTree ) ;
87- } )
88- } )
82+ } ) ;
83+ } ) ;
8984
85+ // review this test
86+ // returnSibling not used?
87+ // Check Test
9088
9189 describe ( 'Copy & clean tree' , ( ) => {
92- let newTree = new Tree ( { } ) ;
93- let returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
94- let returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
95- let copy = newTree . cleanTreeCopy ( ) ;
90+ // const newTree = new Tree({});
91+ const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
92+ returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
93+ const copy = newTree . cleanTreeCopy ( ) ;
9694 it ( 'its copy has 2 children' , ( ) => {
9795 expect ( copy . children . length ) . toEqual ( 2 ) ;
98- } )
99- } )
100- } )
96+ } ) ;
97+ } ) ;
98+ } ) ;
0 commit comments