-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from linkdotnet/feature/pagination
Feature/pagination
- Loading branch information
Showing
14 changed files
with
237 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
LinkDotNet.Blog.UnitTests/Web/Shared/Admin/CreateNewBlogPostTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
LinkDotNet.Blog.UnitTests/Web/Shared/BlogPostNavigationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Bunit; | ||
using FluentAssertions; | ||
using LinkDotNet.Blog.Web.Shared; | ||
using LinkDotNet.Domain; | ||
using Moq; | ||
using X.PagedList; | ||
using Xunit; | ||
|
||
namespace LinkDotNet.Blog.UnitTests.Web.Shared | ||
{ | ||
public class BlogPostNavigationTests : TestContext | ||
{ | ||
[Fact] | ||
public void ShouldFireEventWhenGoingToNextPage() | ||
{ | ||
var actualNewPage = 0; | ||
var page = CreatePagedList(2, 3); | ||
var cut = RenderComponent<BlogPostNavigation>(p => p.Add(param => param.CurrentPage, page.Object) | ||
.Add(param => param.OnPageChanged, newPage => actualNewPage = newPage)); | ||
|
||
cut.Find("li:last-child a").Click(); | ||
|
||
actualNewPage.Should().Be(3); | ||
} | ||
|
||
[Fact] | ||
public void ShouldFireEventWhenGoingToPreviousPage() | ||
{ | ||
var actualNewPage = 0; | ||
var page = CreatePagedList(2, 3); | ||
var cut = RenderComponent<BlogPostNavigation>(p => p.Add(param => param.CurrentPage, page.Object) | ||
.Add(param => param.OnPageChanged, newPage => actualNewPage = newPage)); | ||
|
||
cut.Find("li:first-child a").Click(); | ||
|
||
actualNewPage.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotFireNextWhenOnLastPage() | ||
{ | ||
var page = CreatePagedList(2, 2); | ||
var cut = RenderComponent<BlogPostNavigation>(p => | ||
p.Add(param => param.CurrentPage, page.Object)); | ||
|
||
cut.Find("li:last-child").ClassList.Should().Contain("disabled"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotFireNextWhenOnFirstPage() | ||
{ | ||
var page = CreatePagedList(1, 2); | ||
var cut = RenderComponent<BlogPostNavigation>(p => | ||
p.Add(param => param.CurrentPage, page.Object)); | ||
|
||
cut.Find("li:first-child").ClassList.Should().Contain("disabled"); | ||
} | ||
|
||
private static Mock<IPagedList<BlogPost>> CreatePagedList(int currentPage, int pageCount) | ||
{ | ||
var page = new Mock<IPagedList<BlogPost>>(); | ||
page.Setup(p => p.PageNumber).Returns(currentPage); | ||
page.Setup(p => p.PageCount).Returns(pageCount); | ||
page.Setup(p => p.IsFirstPage).Returns(currentPage == 1); | ||
page.Setup(p => p.IsLastPage).Returns(currentPage == pageCount); | ||
|
||
return page; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@using LinkDotNet.Domain | ||
@using X.PagedList | ||
<nav aria-label="Page navigation example"> | ||
<ul class="pagination justify-content-center"> | ||
<li class="page-item @(!CurrentPage.IsFirstPage ? string.Empty : "disabled")"> | ||
<a class="page-link" href="#" tabindex="-1" @onclick="PreviousPage">Previous</a> | ||
</li> | ||
<li class="page-item @(!CurrentPage.IsLastPage ? string.Empty : "disabled")"> | ||
<a class="page-link" | ||
@onclick="NextPage" | ||
href="#">Next</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
|
||
@code { | ||
[Parameter] | ||
public IPagedList<BlogPost> CurrentPage { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<int> OnPageChanged { get; set; } | ||
|
||
private async Task PageHasChanged(int newPage) | ||
{ | ||
await OnPageChanged.InvokeAsync(newPage); | ||
} | ||
|
||
private async Task PreviousPage() | ||
{ | ||
await PageHasChanged(CurrentPage.PageNumber - 1); | ||
} | ||
|
||
private async Task NextPage() | ||
{ | ||
await PageHasChanged(CurrentPage.PageNumber + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.