Skip to content

Commit 22c599b

Browse files
committed
More details for the VisitCountPerPage
1 parent 4af9eef commit 22c599b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Threading.Tasks;
4+
using AngleSharp.Html.Dom;
45
using Bunit;
56
using FluentAssertions;
67
using LinkDotNet.Blog.TestUtilities;
@@ -17,7 +18,7 @@ public class VisitCountPerPageTests : SqlDatabaseTestBase<BlogPost>
1718
[Fact]
1819
public async Task ShouldShowCounts()
1920
{
20-
var blogPost = new BlogPostBuilder().WithTitle("I was clicked").Build();
21+
var blogPost = new BlogPostBuilder().WithTitle("I was clicked").WithLikes(2).Build();
2122
await Repository.StoreAsync(blogPost);
2223
using var ctx = new TestContext();
2324
ctx.Services.AddScoped<IRepository<BlogPost>>(_ => Repository);
@@ -29,9 +30,14 @@ public async Task ShouldShowCounts()
2930
s => s.PageVisitCount, pageVisitCounts));
3031

3132
cut.WaitForState(() => cut.FindAll("td").Any());
32-
var elements = cut.FindAll("td").Select(t => t.InnerHtml).ToList();
33-
elements.Should().Contain("I was clicked");
34-
elements.Should().Contain("5");
33+
var elements = cut.FindAll("td").ToList();
34+
elements.Count.Should().Be(3);
35+
var titleData = elements[0].ChildNodes.Single() as IHtmlAnchorElement;
36+
titleData.Should().NotBeNull();
37+
titleData.InnerHtml.Should().Be(blogPost.Title);
38+
titleData.Href.Should().Contain($"blogPost/{blogPost.Id}");
39+
elements[1].InnerHtml.Should().Be("5");
40+
elements[2].InnerHtml.Should().Be("2");
3541
}
3642
}
3743
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
<div class="card">
66
<div class="card-header">Blog Post Visit Counts</div>
77
<div class="card-body">
8-
<table class="table table-striped">
8+
<table class="table table-striped table-hover">
99
<tbody>
1010
<tr>
1111
<th>Title</th>
1212
<th>Clicks</th>
13+
<th>Likes</th>
1314
</tr>
1415
@if (PageVisitCount != null)
1516
{
16-
@foreach (var pageVisit in blogPostToCountList)
17+
@foreach (var (blogPost, visitCount) in blogPostToCountList)
1718
{
1819
<tr>
19-
<td>@pageVisit.Key</td>
20-
<td>@pageVisit.Value</td>
20+
<td><a href="blogPost/@blogPost.Id">@blogPost.Title</a></td>
21+
<td>@visitCount</td>
22+
<td>@blogPost.Likes</td>
2123
</tr>
2224
}
2325
}
@@ -30,7 +32,7 @@
3032
[Parameter]
3133
public IOrderedEnumerable<KeyValuePair<string, int>> PageVisitCount { get; set; }
3234

33-
private List<KeyValuePair<string, int>> blogPostToCountList = new();
35+
private List<KeyValuePair<BlogPost, int>> blogPostToCountList = new();
3436

3537
protected override async Task OnParametersSetAsync()
3638
{
@@ -39,18 +41,18 @@
3941
return;
4042
}
4143

42-
foreach (var (blogPost, clickCount) in PageVisitCount)
44+
foreach (var (blogPostUrl, clickCount) in PageVisitCount)
4345
{
44-
var blogPostId = blogPost[(blogPost.IndexOf('/') + 1)..];
46+
var blogPostId = blogPostUrl[(blogPostUrl.IndexOf('/') + 1)..];
4547

4648
if (string.IsNullOrEmpty(blogPostId))
4749
{
4850
continue;
4951
}
5052

51-
var blogPostTitle = (await blogPostRepository.GetByIdAsync(blogPostId)).Title;
53+
var blogPost = (await blogPostRepository.GetByIdAsync(blogPostId));
5254

53-
blogPostToCountList.Add(new KeyValuePair<string, int>(blogPostTitle, clickCount));
55+
blogPostToCountList.Add(new KeyValuePair<BlogPost, int>(blogPost, clickCount));
5456
}
5557
}
5658
}

0 commit comments

Comments
 (0)