11import Tree from '../tree' ;
22
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+
311describe ( 'Tree unit test' , ( ) => {
412 const newTree = new Tree ( { } ) ;
5-
613 describe ( 'Constructor' , ( ) => {
714 it ( 'should be able to create a newTree' , ( ) => {
815 expect ( newTree . state ) . toEqual ( { } ) ;
916 } ) ;
1017
11- it ( 'should have 8 properties' , ( ) => {
18+ it ( 'should have 7 properties' , ( ) => {
1219 expect ( newTree ) . toHaveProperty ( 'state' ) ;
1320 expect ( newTree ) . toHaveProperty ( 'name' ) ;
1421 expect ( newTree ) . toHaveProperty ( 'componentData' ) ;
1522 expect ( newTree ) . toHaveProperty ( 'children' ) ;
1623 expect ( newTree ) . toHaveProperty ( 'parent' ) ;
1724 expect ( newTree ) . toHaveProperty ( 'isExpanded' ) ;
1825 expect ( newTree ) . toHaveProperty ( 'rtid' ) ;
19- expect ( newTree ) . toHaveProperty ( 'route' ) ;
2026 } ) ;
2127
2228 it ( 'has name default value as stateless' , ( ) => {
2329 expect ( newTree . name ) . toBe ( 'nameless' ) ;
2430 } ) ;
25-
26- it ( 'has children as an empty array' , ( ) => {
27- expect ( newTree . children ) . toEqual ( [ ] ) ;
28- } ) ;
2931 } ) ;
3032
3133 /**
@@ -63,22 +65,17 @@ describe('Tree unit test', () => {
6365 } ) ;
6466
6567 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 ) ;
6870 const returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
6971
7072 it ( 'the tree now has 2 children' , ( ) => {
71- expect ( newTree . children . length ) . toBe ( 2 ) ;
73+ expect ( newTreeCopy . children . length ) . toBe ( 2 ) ;
7274 } ) ;
7375
7476 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 ) ;
8279 } ) ;
8380 } ) ;
8481
@@ -87,10 +84,10 @@ describe('Tree unit test', () => {
8784 // Check Test
8885
8986 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 ) ;
9289 returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
93- const copy = newTree . cleanTreeCopy ( ) ;
90+ const copy = newTreeLastCopy . cleanTreeCopy ( ) ;
9491 it ( 'its copy has 2 children' , ( ) => {
9592 expect ( copy . children . length ) . toEqual ( 2 ) ;
9693 } ) ;
0 commit comments