1
1
import Tree from '../tree' ;
2
2
3
+ /**
4
+ * Created new tree under sibling and copy and clean tree describe block --
5
+ * Reason is because other tests are adding properties to tree and affecting the child block,
6
+ * so this was a quick way to test the trees getting reset to initial state
7
+ *
8
+ * Possible fix if more time allowed: Making use of beforeEach or afterEach --
9
+ */
10
+
3
11
describe ( 'Tree unit test' , ( ) => {
4
12
const newTree = new Tree ( { } ) ;
5
-
6
13
describe ( 'Constructor' , ( ) => {
7
14
it ( 'should be able to create a newTree' , ( ) => {
8
15
expect ( newTree . state ) . toEqual ( { } ) ;
9
16
} ) ;
10
17
11
- it ( 'should have 8 properties' , ( ) => {
18
+ it ( 'should have 7 properties' , ( ) => {
12
19
expect ( newTree ) . toHaveProperty ( 'state' ) ;
13
20
expect ( newTree ) . toHaveProperty ( 'name' ) ;
14
21
expect ( newTree ) . toHaveProperty ( 'componentData' ) ;
15
22
expect ( newTree ) . toHaveProperty ( 'children' ) ;
16
23
expect ( newTree ) . toHaveProperty ( 'parent' ) ;
17
24
expect ( newTree ) . toHaveProperty ( 'isExpanded' ) ;
18
25
expect ( newTree ) . toHaveProperty ( 'rtid' ) ;
19
- expect ( newTree ) . toHaveProperty ( 'route' ) ;
20
26
} ) ;
21
27
22
28
it ( 'has name default value as stateless' , ( ) => {
23
29
expect ( newTree . name ) . toBe ( 'nameless' ) ;
24
30
} ) ;
25
-
26
- it ( 'has children as an empty array' , ( ) => {
27
- expect ( newTree . children ) . toEqual ( [ ] ) ;
28
- } ) ;
29
31
} ) ;
30
32
31
33
/**
@@ -63,22 +65,17 @@ describe('Tree unit test', () => {
63
65
} ) ;
64
66
65
67
describe ( 'Adding sibling' , ( ) => {
66
- // const newTree = new Tree({});
67
- const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
68
+ const newTreeCopy = new Tree ( { } ) ;
69
+ const returnChild = newTreeCopy . addChild ( 'stateful' , 'child' , { } , null ) ;
68
70
const returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
69
71
70
72
it ( 'the tree now has 2 children' , ( ) => {
71
- expect ( newTree . children . length ) . toBe ( 2 ) ;
73
+ expect ( newTreeCopy . children . length ) . toBe ( 2 ) ;
72
74
} ) ;
73
75
74
76
it ( 'both of the children has the parent as this tree' , ( ) => {
75
- expect ( newTree . children [ 0 ] ) . toEqual ( returnChild ) ;
76
- expect ( newTree . children [ 1 ] ) . toEqual ( returnSibling ) ;
77
- } ) ;
78
-
79
- it ( 'both of the children has the parent as this tree' , ( ) => {
80
- expect ( returnChild . parent ) . toEqual ( newTree ) ;
81
- expect ( returnSibling . parent ) . toEqual ( newTree ) ;
77
+ expect ( returnChild . parent ) . toEqual ( newTreeCopy ) ;
78
+ expect ( returnSibling . parent ) . toEqual ( newTreeCopy ) ;
82
79
} ) ;
83
80
} ) ;
84
81
@@ -87,10 +84,10 @@ describe('Tree unit test', () => {
87
84
// Check Test
88
85
89
86
describe ( 'Copy & clean tree' , ( ) => {
90
- // const newTree = new Tree({});
91
- const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
87
+ const newTreeLastCopy = new Tree ( { } ) ;
88
+ const returnChild = newTreeLastCopy . addChild ( 'stateful' , 'child' , { } , null ) ;
92
89
returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
93
- const copy = newTree . cleanTreeCopy ( ) ;
90
+ const copy = newTreeLastCopy . cleanTreeCopy ( ) ;
94
91
it ( 'its copy has 2 children' , ( ) => {
95
92
expect ( copy . children . length ) . toEqual ( 2 ) ;
96
93
} ) ;
0 commit comments