-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathNavMenuTests.cs
More file actions
126 lines (102 loc) · 4.03 KB
/
NavMenuTests.cs
File metadata and controls
126 lines (102 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using AngleSharp.Html.Dom;
using LinkDotNet.Blog.TestUtilities;
using LinkDotNet.Blog.Web.Features.Home.Components;
using LinkDotNet.Blog.Web.Features.Services;
using LinkDotNet.Blog.Web.Features.Services.Tags;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.Linq;
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared;
public class NavMenuTests : BunitContext
{
public NavMenuTests()
{
ComponentFactories.Add<ThemeToggler, ThemeTogglerStub>();
var tagQueryService = Substitute.For<ITagQueryService>();
Services.AddSingleton(tagQueryService);
Services.AddSingleton(
Options.Create(new ApplicationConfigurationBuilder().Build())
);
}
[Fact]
public void ShouldNavigateToSearchPage()
{
Services.AddScoped(_ => Options.Create(new ApplicationConfigurationBuilder().Build()));
Services.AddScoped(_ => Substitute.For<ICurrentUserService>());
AddAuthorization();
var navigationManager = Services.GetRequiredService<NavigationManager>();
var cut = Render<NavMenu>();
cut.FindComponent<SearchInput>().Find("input").Change("Text");
cut.FindComponent<SearchInput>().Find("button").Click();
navigationManager.Uri.ShouldEndWith("search/Text");
}
[Fact]
public void ShouldDisplayAboutMePage()
{
var config = Options.Create(new ApplicationConfigurationBuilder()
.WithIsAboutMeEnabled(true)
.Build());
Services.AddScoped(_ => config);
Services.AddScoped(_ => Substitute.For<ICurrentUserService>());
AddAuthorization();
var cut = Render<NavMenu>();
cut
.FindAll(".nav-link").ToList()
.Cast<IHtmlAnchorElement>()
.Count(a => a.Href.Contains("AboutMe")).ShouldBe(1);
}
[Fact]
public void ShouldPassCorrectUriToComponent()
{
var config = Options.Create(new ProfileInformationBuilder().Build());
Services.AddScoped(_ => config);
Services.AddScoped(_ => Substitute.For<ICurrentUserService>());
AddAuthorization();
var cut = Render<NavMenu>();
Services.GetRequiredService<NavigationManager>().NavigateTo("test");
cut.FindComponent<AccessControl>().Instance.CurrentUri.ShouldContain("test");
}
[Fact]
public void ShouldShowBrandImageIfAvailable()
{
var config = Options.Create(new ApplicationConfigurationBuilder()
.WithBlogBrandUrl("http://localhost/img.png")
.Build());
Services.AddScoped(_ => config);
Services.AddScoped(_ => Substitute.For<ICurrentUserService>());
var profileInfoConfig = Options.Create(new ProfileInformationBuilder().Build());
Services.AddScoped(_ => profileInfoConfig);
AddAuthorization();
var cut = Render<NavMenu>();
var brandImage = cut.Find(".nav-brand img");
var image = brandImage as IHtmlImageElement;
image.ShouldNotBeNull();
image.Source.ShouldBe("http://localhost/img.png");
}
[Theory]
[InlineData(null!)]
[InlineData("")]
public void ShouldShowBlogNameWhenNotBrand(string? brandUrl)
{
var config = Options.Create(new ApplicationConfigurationBuilder()
.WithBlogBrandUrl(brandUrl)
.WithBlogName("Steven")
.Build());
Services.AddScoped(_ => config);
Services.AddScoped(_ => Substitute.For<ICurrentUserService>());
var profileInfoConfig = Options.Create(new ProfileInformationBuilder().Build());
Services.AddScoped(_ => profileInfoConfig);
AddAuthorization();
var cut = Render<NavMenu>();
var brandImage = cut.Find(".nav-brand");
var image = brandImage as IHtmlAnchorElement;
image.ShouldNotBeNull();
image.TextContent.ShouldBe("Steven");
}
private class ThemeTogglerStub : ComponentBase
{
[Parameter]
public string Class { get; set; } = default!;
}
}