Skip to content

Commit 603b2a5

Browse files
committed
refactor: added tests
1 parent 53fd154 commit 603b2a5

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

src/LinkDotNet.Blog.Web/Features/SupportMe/SupportMePage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@page "/SupportMe"
22
@using LinkDotNet.Blog.Domain
3+
@using LinkDotNet.Blog.Web.Features.SupportMe.Components
34
@inject IOptions<SupportMeConfiguration> SupportConfiguration
45
@inject NavigationManager NavigationManager
56
@inject IOptions<ProfileInformation> ProfileInformation
6-
@namespace LinkDotNet.Blog.Web.Features.SupportMe.Components
77

88
@if (SupportConfiguration.Value.ShowSupportMePage)
99
{

tests/LinkDotNet.Blog.TestUtilities/SupportMeConfigurationBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ public SupportMeConfigurationBuilder WithPatreonName(string? patreonName)
3232
return this;
3333
}
3434

35-
public SupportMeConfigurationBuilder WithShowUnderBlogPost(bool showUnderBlogPost)
35+
public SupportMeConfigurationBuilder WithShowUnderBlogPost(bool showUnderBlogPost = true)
3636
{
3737
this.showUnderBlogPost = showUnderBlogPost;
3838
return this;
3939
}
4040

41-
public SupportMeConfigurationBuilder WithshowUnderIntroduction(bool showUnderIntroduction)
41+
public SupportMeConfigurationBuilder WithShowUnderIntroduction(bool showUnderIntroduction = true)
4242
{
4343
this.showUnderIntroduction = showUnderIntroduction;
4444
return this;
4545
}
4646

47-
public SupportMeConfigurationBuilder WithShowInFooter(bool showInFooter)
47+
public SupportMeConfigurationBuilder WithShowInFooter(bool showInFooter = true)
4848
{
4949
this.showInFooter = showInFooter;
5050
return this;
5151
}
5252

53-
public SupportMeConfigurationBuilder WithShowSupportMePage(bool showSupportMePage)
53+
public SupportMeConfigurationBuilder WithShowSupportMePage(bool showSupportMePage = true)
5454
{
5555
this.showSupportMePage = showSupportMePage;
5656
return this;
5757
}
5858

59-
public SupportMeConfigurationBuilder WithSupportMePageDescription(string? supportMePageDescription)
59+
public SupportMeConfigurationBuilder WithSupportMePageDescription(string supportMePageDescription)
6060
{
6161
this.supportMePageDescription = supportMePageDescription;
6262
return this;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using LinkDotNet.Blog.TestUtilities;
2+
using LinkDotNet.Blog.Web.Features.Components;
3+
using LinkDotNet.Blog.Web.Features.SupportMe;
4+
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Options;
7+
8+
namespace LinkDotNet.Blog.UnitTests.Web.Features.SupportMe;
9+
10+
public class SupportMePageTests : BunitContext
11+
{
12+
[Fact]
13+
public void ShouldRenderSupportMePage()
14+
{
15+
Services.AddScoped(_ => Options.Create(new ProfileInformationBuilder().Build()));
16+
var supportMe = new SupportMeConfigurationBuilder()
17+
.WithShowSupportMePage()
18+
.WithSupportMePageDescription("**FooBar**")
19+
.Build();
20+
Services.AddScoped(_ => Options.Create(supportMe));
21+
22+
var cut = Render<SupportMePage>();
23+
24+
cut.HasComponent<DonationSection>().ShouldBeTrue();
25+
cut.Find(".container > div").TextContent.ShouldContain("FooBar");
26+
}
27+
28+
[Fact]
29+
public void PageDescriptionCanHandleMarkup()
30+
{
31+
Services.AddScoped(_ => Options.Create(new ProfileInformationBuilder().Build()));
32+
var supportMe = new SupportMeConfigurationBuilder()
33+
.WithShowSupportMePage()
34+
.WithSupportMePageDescription("**FooBar**")
35+
.Build();
36+
Services.AddScoped(_ => Options.Create(supportMe));
37+
38+
var cut = Render<SupportMePage>();
39+
40+
cut.Find(".container > div").InnerHtml.ShouldContain("<strong>FooBar</strong>");
41+
}
42+
43+
[Fact]
44+
public void ShouldSetOgDataForSupportPage()
45+
{
46+
var profile = new ProfileInformationBuilder()
47+
.WithName("LinkDotNet")
48+
.Build();
49+
Services.AddScoped(_ => Options.Create(profile));
50+
var supportMe = new SupportMeConfigurationBuilder()
51+
.WithShowSupportMePage()
52+
.Build();
53+
Services.AddScoped(_ => Options.Create(supportMe));
54+
55+
var cut = Render<SupportMePage>();
56+
57+
var ogData = cut.FindComponent<OgData>();
58+
ogData.Instance.Title.ShouldBe("Support Me - LinkDotNet");
59+
ogData.Instance.Description.ShouldBe("Support Me - LinkDotNet");
60+
ogData.Instance.Keywords.ShouldNotBeNull();
61+
ogData.Instance.Keywords.ShouldContain("Support");
62+
ogData.Instance.Keywords.ShouldContain("Donation");
63+
ogData.Instance.Keywords.ShouldContain("LinkDotNet");
64+
}
65+
}

0 commit comments

Comments
 (0)