Skip to content

Commit 1695119

Browse files
committed
Smaller refactoring
1 parent 84b9818 commit 1695119

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private void RegisterComponents(TestContextBase ctx, ILocalStorageService localS
8787
ctx.Services.AddScoped(_ => new Mock<IToastService>().Object);
8888
ctx.Services.AddScoped(_ => new Mock<IHeadElementHelper>().Object);
8989
ctx.Services.AddScoped(_ => new Mock<IUserRecordService>().Object);
90+
ctx.Services.AddScoped(_ => new Mock<IGiscusService>().Object);
9091
}
9192
}
9293
}

LinkDotNet.Blog.UnitTests/Web/Pages/AboutMeTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AboutMeTests : TestContext
2626
public void ShouldPassIsAuthenticated()
2727
{
2828
this.AddTestAuthorization().SetAuthorized("test");
29-
var config = CreateAppConfiguration(true);
29+
var config = CreateAppConfiguration(new ProfileInformation { ProfilePictureUrl = string.Empty });
3030
SetupMocks(config);
3131

3232
var cut = RenderComponent<AboutMe>();
@@ -39,7 +39,7 @@ public void ShouldPassIsAuthenticated()
3939
public void ShouldNotShowWhenEnabledFalse()
4040
{
4141
this.AddTestAuthorization().SetNotAuthorized();
42-
var config = CreateAppConfiguration(false);
42+
var config = CreateAppConfiguration();
4343
SetupMocks(config);
4444

4545
var cut = RenderComponent<AboutMe>();
@@ -57,7 +57,7 @@ public void ShouldSetOgData()
5757
Name = "My Name",
5858
ProfilePictureUrl = "someurl",
5959
};
60-
var config = CreateAppConfiguration(false, profileInformation);
60+
var config = CreateAppConfiguration(profileInformation);
6161
SetupMocks(config);
6262

6363
var cut = RenderComponent<AboutMe>();
@@ -69,15 +69,11 @@ public void ShouldSetOgData()
6969
ogData.Description.Should().Contain("About Me,My Name");
7070
}
7171

72-
private static AppConfiguration CreateAppConfiguration(bool pageEnabled, ProfileInformation info = null)
72+
private static AppConfiguration CreateAppConfiguration(ProfileInformation info = null)
7373
{
7474
return new AppConfiguration
7575
{
76-
IsAboutMeEnabled = pageEnabled,
77-
ProfileInformation = info ?? new ProfileInformation
78-
{
79-
ProfilePictureUrl = "not null",
80-
},
76+
ProfileInformation = info,
8177
};
8278
}
8379

LinkDotNet.Blog.UnitTests/Web/Pages/Admin/DashboardTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static AppConfiguration CreateAppConfiguration(bool aboutMeEnabled)
3838
{
3939
return new AppConfiguration
4040
{
41-
IsAboutMeEnabled = aboutMeEnabled,
41+
ProfileInformation = aboutMeEnabled ? new ProfileInformation() : null,
4242
};
4343
}
4444
}

LinkDotNet.Blog.UnitTests/Web/Shared/Services/GiscusServiceTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,16 @@ public async Task ShouldInitGiscus()
2424
init.Arguments.Should().Contain("giscus");
2525
init.Arguments.Should().Contain(giscus);
2626
}
27+
28+
[Fact]
29+
public async Task ShouldNotEnabledGiscussWhenNotSet()
30+
{
31+
JSInterop.Mode = JSRuntimeMode.Loose;
32+
var sut = new GiscusService(JSInterop.JSRuntime, new AppConfiguration { Giscus = null });
33+
34+
await sut.EnableCommentSection("div");
35+
36+
JSInterop.Invocations.Any(i => i.Identifier == "initGiscus").Should().BeFalse();
37+
}
2738
}
2839
}

LinkDotNet.Blog.Web/AppConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public record AppConfiguration
2323

2424
public int BlogPostsPerPage { get; init; }
2525

26-
public bool IsAboutMeEnabled { get; init; }
26+
public bool IsAboutMeEnabled => ProfileInformation != null;
2727

2828
public ProfileInformation ProfileInformation { get; init; }
2929

3030
public Giscus Giscus { get; init; }
31-
32-
public bool IsGiscusEnabled { get; init; }
31+
32+
public bool IsGiscusEnabled => Giscus != null;
3333
}
3434
}

LinkDotNet.Blog.Web/AppConfigurationFactory.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public static AppConfiguration Create(IConfiguration config)
2020
DatabaseName = config["DatabaseName"],
2121
BlogPostsPerPage = int.Parse(config["BlogPostsPerPage"]),
2222
ProfileInformation = profileInformation,
23-
IsAboutMeEnabled = profileInformation != null,
2423
Giscus = giscus,
25-
IsGiscusEnabled = giscus != null,
2624
};
2725

2826
return configuration;

LinkDotNet.Blog.Web/Pages/AboutMe.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
@inject AuthenticationStateProvider authenticationStateProvider
66
@inject IUserRecordService userRecordService
77
@inject NavigationManager navigationManager
8-
<OgData Title="@("About Me - " + appConfiguration.ProfileInformation.Name)"
9-
Description="@("About Me," + appConfiguration.ProfileInformation.Name)"
10-
Keywords="@appConfiguration.ProfileInformation.Name"
11-
AbsolutePreviewImageUrl="@ImageUrl"></OgData>
12-
138
@if (appConfiguration.IsAboutMeEnabled)
149
{
10+
<OgData Title="@("About Me - " + appConfiguration.ProfileInformation.Name)"
11+
Description="@("About Me," + appConfiguration.ProfileInformation.Name)"
12+
Keywords="@appConfiguration.ProfileInformation.Name"
13+
AbsolutePreviewImageUrl="@ImageUrl"></OgData>
14+
1515
<div class="page">
1616
<div class="container">
1717
<div class="row">

LinkDotNet.Blog.Web/Shared/Services/GiscusService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public GiscusService(IJSRuntime jsRuntime, AppConfiguration appConfiguration)
1616

1717
public async Task EnableCommentSection(string className)
1818
{
19-
await jsRuntime.InvokeVoidAsync("initGiscus", "giscus", appConfiguration.Giscus);
19+
if (appConfiguration.IsGiscusEnabled)
20+
{
21+
await jsRuntime.InvokeVoidAsync("initGiscus", "giscus", appConfiguration.Giscus);
22+
}
2023
}
2124
}
2225
}

0 commit comments

Comments
 (0)