Skip to content

Commit

Permalink
refactor: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Nov 1, 2024
1 parent 53fd154 commit 603b2a5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@page "/SupportMe"
@using LinkDotNet.Blog.Domain
@using LinkDotNet.Blog.Web.Features.SupportMe.Components
@inject IOptions<SupportMeConfiguration> SupportConfiguration
@inject NavigationManager NavigationManager
@inject IOptions<ProfileInformation> ProfileInformation
@namespace LinkDotNet.Blog.Web.Features.SupportMe.Components

@if (SupportConfiguration.Value.ShowSupportMePage)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ public SupportMeConfigurationBuilder WithPatreonName(string? patreonName)
return this;
}

public SupportMeConfigurationBuilder WithShowUnderBlogPost(bool showUnderBlogPost)
public SupportMeConfigurationBuilder WithShowUnderBlogPost(bool showUnderBlogPost = true)
{
this.showUnderBlogPost = showUnderBlogPost;
return this;
}

public SupportMeConfigurationBuilder WithshowUnderIntroduction(bool showUnderIntroduction)
public SupportMeConfigurationBuilder WithShowUnderIntroduction(bool showUnderIntroduction = true)
{
this.showUnderIntroduction = showUnderIntroduction;
return this;
}

public SupportMeConfigurationBuilder WithShowInFooter(bool showInFooter)
public SupportMeConfigurationBuilder WithShowInFooter(bool showInFooter = true)
{
this.showInFooter = showInFooter;
return this;
}

public SupportMeConfigurationBuilder WithShowSupportMePage(bool showSupportMePage)
public SupportMeConfigurationBuilder WithShowSupportMePage(bool showSupportMePage = true)
{
this.showSupportMePage = showSupportMePage;
return this;
}

public SupportMeConfigurationBuilder WithSupportMePageDescription(string? supportMePageDescription)
public SupportMeConfigurationBuilder WithSupportMePageDescription(string supportMePageDescription)
{
this.supportMePageDescription = supportMePageDescription;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web.Features.Components;
using LinkDotNet.Blog.Web.Features.SupportMe;
using LinkDotNet.Blog.Web.Features.SupportMe.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace LinkDotNet.Blog.UnitTests.Web.Features.SupportMe;

public class SupportMePageTests : BunitContext
{
[Fact]
public void ShouldRenderSupportMePage()
{
Services.AddScoped(_ => Options.Create(new ProfileInformationBuilder().Build()));
var supportMe = new SupportMeConfigurationBuilder()
.WithShowSupportMePage()
.WithSupportMePageDescription("**FooBar**")
.Build();
Services.AddScoped(_ => Options.Create(supportMe));

var cut = Render<SupportMePage>();

cut.HasComponent<DonationSection>().ShouldBeTrue();
cut.Find(".container > div").TextContent.ShouldContain("FooBar");
}

[Fact]
public void PageDescriptionCanHandleMarkup()
{
Services.AddScoped(_ => Options.Create(new ProfileInformationBuilder().Build()));
var supportMe = new SupportMeConfigurationBuilder()
.WithShowSupportMePage()
.WithSupportMePageDescription("**FooBar**")
.Build();
Services.AddScoped(_ => Options.Create(supportMe));

var cut = Render<SupportMePage>();

cut.Find(".container > div").InnerHtml.ShouldContain("<strong>FooBar</strong>");
}

[Fact]
public void ShouldSetOgDataForSupportPage()
{
var profile = new ProfileInformationBuilder()
.WithName("LinkDotNet")
.Build();
Services.AddScoped(_ => Options.Create(profile));
var supportMe = new SupportMeConfigurationBuilder()
.WithShowSupportMePage()
.Build();
Services.AddScoped(_ => Options.Create(supportMe));

var cut = Render<SupportMePage>();

var ogData = cut.FindComponent<OgData>();
ogData.Instance.Title.ShouldBe("Support Me - LinkDotNet");
ogData.Instance.Description.ShouldBe("Support Me - LinkDotNet");
ogData.Instance.Keywords.ShouldNotBeNull();
ogData.Instance.Keywords.ShouldContain("Support");
ogData.Instance.Keywords.ShouldContain("Donation");
ogData.Instance.Keywords.ShouldContain("LinkDotNet");
}
}

0 comments on commit 603b2a5

Please sign in to comment.