1+ /* eslint-disable camelcase */
2+
13import React from 'react' ;
24import { shallow , mount } from 'enzyme' ;
35import { render } from 'react-dom' ;
@@ -6,7 +8,7 @@ import NodeWrapper from '../NodeWrapper';
68import Node from '../../Node' ;
79import Link from '../../Link' ;
810import Tree from '../index' ;
9- import { mockData , mockData2 , mockData3 , mockData4 } from './mockData' ;
11+ import { mockData , mockData2 , mockData3 , mockData4 , mockTree_D1N2_D2N2 } from './mockData' ;
1012
1113describe ( '<Tree />' , ( ) => {
1214 jest . spyOn ( Tree . prototype , 'generateTree' ) ;
@@ -270,14 +272,19 @@ describe('<Tree />', () => {
270272 } ) ;
271273
272274 describe ( 'initialDepth' , ( ) => {
273- it ( 'sets tree depth to `props.initialDepth` if specified' , ( ) => {
274- mount ( < Tree data = { mockData } initialDepth = { 1 } /> ) ;
275- expect ( Tree . prototype . setInitialTreeDepth ) . toHaveBeenCalled ( ) ;
275+ it ( 'expands tree to full depth by default' , ( ) => {
276+ const renderedComponent = shallow ( < Tree data = { mockTree_D1N2_D2N2 } /> ) ;
277+ expect ( renderedComponent . find ( Node ) . length ) . toBe ( 5 ) ;
278+ } ) ;
279+
280+ it ( 'expands tree to `props.initialDepth` if specified' , ( ) => {
281+ const renderedComponent = shallow ( < Tree data = { mockTree_D1N2_D2N2 } initialDepth = { 1 } /> ) ;
282+ expect ( renderedComponent . find ( Node ) . length ) . toBe ( 3 ) ;
276283 } ) ;
277284
278- it ( 'does not set an initialDepth if `props.useCollapseData` is true ' , ( ) => {
279- mount ( < Tree data = { mockData } initialDepth = { 1 } useCollapseData /> ) ;
280- expect ( Tree . prototype . setInitialTreeDepth ) . not . toHaveBeenCalled ( ) ;
285+ it ( 'renders only the root node if `initialDepth === 0` ' , ( ) => {
286+ const renderedComponent = shallow ( < Tree data = { mockTree_D1N2_D2N2 } initialDepth = { 0 } /> ) ;
287+ expect ( renderedComponent . find ( Node ) . length ) . toBe ( 1 ) ;
281288 } ) ;
282289 } ) ;
283290
@@ -746,7 +753,6 @@ describe('<Tree />', () => {
746753 . first ( )
747754 . simulate ( 'click' ) ; // collapse
748755
749- expect ( onUpdateSpy ) . toHaveBeenCalledTimes ( 1 ) ;
750756 expect ( onUpdateSpy ) . toHaveBeenCalledWith ( {
751757 node : expect . any ( Object ) ,
752758 zoom : 1 ,
@@ -764,7 +770,6 @@ describe('<Tree />', () => {
764770 ) ;
765771 const scrollableComponent = document . querySelector ( '.rd3t-tree-container > svg' ) ;
766772 scrollableComponent . dispatchEvent ( new Event ( 'wheel' ) ) ;
767- expect ( onUpdateSpy ) . toHaveBeenCalledTimes ( 1 ) ;
768773 expect ( onUpdateSpy ) . toHaveBeenCalledWith ( {
769774 node : null ,
770775 translate : { x : expect . any ( Number ) , y : expect . any ( Number ) } ,
@@ -798,7 +803,6 @@ describe('<Tree />', () => {
798803 . first ( )
799804 . simulate ( 'click' ) ;
800805
801- expect ( onUpdateSpy ) . toHaveBeenCalledTimes ( 1 ) ;
802806 expect ( onUpdateSpy ) . toHaveBeenCalledWith ( {
803807 node : expect . any ( Object ) ,
804808 translate,
0 commit comments