1
1
import Tree from '../tree' ;
2
- import { networkInterfaces } from 'os' ;
3
2
4
3
describe ( 'Tree unit test' , ( ) => {
5
- describe ( 'Constructor' , ( ) => {
6
- let newTree = new Tree ( { } ) ;
4
+ const newTree = new Tree ( { } ) ;
7
5
6
+ describe ( 'Constructor' , ( ) => {
8
7
it ( 'should be able to create a newTree' , ( ) => {
9
8
expect ( newTree . state ) . toEqual ( { } ) ;
10
- } )
9
+ } ) ;
11
10
12
- it ( 'should have 5 properties' , ( ) => {
11
+ it ( 'should have 8 properties' , ( ) => {
13
12
expect ( newTree ) . toHaveProperty ( 'state' ) ;
14
13
expect ( newTree ) . toHaveProperty ( 'name' ) ;
15
14
expect ( newTree ) . toHaveProperty ( 'componentData' ) ;
16
15
expect ( newTree ) . toHaveProperty ( 'children' ) ;
17
16
expect ( newTree ) . toHaveProperty ( 'parent' ) ;
18
- } )
17
+ expect ( newTree ) . toHaveProperty ( 'isExpanded' ) ;
18
+ expect ( newTree ) . toHaveProperty ( 'rtid' ) ;
19
+ expect ( newTree ) . toHaveProperty ( 'route' ) ;
20
+ } ) ;
19
21
20
22
it ( 'has name default value as stateless' , ( ) => {
21
23
expect ( newTree . name ) . toBe ( 'nameless' ) ;
22
- } )
24
+ } ) ;
23
25
24
26
it ( 'has children as an empty array' , ( ) => {
25
27
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
+ */
29
44
30
45
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
40
55
expect ( returnChild . parent ) . toEqual ( newTree ) ;
41
- } )
56
+ } ) ;
42
57
43
58
it ( 'parent now contains an array of children and each children is a valid tree' , ( ) => {
44
59
expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'state' ) ;
45
60
expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'name' ) ;
46
61
expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'componentData' ) ;
47
- } )
48
- } )
62
+ } ) ;
63
+ } ) ;
49
64
50
65
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 ) ;
63
69
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 ) ;
75
70
it ( 'the tree now has 2 children' , ( ) => {
76
71
expect ( newTree . children . length ) . toBe ( 2 ) ;
77
- } )
72
+ } ) ;
78
73
79
74
it ( 'both of the children has the parent as this tree' , ( ) => {
80
75
expect ( newTree . children [ 0 ] ) . toEqual ( returnChild ) ;
81
76
expect ( newTree . children [ 1 ] ) . toEqual ( returnSibling ) ;
82
- } )
77
+ } ) ;
83
78
84
79
it ( 'both of the children has the parent as this tree' , ( ) => {
85
80
expect ( returnChild . parent ) . toEqual ( newTree ) ;
86
81
expect ( returnSibling . parent ) . toEqual ( newTree ) ;
87
- } )
88
- } )
82
+ } ) ;
83
+ } ) ;
89
84
85
+ // review this test
86
+ // returnSibling not used?
87
+ // Check Test
90
88
91
89
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 ( ) ;
96
94
it ( 'its copy has 2 children' , ( ) => {
97
95
expect ( copy . children . length ) . toEqual ( 2 ) ;
98
- } )
99
- } )
100
- } )
96
+ } ) ;
97
+ } ) ;
98
+ } ) ;
0 commit comments