Skip to content

Commit 5fff491

Browse files
committed
Add re-exec tests for SSR + move NotFound sources into one directory.
1 parent 08cff58 commit 5fff491

File tree

7 files changed

+79
-12
lines changed

7 files changed

+79
-12
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,34 @@ public void CanRenderNotFoundPageAfterStreamingStarted()
8787
Browser.Equal("Default Not Found Page", () => Browser.Title);
8888
}
8989

90+
[Fact]
91+
public void ProgrammaticNavigationToNotExistingPathReExecutesTo404()
92+
{
93+
Navigate($"{ServerPathBase}/reexecution/redirection-not-found?navigate-programmatically=true");
94+
Assert404ReExecuted();
95+
}
96+
97+
[Fact]
98+
public void LinkNavigationToNotExistingPathReExecutesTo404()
99+
{
100+
Navigate($"{ServerPathBase}/reexecution/redirection-not-found");
101+
Browser.Click(By.Id("link-to-not-existing-page"));
102+
Assert404ReExecuted();
103+
}
104+
105+
[Fact]
106+
public void BrowserNavigationToNotExistingPathReExecutesTo404()
107+
{
108+
// non-existing path has to have re-execution middleware set up
109+
// so it has to have "reexecution" prefix. Otherwise middleware mapping
110+
// will not be activated, see configuration in Startup
111+
Navigate($"{ServerPathBase}/reexecution/not-existing-page");
112+
Assert404ReExecuted();
113+
}
114+
115+
private void Assert404ReExecuted() =>
116+
Browser.Equal("Welcome On Page Re-executed After Not Found Event", () => Browser.Exists(By.Id("test-info")).Text);
117+
90118
[Theory]
91119
[InlineData(true)]
92120
[InlineData(false)]

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,30 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4848

4949
app.Map("/subdir", app =>
5050
{
51-
if (!env.IsDevelopment())
51+
app.Map("/reexecution", reexecutionApp =>
5252
{
53-
app.UseExceptionHandler("/Error", createScopeForErrors: true);
54-
}
55-
56-
app.UseStaticFiles();
57-
app.UseRouting();
58-
RazorComponentEndpointsStartup<TRootComponent>.UseFakeAuthState(app);
59-
app.UseAntiforgery();
60-
app.UseEndpoints(endpoints =>
61-
{
62-
endpoints.MapRazorComponents<TRootComponent>();
53+
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForErrors: true);
54+
ConfigureSubdirPipeline(reexecutionApp, env);
6355
});
56+
57+
ConfigureSubdirPipeline(app, env);
58+
});
59+
}
60+
61+
private void ConfigureSubdirPipeline(IApplicationBuilder app, IWebHostEnvironment env)
62+
{
63+
if (!env.IsDevelopment())
64+
{
65+
app.UseExceptionHandler("/Error", createScopeForErrors: true);
66+
}
67+
68+
app.UseStaticFiles();
69+
app.UseRouting();
70+
RazorComponentEndpointsStartup<TRootComponent>.UseFakeAuthState(app);
71+
app.UseAntiforgery();
72+
app.UseEndpoints(endpoints =>
73+
{
74+
endpoints.MapRazorComponents<TRootComponent>();
6475
});
6576
}
6677
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
8989
});
9090
}
9191

92-
protected virtual void ConfigureSubdirPipeline(IApplicationBuilder app, IWebHostEnvironment env)
92+
private void ConfigureSubdirPipeline(IApplicationBuilder app, IWebHostEnvironment env)
9393
{
9494
WebAssemblyTestHelper.ServeCoopHeadersIfWebAssemblyThreadingEnabled(app);
9595

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@page "/redirection-not-found"
2+
@page "/reexecution/redirection-not-found"
3+
@attribute [StreamRendering(false)]
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]
15+
[SupplyParameterFromQuery(Name = "navigate-programmatically")]
16+
public bool? NavigateProgrammatically { get; set; }
17+
18+
private string? _nonExistingPath;
19+
20+
protected override void OnInitialized()
21+
{
22+
_nonExistingPath = $"{NavigationManager.BaseUri}not-existing-page";
23+
if (NavigateProgrammatically == true)
24+
{
25+
NavigationManager.NavigateTo(_nonExistingPath);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)