File tree Expand file tree Collapse file tree 3 files changed +61
-8
lines changed
src/LinkDotNet.Blog.Web/Features/Home/Components
tests/LinkDotNet.Blog.UnitTests/Web/Features/Home/Components Expand file tree Collapse file tree 3 files changed +61
-8
lines changed Original file line number Diff line number Diff line change
1
+ @if (string .IsNullOrEmpty (Href ))
2
+ {
3
+ <a class =" @CssClass" >@ChildContent </a >
4
+ }
5
+ else
6
+ {
7
+ <a class =" @CssClass" href =" @Href" >@ChildContent </a >
8
+ }
9
+ @code {
10
+ [Parameter ]
11
+ public string CssClass { get ; set ; }
12
+
13
+ [Parameter ]
14
+ public string Href { get ; set ; }
15
+
16
+ [Parameter ]
17
+ public RenderFragment ChildContent { get ; set ; }
18
+ }
Original file line number Diff line number Diff line change 3
3
<nav aria-label =" Page navigation" >
4
4
<ul class =" pagination justify-content-center" >
5
5
<li class =" page-item @(!PageList.IsFirstPage && PageList.Count > 0 ? string.Empty : " disabled " )" >
6
- <a class =" page-link" href =" @PreviousPageLink" tabindex = " -1 " >Previous</a >
6
+ <Anchor CssClass =" page-link" Href =" @PreviousPageLink" >Previous</Anchor >
7
7
</li >
8
8
<li class =" page-item @(!PageList.IsLastPage && PageList.Count > 0 ? string.Empty : " disabled " )" >
9
- <a class =" page-link" href =" @NextPageLink" >Next</a >
9
+ <Anchor CssClass =" page-link" Href =" @NextPageLink" >Next</Anchor >
10
10
</li >
11
11
</ul >
12
12
</nav >
13
13
14
- @code {
15
- [Parameter ]
16
- public IPagedList <BlogPost > PageList { get ; set ; }
14
+ @code {
15
+ [Parameter ]
16
+ public IPagedList <BlogPost > PageList { get ; set ; }
17
17
18
- private string PreviousPageLink => PageList .IsFirstPage ? string .Empty : $" /{PageList .PageNumber - 1 }" ;
19
- private string NextPageLink => PageList .IsLastPage ? string .Empty : $" /{PageList .PageNumber + 1 }" ;
20
- }
18
+ private string PreviousPageLink => PageList .IsFirstPage ? string .Empty : $" /{PageList .PageNumber - 1 }" ;
19
+ private string NextPageLink => PageList .IsLastPage ? string .Empty : $" /{PageList .PageNumber + 1 }" ;
20
+ }
Original file line number Diff line number Diff line change
1
+ using System . Linq ;
2
+ using AngleSharp . Html . Dom ;
3
+ using AngleSharpWrappers ;
4
+ using Bunit ;
5
+ using LinkDotNet . Blog . Web . Features . Home . Components ;
6
+
7
+ namespace LinkDotNet . Blog . UnitTests . Web . Features . Home . Components ;
8
+
9
+ public class AnchorTests : TestContext
10
+ {
11
+ [ Fact ]
12
+ public void ShouldShowHrefWhenNotEmpty ( )
13
+ {
14
+ var cut = RenderComponent < Anchor > ( ps => ps
15
+ . Add ( p => p . Href , "http://url/" )
16
+ . Add ( p => p . CssClass , "page" ) ) ;
17
+
18
+ var anchor = cut . Find ( "a" ) . Unwrap ( ) as IHtmlAnchorElement ;
19
+ anchor . Should ( ) . NotBeNull ( ) ;
20
+ anchor . Href . Should ( ) . Be ( "http://url/" ) ;
21
+ anchor . GetAttribute ( "class" ) . Should ( ) . Be ( "page" ) ;
22
+ }
23
+
24
+ [ Fact ]
25
+ public void ShouldNotShowHrefWhenEmpty ( )
26
+ {
27
+ var cut = RenderComponent < Anchor > ( ps => ps
28
+ . Add ( p => p . Href , string . Empty )
29
+ . Add ( p => p . CssClass , "page" ) ) ;
30
+
31
+ var anchor = cut . Find ( "a" ) . Unwrap ( ) as IHtmlAnchorElement ;
32
+ anchor . Should ( ) . NotBeNull ( ) ;
33
+ anchor . Attributes . Count ( a => a . Name == "href" ) . Should ( ) . Be ( 0 ) ;
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments