Skip to content

Commit e0444ce

Browse files
committed
Added Tests for BlogPostNavigation
1 parent 2e70022 commit e0444ce

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

LinkDotNet.Blog.UnitTests/Web/Shared/Admin/CreateNewBlogPostTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Linq;
2-
using AngleSharp.Dom;
32
using Bunit;
43
using FluentAssertions;
54
using LinkDotNet.Blog.TestUtilities;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Bunit;
2+
using FluentAssertions;
3+
using LinkDotNet.Blog.Web.Shared;
4+
using LinkDotNet.Domain;
5+
using Moq;
6+
using X.PagedList;
7+
using Xunit;
8+
9+
namespace LinkDotNet.Blog.UnitTests.Web.Shared
10+
{
11+
public class BlogPostNavigationTests : TestContext
12+
{
13+
[Fact]
14+
public void ShouldFireEventWhenGoingToNextPage()
15+
{
16+
var actualNewPage = 0;
17+
var page = CreatePagedList(2, 3);
18+
var cut = RenderComponent<BlogPostNavigation>(p => p.Add(param => param.CurrentPage, page.Object)
19+
.Add(param => param.OnPageChanged, newPage => actualNewPage = newPage));
20+
21+
cut.Find("li:last-child a").Click();
22+
23+
actualNewPage.Should().Be(3);
24+
}
25+
26+
[Fact]
27+
public void ShouldFireEventWhenGoingToPreviousPage()
28+
{
29+
var actualNewPage = 0;
30+
var page = CreatePagedList(2, 3);
31+
var cut = RenderComponent<BlogPostNavigation>(p => p.Add(param => param.CurrentPage, page.Object)
32+
.Add(param => param.OnPageChanged, newPage => actualNewPage = newPage));
33+
34+
cut.Find("li:first-child a").Click();
35+
36+
actualNewPage.Should().Be(1);
37+
}
38+
39+
[Fact]
40+
public void ShouldNotFireNextWhenOnLastPage()
41+
{
42+
var page = CreatePagedList(2, 2);
43+
var cut = RenderComponent<BlogPostNavigation>(p =>
44+
p.Add(param => param.CurrentPage, page.Object));
45+
46+
cut.Find("li:last-child").ClassList.Should().Contain("disabled");
47+
}
48+
49+
[Fact]
50+
public void ShouldNotFireNextWhenOnFirstPage()
51+
{
52+
var page = CreatePagedList(1, 2);
53+
var cut = RenderComponent<BlogPostNavigation>(p =>
54+
p.Add(param => param.CurrentPage, page.Object));
55+
56+
cut.Find("li:first-child").ClassList.Should().Contain("disabled");
57+
}
58+
59+
private static Mock<IPagedList<BlogPost>> CreatePagedList(int currentPage, int pageCount)
60+
{
61+
var page = new Mock<IPagedList<BlogPost>>();
62+
page.Setup(p => p.PageNumber).Returns(currentPage);
63+
page.Setup(p => p.PageCount).Returns(pageCount);
64+
page.Setup(p => p.IsFirstPage).Returns(currentPage == 1);
65+
page.Setup(p => p.IsLastPage).Returns(currentPage == pageCount);
66+
67+
return page;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)