Skip to content

Commit 8de6213

Browse files
committed
Title test for blog post page
1 parent f4cace4 commit 8de6213

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/LinkDotNet.Blog.UnitTests/Web/Pages/BlogPostPageTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
using System.Threading.Tasks;
2+
using Blazored.Toast.Services;
23
using Bunit;
4+
using Bunit.TestDoubles;
35
using LinkDotNet.Blog.Domain;
46
using LinkDotNet.Blog.Infrastructure.Persistence;
57
using LinkDotNet.Blog.TestUtilities;
8+
using LinkDotNet.Blog.Web;
69
using LinkDotNet.Blog.Web.Pages;
710
using LinkDotNet.Blog.Web.Shared;
811
using LinkDotNet.Blog.Web.Shared.Services;
12+
using Microsoft.AspNetCore.Components.Web;
913
using Microsoft.Extensions.DependencyInjection;
1014

1115
namespace LinkDotNet.Blog.UnitTests.Web.Pages;
@@ -32,4 +36,28 @@ public void ShouldShowLoadingAnimation()
3236

3337
cut.FindComponents<Loading>().Count.Should().Be(1);
3438
}
39+
40+
[Fact]
41+
public void ShouldSetTitleToTag()
42+
{
43+
JSInterop.Mode = JSRuntimeMode.Loose;
44+
var repositoryMock = new Mock<IRepository<BlogPost>>();
45+
var blogPost = new BlogPostBuilder().WithTitle("Title").Build();
46+
repositoryMock.Setup(r => r.GetByIdAsync("1")).ReturnsAsync(blogPost);
47+
Services.AddScoped(_ => repositoryMock.Object);
48+
Services.AddScoped(_ => Mock.Of<IUserRecordService>());
49+
Services.AddScoped(_ => Mock.Of<IToastService>());
50+
Services.AddScoped(_ => Mock.Of<AppConfiguration>());
51+
this.AddTestAuthorization();
52+
ComponentFactories.AddStub<PageTitle>();
53+
ComponentFactories.AddStub<Like>();
54+
ComponentFactories.AddStub<CommentSection>();
55+
56+
var cut = RenderComponent<BlogPostPage>(
57+
p => p.Add(s => s.BlogPostId, "1"));
58+
59+
var pageTitleStub = cut.FindComponent<Stub<PageTitle>>();
60+
var pageTitle = Render(pageTitleStub.Instance.Parameters.Get(p => p.ChildContent));
61+
pageTitle.Markup.Should().Be("Title");
62+
}
3563
}

0 commit comments

Comments
 (0)