1+ using Bunit ;
2+ using Microsoft . AspNetCore . Components ;
3+ using Xunit ;
4+
5+ namespace Blazorise . Tests . Components ;
6+
7+ public class PaginationComponentTest : TestContext
8+ {
9+ public PaginationComponentTest ( )
10+ {
11+ Services . AddBlazoriseTests ( ) . AddBootstrapProviders ( ) . AddEmptyIconProvider ( ) . AddTestData ( ) ;
12+ }
13+
14+ [ Fact ]
15+ public void EnabledPaginationLink_ShouldBeTabbable ( )
16+ {
17+ var cut = RenderPaginationLink ( ) ;
18+
19+ var link = cut . Find ( "a" ) ;
20+
21+ Assert . Equal ( "0" , link . GetAttribute ( "tabindex" ) ) ;
22+ Assert . False ( link . HasAttribute ( "aria-disabled" ) ) ;
23+ }
24+
25+ [ Fact ]
26+ public void DisabledPaginationLink_ShouldNotBeTabbable ( )
27+ {
28+ var cut = RenderPaginationLink ( disabled : true ) ;
29+
30+ var link = cut . Find ( "a" ) ;
31+
32+ Assert . Equal ( "-1" , link . GetAttribute ( "tabindex" ) ) ;
33+ Assert . Equal ( "true" , link . GetAttribute ( "aria-disabled" ) ) ;
34+ }
35+
36+ [ Fact ]
37+ public void ActivePaginationLink_ShouldSetAriaCurrent ( )
38+ {
39+ var cut = RenderPaginationLink ( active : true ) ;
40+
41+ var link = cut . Find ( "a" ) ;
42+
43+ Assert . Equal ( "page" , link . GetAttribute ( "aria-current" ) ) ;
44+ }
45+
46+ private IRenderedComponent < Pagination > RenderPaginationLink ( bool disabled = false , bool active = false )
47+ {
48+ return RenderComponent < Pagination > ( parameters => parameters
49+ . AddChildContent ( builder =>
50+ {
51+ builder . OpenComponent < PaginationItem > ( 0 ) ;
52+ builder . AddAttribute ( 1 , nameof ( PaginationItem . Disabled ) , disabled ) ;
53+ builder . AddAttribute ( 2 , nameof ( PaginationItem . Active ) , active ) ;
54+ builder . AddAttribute ( 3 , nameof ( PaginationItem . ChildContent ) , ( RenderFragment ) ( childBuilder =>
55+ {
56+ childBuilder . OpenComponent < PaginationLink > ( 0 ) ;
57+ childBuilder . AddAttribute ( 1 , nameof ( PaginationLink . Page ) , "1" ) ;
58+ childBuilder . AddAttribute ( 2 , nameof ( PaginationLink . ChildContent ) , ( RenderFragment ) ( contentBuilder => contentBuilder . AddContent ( 0 , "1" ) ) ) ;
59+ childBuilder . CloseComponent ( ) ;
60+ } ) ) ;
61+ builder . CloseComponent ( ) ;
62+ } ) ) ;
63+ }
64+ }
0 commit comments