Skip to content

Commit b4db2f5

Browse files
E2E test for enhanced nav auto-disabling itself for non-Blazor endpoints
1 parent 9ae8dd8 commit b4db2f5

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Xunit.Abstractions;
99
using Components.TestServer.RazorComponents;
1010
using OpenQA.Selenium;
11+
using OpenQA.Selenium.Support.Extensions;
1112

1213
namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests;
1314

@@ -307,6 +308,18 @@ public void RefreshWithForceReloadDoesFullPageReload(string renderMode)
307308
Assert.EndsWith("/nav", Browser.Url);
308309
}
309310

311+
[Fact]
312+
public void EnhancedNavNotUsedForNonBlazorDestinations()
313+
{
314+
Navigate($"{ServerPathBase}/nav");
315+
Browser.Equal("Hello", () => Browser.Exists(By.TagName("h1")).Text);
316+
Assert.Equal("object", Browser.ExecuteJavaScript<string>("return typeof Blazor")); // Blazor JS is loaded
317+
318+
Browser.Exists(By.TagName("nav")).FindElement(By.LinkText("Non-Blazor HTML page")).Click();
319+
Browser.Equal("This is a non-Blazor endpoint", () => Browser.Exists(By.TagName("h1")).Text);
320+
Assert.Equal("undefined", Browser.ExecuteJavaScript<string>("return typeof Blazor")); // Blazor JS is NOT loaded
321+
}
322+
310323
private static bool IsElementStale(IWebElement element)
311324
{
312325
try

src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ private static void MapEnhancedNavigationEndpoints(IEndpointRouteBuilder endpoin
145145
endpoints.MapGet("redirect/nonblazor/get", PerformRedirection);
146146
endpoints.MapPost("redirect/nonblazor/post", PerformRedirection);
147147

148+
// Used when testing enhanced navigation to non-Blazor endpoints
149+
endpoints.Map("/nav/non-blazor-html-response", async (HttpResponse response) =>
150+
{
151+
response.ContentType = "text/html";
152+
await response.WriteAsync("<html><body><h1>This is a non-Blazor endpoint</h1><p>That's all</p></body></html>");
153+
});
154+
148155
static Task PerformRedirection(HttpRequest request, HttpResponse response)
149156
{
150157
response.Redirect(request.Query["external"] == "true"

src/Components/test/testassets/Components.TestServer/RazorComponents/Shared/EnhancedNavLayout.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<NavLink href="nav/give-404-with-content">Error page with 404 content</NavLink> |
88
<NavLink href="nav/nonexistent-page">Error page with no content</NavLink> |
99
<NavLink href="nav/non-html-response">Non-HTML page</NavLink> |
10+
<NavLink href="nav/non-blazor-html-response">Non-Blazor HTML page</NavLink> |
1011
<NavLink href="nav/scroll-to-hash#some-content">Scroll to hash</NavLink> |
1112
<NavLink href="nav/throw-while-streaming">Error while streaming</NavLink> |
1213
<NavLink href="nav/interactive-component-navigation/server">Interactive component navigation (server)</NavLink> |

0 commit comments

Comments
 (0)