@@ -402,18 +402,36 @@ public void Button_Applies_Additional_Attributes()
402402 }
403403
404404 [ Fact ]
405- public void Throws_When_No_PrivilegeContext_Provided ( )
405+ public void NoPrivilegeContext_AssumeAllPrivileges_RendersEnabledButton ( )
406406 {
407- var exception = Assert . Throws < InvalidOperationException > ( ( ) =>
408- {
409- RenderComponent < PrivilegeButton > ( ps => ps
410- . Add ( p => p . Action , "create" )
411- . Add ( p => p . Subject , "Post" )
412- . Add ( p => p . ChildContent , builder => builder . AddContent ( 0 , "Create Post" ) )
413- ) ;
414- } ) ;
407+ // When no PrivilegeContext is provided, component should assume all privileges
408+ var cut = RenderComponent < PrivilegeButton > ( ps => ps
409+ . Add ( p => p . Action , "create" )
410+ . Add ( p => p . Subject , "Post" )
411+ . Add ( p => p . ChildContent , builder => builder . AddContent ( 0 , "Create Post" ) )
412+ ) ;
413+
414+ var button = cut . Find ( "button" ) ;
415+ button . Should ( ) . NotBeNull ( ) ;
416+ button . HasAttribute ( "disabled" ) . Should ( ) . BeFalse ( ) ;
417+ button . TextContent . Should ( ) . Be ( "Create Post" ) ;
418+ }
415419
416- exception . Message . Should ( ) . Contain ( "PrivilegeContext" ) ;
420+ [ Fact ]
421+ public void NoPrivilegeContext_WithHideForbidden_DoesNotHide ( )
422+ {
423+ // When no PrivilegeContext is provided, all privileges are assumed, so button should not hide
424+ var cut = RenderComponent < PrivilegeButton > ( ps => ps
425+ . Add ( p => p . Action , "create" )
426+ . Add ( p => p . Subject , "Post" )
427+ . Add ( p => p . HideForbidden , true )
428+ . Add ( p => p . ChildContent , builder => builder . AddContent ( 0 , "Create Post" ) )
429+ ) ;
430+
431+ var button = cut . Find ( "button" ) ;
432+ button . Should ( ) . NotBeNull ( ) ;
433+ button . HasAttribute ( "disabled" ) . Should ( ) . BeFalse ( ) ;
434+ button . TextContent . Should ( ) . Be ( "Create Post" ) ;
417435 }
418436
419437 [ Fact ]
0 commit comments