@@ -72,17 +72,31 @@ describe("useIncrementalTreeData", () => {
7272 expect ( result . current [ 0 ] . children [ 0 ] . id ) . toBe ( "child" ) ;
7373 } ) ;
7474
75- it ( "assigns COLLAPSED_WITH_JS when startExpanded is false" , ( ) => {
75+ it ( "assigns LOADING on first render, then COLLAPSED_WITH_JS when startExpanded is false" , ( ) => {
7676 const items = [ makeItem ( "a" ) ] ;
7777 const config = makeConfig ( { startExpanded : false } ) ;
78- const { result } = renderHook ( ( ) => useIncrementalTreeData ( items , config ) ) ;
78+ const { result, rerender } = renderHook (
79+ ( { items, config } : { items : ObjectItem [ ] ; config : TreeConfigRef } ) =>
80+ useIncrementalTreeData ( items , config ) ,
81+ { initialProps : { items, config } }
82+ ) ;
83+ expect ( result . current [ 0 ] . treeNodeState ) . toBe ( TreeNodeState . LOADING ) ;
84+ // Simulate Mendix re-providing items (new array reference)
85+ rerender ( { items : [ ...items ] , config } ) ;
7986 expect ( result . current [ 0 ] . treeNodeState ) . toBe ( TreeNodeState . COLLAPSED_WITH_JS ) ;
8087 } ) ;
8188
82- it ( "assigns EXPANDED when startExpanded is true" , ( ) => {
89+ it ( "assigns LOADING on first render, then EXPANDED when startExpanded is true" , ( ) => {
8390 const items = [ makeItem ( "a" ) ] ;
8491 const config = makeConfig ( { startExpanded : true } ) ;
85- const { result } = renderHook ( ( ) => useIncrementalTreeData ( items , config ) ) ;
92+ const { result, rerender } = renderHook (
93+ ( { items, config } : { items : ObjectItem [ ] ; config : TreeConfigRef } ) =>
94+ useIncrementalTreeData ( items , config ) ,
95+ { initialProps : { items, config } }
96+ ) ;
97+ expect ( result . current [ 0 ] . treeNodeState ) . toBe ( TreeNodeState . LOADING ) ;
98+ // Simulate Mendix re-providing items (new array reference)
99+ rerender ( { items : [ ...items ] , config } ) ;
86100 expect ( result . current [ 0 ] . treeNodeState ) . toBe ( TreeNodeState . EXPANDED ) ;
87101 } ) ;
88102 } ) ;
0 commit comments