Skip to content

Commit 316897c

Browse files
committed
Show only published blog posts in main overview
1 parent fcc0b60 commit 316897c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/IndexTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ public async Task ShouldShowAllBlogPostsWithLatestOneFirst()
3434
blogPosts[1].Find(".description h1").InnerHtml.Should().Be("Old");
3535
}
3636

37+
[Fact]
38+
public async Task ShouldOnlyShowPublishedPosts()
39+
{
40+
var publishedPost = new BlogPostBuilder().WithTitle("Published").IsPublished().Build();
41+
var unpublishedPost = new BlogPostBuilder().WithTitle("Not published").IsPublished(false).Build();
42+
await BlogPostRepository.StoreAsync(publishedPost);
43+
await BlogPostRepository.StoreAsync(unpublishedPost);
44+
using var ctx = new TestContext();
45+
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
46+
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
47+
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
48+
var cut = ctx.RenderComponent<Index>();
49+
50+
var blogPosts = cut.FindComponents<ShortBlogPost>();
51+
52+
blogPosts.Should().HaveCount(1);
53+
blogPosts[0].Find(".description h1").InnerHtml.Should().Be("Published");
54+
}
55+
3756
private static AppConfiguration CreateSampleAppConfiguration()
3857
{
3958
return new()

LinkDotNet.Blog.Web/Pages/Index.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
IList<BlogPost> _blogPosts = new List<BlogPost>();
2424
protected override async Task OnInitializedAsync()
2525
{
26-
_blogPosts = (await _repository.GetAllAsync(orderBy: b => b.UpdatedDate)).ToList();
26+
_blogPosts = (await _repository.GetAllAsync(p => p.IsPublished, b => b.UpdatedDate)).ToList();
2727
}
2828

2929
private string GetAbsolutePreviewImageUrl()

0 commit comments

Comments
 (0)