Skip to content

Commit

Permalink
fix: Social Accounts and Show youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Nov 1, 2024
1 parent ddb0033 commit d3065c2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/LinkDotNet.Blog.Domain/Social.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public sealed record Social
{
public const string SocialSection = "Social";

public string? LinkedinAccountUrl { get; init; }
public string? LinkedInAccountUrl { get; init; }

public bool HasLinkedinAccount => !string.IsNullOrEmpty(LinkedinAccountUrl);
public bool HasLinkedinAccount => !string.IsNullOrEmpty(LinkedInAccountUrl);

public string? GithubAccountUrl { get; init; }

Expand All @@ -15,4 +15,8 @@ public sealed record Social
public string? TwitterAccountUrl { get; init; }

public bool HasTwitterAccount => !string.IsNullOrEmpty(TwitterAccountUrl);

public string? YoutubeAccountUrl { get; init; }

public bool HasYoutubeAccount => !string.IsNullOrEmpty(YoutubeAccountUrl);
}
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Web/ConfigurationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static IServiceCollection AddSocialConfigurations(this IServiceCollectio
{
ArgumentNullException.ThrowIfNull(services);

services.AddOptions<AuthInformation>()
services.AddOptions<Social>()
.Configure<IConfiguration>((settings, config) =>
{
config.GetSection(Social.SocialSection).Bind(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="d-flex flex-row justify-content-center" style="font-size: 1.25em;">
@if (Social.HasLinkedinAccount)
{
<a id="linkedin" class="nav-link px-3 py-2" target="_blank" href="@Social.LinkedinAccountUrl" aria-label="LinkedIn" rel="noreferrer">
<a id="linkedin" class="nav-link px-3 py-2" target="_blank" href="@Social.LinkedInAccountUrl" aria-label="LinkedIn" rel="noreferrer">
<i class="linkedin"></i>
</a>
}
Expand All @@ -18,6 +18,13 @@
<i class="twitter"></i>
</a>
}

@if (Social.HasYoutubeAccount)
{
<a id="youtube" class="nav-link px-3 py-2" target="_blank" href="@Social.YoutubeAccountUrl" aria-label="Youtube" rel="noreferrer">
<i class="youtube"></i>
</a>
}
</div>

@code {
Expand Down
3 changes: 2 additions & 1 deletion src/LinkDotNet.Blog.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"Social": {
"GithubAccountUrl": "",
"LinkedInAccountUrl": "",
"TwitterAccountUrl": ""
"TwitterAccountUrl": "",
"YoutubeAccountUrl": ""
},
"Introduction": {
"Description": "A small introduction to your **blog**. Can be in markdown",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void ShouldMapFromAppConfiguration()
configuration.GetSection(Social.SocialSection).Bind(social);
social.GithubAccountUrl.ShouldBe("github");
social.HasGithubAccount.ShouldBeTrue();
social.LinkedinAccountUrl.ShouldBe("linkedIn");
social.LinkedInAccountUrl.ShouldBe("linkedIn");
social.HasLinkedinAccount.ShouldBeTrue();
social.TwitterAccountUrl.ShouldBe("twitter");
social.HasTwitterAccount.ShouldBeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.Home.Components;
public class SocialAccountTests : BunitContext
{
[Theory]
[InlineData(null, null, null, false, false, false)]
[InlineData(null, "linkedin", null, false, true, false)]
[InlineData("github", null, null, true, false, false)]
[InlineData(null, null, "twitter", false, false, true)]
[InlineData(null, null, null, null, false, false, false, false)]
[InlineData(null, "linkedin", null, null, false, true, false, false)]
[InlineData("github", null, null, null, true, false, false, false)]
[InlineData(null, null, "twitter", null, false, false, true, false)]
[InlineData(null, null, null, "youtube", false, false, false, true)]
public void ShouldDisplayGithubAndLinkedInPageWhenOnlyWhenSet(
string? github,
string? linkedin,
string? twitter,
string? youtube,
bool githubAvailable,
bool linkedinAvailable,
bool twitterAvailable)
bool twitterAvailable,
bool youtubeAvailable)
{
var social = new Social
{
GithubAccountUrl = github,
LinkedinAccountUrl = linkedin,
LinkedInAccountUrl = linkedin,
TwitterAccountUrl = twitter,
YoutubeAccountUrl = youtube,
};

var cut = Render<SocialAccounts>(s => s.Add(p => p.Social, social));

cut.FindAll("#github").Any().ShouldBe(githubAvailable);
cut.FindAll("#linkedin").Any().ShouldBe(linkedinAvailable);
cut.FindAll("#twitter").Any().ShouldBe(twitterAvailable);
cut.FindAll("#youtube").Any().ShouldBe(youtubeAvailable);
}
}

0 comments on commit d3065c2

Please sign in to comment.