Skip to content

Commit 66cc974

Browse files
committed
Per-component interactivity: test navigation to non-existing page.
1 parent 5fff491 commit 66cc974

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,4 +1411,41 @@ public void NavigatesWithInteractivityByRequestRedirection(bool controlFlowByExc
14111411
Browser.Click(By.Id("redirectButton"));
14121412
Browser.Equal("Routing test cases", () => Browser.Exists(By.Id("test-info")).Text);
14131413
}
1414+
1415+
[Theory]
1416+
// prerendering (SSR) is tested in NoInteractivityTest
1417+
[InlineData("ServerNonPrerendered")]
1418+
[InlineData("WebAssemblyNonPrerendered")]
1419+
public void ProgrammaticNavigationToNotExistingPathReExecutesTo404(string renderMode)
1420+
{
1421+
Navigate($"{ServerPathBase}/reexecution/redirection-not-found?render-mode={renderMode}&navigate-programmatically=true");
1422+
Assert404ReExecuted();
1423+
}
1424+
1425+
[Theory]
1426+
// prerendering (SSR) is tested in NoInteractivityTest
1427+
[InlineData("ServerNonPrerendered")]
1428+
[InlineData("WebAssemblyNonPrerendered")]
1429+
public void LinkNavigationToNotExistingPathReExecutesTo404(string renderMode)
1430+
{
1431+
Navigate($"{ServerPathBase}/reexecution/redirection-not-found?render-mode={renderMode}");
1432+
Browser.Click(By.Id("link-to-not-existing-page"));
1433+
Assert404ReExecuted();
1434+
}
1435+
1436+
[Theory]
1437+
// prerendering (SSR) is tested in NoInteractivityTest
1438+
[InlineData("ServerNonPrerendered")]
1439+
[InlineData("WebAssemblyNonPrerendered")]
1440+
public void BrowserNavigationToNotExistingPathReExecutesTo404(string renderMode)
1441+
{
1442+
// non-existing path has to have re-execution middleware set up
1443+
// so it has to have "reexecution" prefix. Otherwise middleware mapping
1444+
// will not be activated, see configuration in Startup
1445+
Navigate($"{ServerPathBase}/reexecution/not-existing-page?render-mode={renderMode}");
1446+
Assert404ReExecuted();
1447+
}
1448+
1449+
private void Assert404ReExecuted() =>
1450+
Browser.Equal("Welcome On Page Re-executed After Not Found Event", () => Browser.Exists(By.Id("test-info")).Text);
14141451
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@page "/redirection-not-found"
2+
@page "/reexecution/redirection-not-found"
3+
@rendermode @(RenderModeHelper.GetRenderMode(_currentRenderMode))
4+
@inject NavigationManager NavigationManager
5+
6+
<PageTitle>Original page</PageTitle>
7+
8+
<p id="test-info">Any content</p>
9+
<a id="link-to-not-existing-page" href="@(_nonExistingPath)">
10+
Go to not-existing-page
11+
</a>
12+
13+
@code{
14+
[Parameter, SupplyParameterFromQuery(Name = "renderMode")]
15+
public string? RenderModeStr { get; set; }
16+
17+
[Parameter]
18+
[SupplyParameterFromQuery(Name = "navigate-programmatically")]
19+
public bool? NavigateProgrammatically { get; set; }
20+
21+
private string? _nonExistingPath;
22+
private RenderModeId _currentRenderMode => RenderModeHelper.ParseRenderMode(RenderModeStr);
23+
24+
protected override void OnInitialized()
25+
{
26+
_nonExistingPath = $"{NavigationManager.BaseUri}not-existing-page";
27+
if (NavigateProgrammatically == true)
28+
{
29+
NavigationManager.NavigateTo(_nonExistingPath);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)