@@ -61,4 +61,47 @@ describe('TreeState', () => {
6161 expect ( ( ) => TreeState . getTree ( ( ) => { } ) ) . toThrowError ( 'Expected a State instance but got function' ) ;
6262 } ) ;
6363 } ) ;
64+
65+ describe ( 'getNumberOfVisibleDescendants' , ( ) => {
66+ test ( 'should fail for when invalid state is supplied' , ( ) => {
67+ expect ( ( ) => TreeState . getNumberOfVisibleDescendants ( 'state' , 0 ) ) . toThrowError (
68+ 'Expected a State instance but got string' ,
69+ ) ;
70+ expect ( ( ) => TreeState . getNumberOfVisibleDescendants ( 1225 , 0 ) ) . toThrowError (
71+ 'Expected a State instance but got number' ,
72+ ) ;
73+ expect ( ( ) => TreeState . getNumberOfVisibleDescendants ( [ ] , 0 ) ) . toThrowError (
74+ 'Expected a State instance but got object' ,
75+ ) ;
76+ expect ( ( ) => TreeState . getNumberOfVisibleDescendants ( { } , 0 ) ) . toThrowError (
77+ 'Expected a State instance but got object' ,
78+ ) ;
79+ expect ( ( ) => TreeState . getNumberOfVisibleDescendants ( true , 0 ) ) . toThrowError (
80+ 'Expected a State instance but got boolean' ,
81+ ) ;
82+ expect ( ( ) => TreeState . getNumberOfVisibleDescendants ( ( ) => { } , 0 ) ) . toThrowError (
83+ 'Expected a State instance but got function' ,
84+ ) ;
85+ } ) ;
86+
87+ test ( 'should get a correct number of descendants for a node with deep descendants' , ( ) => {
88+ expect ( TreeState . getNumberOfVisibleDescendants ( TreeState . createFromTree ( Nodes ) , 0 ) ) . toEqual ( 4 ) ;
89+ } ) ;
90+
91+ test ( 'should get a correct number of descendants for a node without grand children' , ( ) => {
92+ expect ( TreeState . getNumberOfVisibleDescendants ( TreeState . createFromTree ( Nodes ) , 1 ) ) . toEqual ( 2 ) ;
93+ } ) ;
94+
95+ test ( 'should get a correct number of descendants for a node with deep descendants' , ( ) => {
96+ expect ( TreeState . getNumberOfVisibleDescendants ( TreeState . createFromTree ( Nodes ) , 0 ) ) . toEqual ( 4 ) ;
97+ } ) ;
98+
99+ test ( 'should get 0 descendants for a node that does not have any descendants in the root node' , ( ) => {
100+ expect ( TreeState . getNumberOfVisibleDescendants ( TreeState . createFromTree ( Nodes ) , 6 ) ) . toEqual ( 0 ) ;
101+ } ) ;
102+
103+ test ( 'should get 0 descendants for a node that does not have any descendants' , ( ) => {
104+ expect ( TreeState . getNumberOfVisibleDescendants ( TreeState . createFromTree ( Nodes ) , 3 ) ) . toEqual ( 0 ) ;
105+ } ) ;
106+ } ) ;
64107} ) ;
0 commit comments