Skip to content

Commit 989dd41

Browse files
committed
Check for empty strings for brandurl and background
1 parent 8fcca9e commit 989dd41

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/LinkDotNet.Blog.Web/Shared/IntroductionCard.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
[Parameter]
1515
public Introduction Introduction { get; set; }
1616

17-
private string IntroductionClass => Introduction.BackgroundUrl != null ? "introduction-background" : string.Empty;
17+
private string IntroductionClass => !string.IsNullOrEmpty(Introduction.BackgroundUrl)
18+
? "introduction-background"
19+
: string.Empty;
1820
}

src/LinkDotNet.Blog.Web/Shared/NavMenu.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<nav class="navbar navbar-expand-lg navbar-light w-100">
66
<div class="container-fluid">
7-
@if (configuration.BlogBrandUrl != null)
7+
@if (!string.IsNullOrEmpty(configuration.BlogBrandUrl))
88
{
99
<a class="nav-brand ms-5" href="/">
1010
<img style="max-height: 70px;"

tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,30 @@ public void ShouldShowBrandImageIfAvailable()
9999
var cut = RenderComponent<NavMenu>();
100100

101101
var brandImage = cut.Find(".nav-brand img");
102-
103102
var image = brandImage.Unwrap() as IHtmlImageElement;
104103
image.Should().NotBeNull();
105104
image.Source.Should().Be("http://localhost/img.png");
106105
}
106+
107+
[Theory]
108+
[InlineData(null)]
109+
[InlineData("")]
110+
public void ShouldShowBlogNameWhenNotBrand(string brandUrl)
111+
{
112+
var config = new AppConfiguration
113+
{
114+
ProfileInformation = new ProfileInformation(),
115+
BlogBrandUrl = brandUrl,
116+
BlogName = "Steven",
117+
};
118+
Services.AddScoped(_ => config);
119+
this.AddTestAuthorization();
120+
121+
var cut = RenderComponent<NavMenu>();
122+
123+
var brandImage = cut.Find(".nav-brand");
124+
var image = brandImage.Unwrap() as IHtmlAnchorElement;
125+
image.Should().NotBeNull();
126+
image.TextContent.Should().Be("Steven");
127+
}
107128
}

tests/LinkDotNet.Blog.UnitTests/Web/Shared/IntroductionCardTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class IntroductionCardTests : TestContext
1111
[Fact]
1212
public void ShouldSetBackgroundWhenSet()
1313
{
14-
var introduction = new Introduction()
14+
var introduction = new Introduction
1515
{
1616
BackgroundUrl = "something_but_null",
1717
};
@@ -24,4 +24,21 @@ public void ShouldSetBackgroundWhenSet()
2424
background.Should().HaveCount(1);
2525
background.Single().GetStyle().CssText.Should().Contain(introduction.BackgroundUrl);
2626
}
27+
28+
[Theory]
29+
[InlineData(null)]
30+
[InlineData("")]
31+
public void ShouldNotSetBackgroundWhenNotSet(string url)
32+
{
33+
var introduction = new Introduction
34+
{
35+
BackgroundUrl = url,
36+
};
37+
38+
var cut = RenderComponent<IntroductionCard>(
39+
p => p.Add(s => s.Introduction, introduction));
40+
41+
var background = cut.FindAll(".introduction-background");
42+
background.Should().BeNullOrEmpty();
43+
}
2744
}

0 commit comments

Comments
 (0)