Skip to content

Commit d20b530

Browse files
committed
Added tests for disqus
1 parent f216218 commit d20b530

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

tests/LinkDotNet.Blog.UnitTests/Web/AppConfigurationFactoryTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void ShouldMapFromAppConfiguration()
2929
{ "Giscus:RepositoryId", "repoid" },
3030
{ "Giscus:Category", "general" },
3131
{ "Giscus:CategoryId", "generalid" },
32+
{ "Disqus:Shortname", "blog" },
3233
};
3334
var configuration = new ConfigurationBuilder()
3435
.AddInMemoryCollection(inMemorySettings)
@@ -55,6 +56,7 @@ public void ShouldMapFromAppConfiguration()
5556
appConfiguration.GiscusConfiguration.RepositoryId.Should().Be("repoid");
5657
appConfiguration.GiscusConfiguration.Category.Should().Be("general");
5758
appConfiguration.GiscusConfiguration.CategoryId.Should().Be("generalid");
59+
appConfiguration.DisqusConfiguration.Shortname.Should().Be("blog");
5860
}
5961

6062
[Theory]
@@ -106,7 +108,7 @@ public void ShouldSetIsAboutMeEnabledToFalseWhenNoInformation()
106108
}
107109

108110
[Fact]
109-
public void ShouldSetGiscusToFalseWhenNoInformation()
111+
public void ShouldSetCommentPluginsToFalseWhenNoInformation()
110112
{
111113
var inMemorySettings = new Dictionary<string, string>
112114
{
@@ -122,5 +124,6 @@ public void ShouldSetGiscusToFalseWhenNoInformation()
122124
var appConfiguration = AppConfigurationFactory.Create(configuration);
123125

124126
appConfiguration.IsGiscusEnabled.Should().BeFalse();
127+
appConfiguration.IsDisqusEnabled.Should().BeFalse();
125128
}
126-
}
129+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Linq;
2+
using Bunit;
3+
using FluentAssertions;
4+
using LinkDotNet.Blog.Web;
5+
using LinkDotNet.Blog.Web.Shared;
6+
using LinkDotNet.Blog.Web.Shared.Services;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Xunit;
9+
10+
namespace LinkDotNet.Blog.UnitTests.Web.Shared;
11+
12+
public class DisqusTests : TestContext
13+
{
14+
[Fact]
15+
public void ShouldLoadJavascript()
16+
{
17+
var disqusData = new DisqusConfiguration()
18+
{
19+
Shortname = "blog",
20+
};
21+
Services.AddScoped(_ => new AppConfiguration { DisqusConfiguration = disqusData });
22+
JSInterop.SetupModule("./Shared/Disqus.razor.js");
23+
JSInterop.Mode = JSRuntimeMode.Loose;
24+
25+
RenderComponent<Disqus>();
26+
27+
var init = JSInterop.Invocations.SingleOrDefault(i => i.Identifier == "initDisqus");
28+
init.Should().NotBeNull();
29+
init.Arguments.Should().Contain(disqusData);
30+
}
31+
32+
[Fact]
33+
public void ShouldNotInitDisqusWhenNoInformationProvided()
34+
{
35+
Services.AddScoped(_ => new AppConfiguration());
36+
37+
RenderComponent<Disqus>();
38+
39+
JSInterop.Invocations.Should().BeEmpty();
40+
}
41+
}

0 commit comments

Comments
 (0)