@@ -363,6 +363,80 @@ public async Task OnExpandRowAsync_Ok()
363363 Assert . True ( expanded ) ;
364364 }
365365
366+ [ Fact ]
367+ public async Task KeepExpandState_Ok ( )
368+ {
369+ // UI 重新刷新后保持状态节点状态
370+ var items = TreeFoo . GetTreeItems ( ) ;
371+ items . RemoveAt ( 1 ) ;
372+ items . RemoveAt ( 1 ) ;
373+ items [ 0 ] . HasChildren = true ;
374+
375+ var cut = Context . RenderComponent < TreeView < TreeFoo > > ( pb =>
376+ {
377+ pb . Add ( a => a . Items , items ) ;
378+ pb . Add ( a => a . OnExpandNodeAsync , item =>
379+ {
380+ return OnExpandNodeAsync ( item . Value ) ;
381+ } ) ;
382+ } ) ;
383+ var nodes = cut . FindAll ( ".tree-node" ) ;
384+ Assert . Single ( nodes ) ;
385+
386+ // 展开节点
387+ var bar = cut . Find ( ".fa-caret-right.visible" ) ;
388+ await cut . InvokeAsync ( ( ) => bar . Click ( ) ) ;
389+
390+ cut . WaitForAssertion ( ( ) =>
391+ {
392+ nodes = cut . FindAll ( ".tree-node" ) ;
393+ Assert . Equal ( 3 , nodes . Count ) ;
394+ } ) ;
395+
396+ // 重新渲染
397+ items = TreeFoo . GetTreeItems ( ) ;
398+ items . RemoveAt ( 1 ) ;
399+ items . RemoveAt ( 1 ) ;
400+ items [ 0 ] . HasChildren = true ;
401+ cut . SetParametersAndRender ( pb =>
402+ {
403+ pb . Add ( a => a . Items , items ) ;
404+ } ) ;
405+
406+ cut . WaitForAssertion ( ( ) =>
407+ {
408+ nodes = cut . FindAll ( ".tree-node" ) ;
409+ Assert . Equal ( 3 , nodes . Count ) ;
410+ } ) ;
411+
412+ // 重新渲染
413+ items = TreeFoo . GetTreeItems ( ) ;
414+ items . RemoveAt ( 1 ) ;
415+ items . RemoveAt ( 1 ) ;
416+ items [ 0 ] . HasChildren = false ;
417+ items [ 0 ] . Items =
418+ [
419+ new ( new TreeFoo ( ) { Id = "101" , ParentId = "1010" } )
420+ {
421+ Text = "懒加载子节点11" ,
422+ HasChildren = true
423+ } ,
424+ new ( new TreeFoo ( ) { Id = "102" , ParentId = "1010" } )
425+ {
426+ Text = "懒加载子节点22"
427+ }
428+ ] ;
429+ cut . SetParametersAndRender ( pb =>
430+ {
431+ pb . Add ( a => a . Items , items ) ;
432+ } ) ;
433+ cut . WaitForAssertion ( ( ) =>
434+ {
435+ nodes = cut . FindAll ( ".tree-node" ) ;
436+ Assert . Equal ( 3 , nodes . Count ) ;
437+ } ) ;
438+ }
439+
366440 [ Fact ]
367441 public async Task OnExpandRowAsync_CheckCascadeState_Ok ( )
368442 {
0 commit comments