55
66using AngleSharp . Dom ;
77using Bunit . TestDoubles ;
8+ using Microsoft . AspNetCore . Components . Rendering ;
89using System . Reflection ;
910using UnitTest . Misc ;
1011
@@ -386,7 +387,7 @@ public void MenuItem_Menu()
386387 }
387388
388389 [ Fact ]
389- public void IsDisabled_Ok ( )
390+ public async Task IsDisabled_Ok ( )
390391 {
391392 var cut = Context . RenderComponent < Tab > ( pb =>
392393 {
@@ -402,10 +403,23 @@ public void IsDisabled_Ok()
402403 pb . AddChildContent < TabItem > ( pb =>
403404 {
404405 pb . Add ( a => a . Text , "Text2" ) ;
405- pb . Add ( a => a . ChildContent , builder => builder . AddContent ( 0 , "Test2" ) ) ;
406+ pb . AddChildContent < DisableTabItemButton > ( ) ;
406407 } ) ;
407408 } ) ;
408409 Assert . Contains ( "<div role=\" tab\" class=\" tabs-item disabled\" ><i class=\" fa fa-fa\" ></i><span class=\" tabs-item-text\" >Text1</span></div>" , cut . Markup ) ;
410+
411+ var button = cut . FindComponent < DisableTabItemButton > ( ) ;
412+ Assert . NotNull ( button ) ;
413+
414+ await cut . InvokeAsync ( ( ) => button . Instance . OnDisabledTabItem ( ) ) ;
415+ Assert . Contains ( "<div role=\" tab\" class=\" tabs-item active disabled\" ><span class=\" tabs-item-text\" >Text2</span></div>" , cut . Markup ) ;
416+ }
417+
418+ [ Fact ]
419+ public void SetDisabled_Ok ( )
420+ {
421+ var cut = Context . RenderComponent < TabItem > ( ) ;
422+ cut . Instance . SetDisabled ( true ) ;
409423 }
410424
411425 [ Fact ]
@@ -815,4 +829,23 @@ public async Task FullScreen_Ok()
815829 var button = cut . Find ( ".btn-fs" ) ;
816830 await cut . InvokeAsync ( ( ) => button . Click ( ) ) ;
817831 }
832+
833+ class DisableTabItemButton : ComponentBase
834+ {
835+ [ CascadingParameter , NotNull ]
836+ private TabItem ? TabItem { get ; set ; }
837+
838+ protected override void BuildRenderTree ( RenderTreeBuilder builder )
839+ {
840+ builder . OpenComponent < Button > ( 0 ) ;
841+ builder . AddAttribute ( 1 , nameof ( Button . OnClickWithoutRender ) , OnDisabledTabItem ) ;
842+ builder . CloseComponent ( ) ;
843+ }
844+
845+ public Task OnDisabledTabItem ( )
846+ {
847+ TabItem . SetDisabled ( true ) ;
848+ return Task . CompletedTask ;
849+ }
850+ }
818851}
0 commit comments