Skip to content

Commit 9161450

Browse files
committed
Added Test for filtering
1 parent 5ee4a7a commit 9161450

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/Admin/Dashboard/VisitCountPerPageTests.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using AngleSharp.Html.Dom;
45
using Bunit;
@@ -11,7 +12,7 @@
1112

1213
namespace LinkDotNet.Blog.IntegrationTests.Web.Pages.Admin.Dashboard
1314
{
14-
public sealed class VisitCountPerPageTests : SqlDatabaseTestBase<BlogPost>
15+
public class VisitCountPerPageTests : SqlDatabaseTestBase<BlogPost>
1516
{
1617
[Fact]
1718
public async Task ShouldShowCounts()
@@ -35,6 +36,37 @@ public async Task ShouldShowCounts()
3536
elements[2].InnerHtml.Should().Be("2");
3637
}
3738

39+
[Fact]
40+
public async Task ShouldFilterStartDate()
41+
{
42+
var blogPost1 = new BlogPostBuilder().WithTitle("1").WithLikes(2).Build();
43+
var blogPost2 = new BlogPostBuilder().WithTitle("2").WithLikes(2).Build();
44+
await Repository.StoreAsync(blogPost1);
45+
await Repository.StoreAsync(blogPost2);
46+
var urlClicked1New = new UserRecord
47+
{ UrlClicked = $"blogPost/{blogPost1.Id}", DateTimeUtcClicked = DateTime.UtcNow };
48+
var urlClicked1Old = new UserRecord
49+
{ UrlClicked = $"blogPost/{blogPost1.Id}", DateTimeUtcClicked = DateTime.MinValue };
50+
var urlClicked2 = new UserRecord
51+
{ UrlClicked = $"blogPost/{blogPost2.Id}", DateTimeUtcClicked = DateTime.MinValue };
52+
await DbContext.UserRecords.AddRangeAsync(new[] { urlClicked1New, urlClicked1Old, urlClicked2 });
53+
await DbContext.SaveChangesAsync();
54+
using var ctx = new TestContext();
55+
ctx.Services.AddScoped(_ => DbContext);
56+
var cut = ctx.RenderComponent<VisitCountPerPage>();
57+
58+
cut.FindComponent<DateRangeSelector>().Find("select").Change(DateTime.UtcNow.Date);
59+
60+
cut.WaitForState(() => cut.FindAll("td").Any());
61+
var elements = cut.FindAll("td").ToList();
62+
elements.Count.Should().Be(3);
63+
var titleData = elements[0].ChildNodes.Single() as IHtmlAnchorElement;
64+
titleData.Should().NotBeNull();
65+
titleData.InnerHtml.Should().Be(blogPost1.Title);
66+
titleData.Href.Should().Contain($"blogPost/{blogPost1.Id}");
67+
elements[1].InnerHtml.Should().Be("1");
68+
}
69+
3870
private async Task SaveBlogPostArticleClicked(string blogPostId, int count)
3971
{
4072
var urlClicked = $"blogPost/{blogPostId}";

LinkDotNet.Blog.UnitTests/Web/Pages/Admin/DashboardTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using FluentAssertions;
55
using LinkDotNet.Blog.Domain;
66
using LinkDotNet.Blog.Infrastructure.Persistence;
7+
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
78
using LinkDotNet.Blog.Web;
89
using LinkDotNet.Blog.Web.Pages.Admin;
910
using LinkDotNet.Blog.Web.Shared.Admin.Dashboard;
11+
using Microsoft.EntityFrameworkCore;
1012
using Microsoft.Extensions.DependencyInjection;
1113
using Moq;
1214
using Xunit;

LinkDotNet.Blog.Web/Shared/Admin/Dashboard/VisitCountPerPage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
private async Task LoadBlogPostInformationAsync()
5252
{
5353
visitData = await (from ur in blogDbContext.UserRecords
54-
where ur.DateTimeUtcClicked > startDate
54+
where ur.DateTimeUtcClicked >= startDate
5555
join bp in blogDbContext.BlogPosts
5656
on ur.UrlClicked.Replace("blogPost/", string.Empty) equals bp.Id
5757
group new { ur, bp } by new { ur.UrlClicked }

0 commit comments

Comments
 (0)