@@ -62,4 +62,59 @@ await cut.InvokeAsync(() => cut.Instance.TriggerIntersecting(new IntersectionObs
6262 } ) ) ;
6363 Assert . Equal ( 10 , count ) ;
6464 }
65+
66+ [ Fact ]
67+ public async Task LoadMore_Ok ( )
68+ {
69+ var loading = false ;
70+ var cut = Context . RenderComponent < LoadMore > ( pb =>
71+ {
72+ pb . Add ( a => a . Threshold , "1" ) ;
73+ pb . Add ( a => a . CanLoading , true ) ;
74+ pb . Add ( a => a . OnLoadMoreAsync , ( ) =>
75+ {
76+ loading = true ;
77+ return Task . CompletedTask ;
78+ } ) ;
79+ } ) ;
80+ cut . Contains ( "<div class=\" bb-intersection-observer-item\" ><div class=\" bb-intersection-loading\" ><div class=\" spinner spinner-border\" role=\" status\" ><span class=\" visually-hidden\" >Loading...</span></div></div></div>" ) ;
81+
82+ // trigger intersecting
83+ var observerItem = cut . FindComponent < IntersectionObserver > ( ) ;
84+ await cut . InvokeAsync ( ( ) => observerItem . Instance . TriggerIntersecting ( new IntersectionObserverEntry ( )
85+ {
86+ IsIntersecting = true ,
87+ Index = 10 ,
88+ Time = 100.00 ,
89+ IntersectionRatio = 0.5f
90+ } ) ) ;
91+ Assert . True ( loading ) ;
92+
93+ cut . SetParametersAndRender ( pb =>
94+ {
95+ pb . Add ( a => a . LoadingTemplate , new RenderFragment ( builder => builder . AddContent ( 0 , "loading template" ) ) ) ;
96+ } ) ;
97+ cut . Contains ( "loading template" ) ;
98+
99+ loading = false ;
100+ cut . SetParametersAndRender ( pb =>
101+ {
102+ pb . Add ( a => a . CanLoading , false ) ;
103+ } ) ;
104+ observerItem = cut . FindComponent < IntersectionObserver > ( ) ;
105+ await cut . InvokeAsync ( ( ) => observerItem . Instance . TriggerIntersecting ( new IntersectionObserverEntry ( )
106+ {
107+ IsIntersecting = true ,
108+ Index = 10 ,
109+ Time = 100.00 ,
110+ IntersectionRatio = 0.5f
111+ } ) ) ;
112+ Assert . False ( loading ) ;
113+
114+ cut . SetParametersAndRender ( pb =>
115+ {
116+ pb . Add ( a => a . NoMoreTemplate , new RenderFragment ( builder => builder . AddContent ( 0 , "没有更多数据模板" ) ) ) ;
117+ } ) ;
118+ cut . Contains ( "没有更多数据模板" ) ;
119+ }
65120}
0 commit comments