Skip to content

Commit d5a28bd

Browse files
committed
Escape Uri and added test
1 parent cb4ed20 commit d5a28bd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Bunit;
2+
using Bunit.TestDoubles;
3+
using FluentAssertions;
4+
using LinkDotNet.Blog.Web;
5+
using LinkDotNet.Blog.Web.Shared;
6+
using Microsoft.AspNetCore.Components;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Xunit;
9+
10+
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared
11+
{
12+
public class NavMenuTests : TestContext
13+
{
14+
[Fact]
15+
public void ShouldNavigateToSearchPage()
16+
{
17+
Services.AddScoped(_ => new AppConfiguration());
18+
this.AddTestAuthorization();
19+
var navigationManager = Services.GetRequiredService<NavigationManager>();
20+
var cut = RenderComponent<NavMenu>();
21+
cut.FindComponent<SearchInput>().Find("input").Change("Text");
22+
23+
cut.FindComponent<SearchInput>().Find("button").Click();
24+
25+
navigationManager.Uri.Should().EndWith("search/Text");
26+
}
27+
}
28+
}

LinkDotNet.Blog.Web/Shared/NavMenu.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@code {
3232
private void NavigateToSearchPage(string searchTerm)
3333
{
34-
navigationManager.NavigateTo($"search/{searchTerm}");
34+
var escapeDataString = Uri.EscapeDataString(searchTerm);
35+
navigationManager.NavigateTo($"search/{escapeDataString}");
3536
}
3637
}

0 commit comments

Comments
 (0)