Skip to content

Commit 842bc6c

Browse files
committed
Added tests from dotnet#62524 to fix it in one place.
1 parent 3ff48fe commit 842bc6c

File tree

7 files changed

+111
-24
lines changed

7 files changed

+111
-24
lines changed

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

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,29 @@ public void NotFoundSetOnInitialization_ResponseNotStarted_SSR(bool hasReExecuti
151151
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
152152
Navigate(testUrl);
153153

154-
if (hasCustomNotFoundPageSet)
155-
{
156-
AssertNotFoundPageRendered();
157-
}
158-
else
159-
{
160-
AssertNotFoundFragmentRendered();
161-
}
154+
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
155+
AssertUrlNotChanged(testUrl);
156+
}
157+
158+
[Theory]
159+
[InlineData(true, true)]
160+
[InlineData(true, false)]
161+
[InlineData(false, true)]
162+
[InlineData(false, false)]
163+
public void NotFoundSetOnInitialization_AfterAsyncOperation_ResponseNotStarted_SSR(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet)
164+
{
165+
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
166+
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr?doAsync=true&useCustomNotFoundPage={hasCustomNotFoundPageSet}";
167+
Navigate(testUrl);
168+
169+
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
162170
AssertUrlNotChanged(testUrl);
163171
}
164172

165173
[Theory]
166174
[InlineData(true)]
167175
[InlineData(false)]
168-
// our custom router does not support NotFoundPage nor NotFound fragment to simulate most probable custom router behavior
176+
// our custom router does not support NotFoundPage to simulate the most probable custom router behavior
169177
public void NotFoundSetOnInitialization_ResponseNotStarted_CustomRouter_SSR(bool hasReExecutionMiddleware)
170178
{
171179
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
@@ -196,7 +204,7 @@ public void NotFoundSetOnInitialization_ResponseStarted_SSR(bool hasReExecutionM
196204
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
197205
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
198206
Navigate(testUrl);
199-
AssertNotFoundRendered_ResponseStarted_Or_POST(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
207+
AssertNotFoundRendered_ResponseStarted(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
200208
AssertUrlNotChanged(testUrl);
201209
}
202210

@@ -210,11 +218,47 @@ public void NotFoundSetOnInitialization_ResponseStarted_EnhancedNavigationDisabl
210218
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
211219
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
212220
Navigate(testUrl);
213-
AssertNotFoundRendered_ResponseStarted_Or_POST(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
221+
AssertNotFoundRendered_ResponseStarted(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
214222
AssertUrlChanged(testUrl);
215223
}
216224

217-
private void AssertNotFoundRendered_ResponseStarted_Or_POST(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet, string testUrl)
225+
[Theory]
226+
[InlineData(true)]
227+
[InlineData(false)]
228+
// our custom router does not support NotFoundPage to simulate the most probable custom router behavior
229+
public void NotFoundSetOnInitialization_ResponseStarted_CustomRouter_SSR(bool hasReExecutionMiddleware)
230+
{
231+
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
232+
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr-streaming?useCustomRouter=true";
233+
Navigate(testUrl);
234+
235+
if (hasReExecutionMiddleware)
236+
{
237+
AssertReExecutionPageRendered();
238+
}
239+
else
240+
{
241+
// Apps that don't support re-execution and don't have blazor's router,
242+
// cannot render custom NotFound contents.
243+
// The browser will display default 404 page.
244+
AssertBrowserDefaultNotFoundViewRendered();
245+
}
246+
AssertUrlNotChanged(testUrl);
247+
}
248+
249+
private void AssertNotFoundRendered_ResponseNotStarted(bool hasCustomNotFoundPageSet)
250+
{
251+
if (hasCustomNotFoundPageSet)
252+
{
253+
AssertNotFoundPageRendered();
254+
}
255+
else
256+
{
257+
AssertNotFoundContentNotRendered();
258+
}
259+
}
260+
261+
private void AssertNotFoundRendered_ResponseStarted(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet, string testUrl)
218262
{
219263
if (hasCustomNotFoundPageSet)
220264
{
@@ -243,7 +287,33 @@ public void NotFoundSetOnFormSubmit_ResponseNotStarted_SSR(bool hasReExecutionMi
243287
Navigate(testUrl);
244288
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
245289

246-
AssertNotFoundRendered_ResponseStarted_Or_POST(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
290+
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
291+
AssertUrlNotChanged(testUrl);
292+
}
293+
294+
[Theory]
295+
[InlineData(true, true)]
296+
[InlineData(true, false)]
297+
[InlineData(false, true)]
298+
[InlineData(false, false)]
299+
public void NotFoundSetOnFormSubmit_AfterAsyncOperation_ResponseNotStarted_SSR(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet)
300+
{
301+
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
302+
string testUrl = $"{ServerPathBase}{reexecution}/post-not-found-ssr?doAsync=true&useCustomNotFoundPage={hasCustomNotFoundPageSet}";
303+
Navigate(testUrl);
304+
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
305+
306+
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
307+
AssertUrlNotChanged(testUrl);
308+
}
309+
310+
[Fact]
311+
public void NotFoundSetOnFormSubmit_ResponseNotStarted_CustomRouter_SSR()
312+
{
313+
string testUrl = $"{ServerPathBase}/reexecution/post-not-found-ssr?useCustomRouter=true";
314+
Navigate(testUrl);
315+
316+
AssertReExecutionPageRendered();
247317
AssertUrlNotChanged(testUrl);
248318
}
249319

@@ -259,12 +329,19 @@ public void NotFoundSetOnFormSubmit_ResponseStarted_SSR(bool hasReExecutionMiddl
259329
Navigate(testUrl);
260330
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
261331

262-
AssertNotFoundRendered_ResponseStarted_Or_POST(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
332+
AssertNotFoundRendered_ResponseStarted(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
263333
AssertUrlNotChanged(testUrl);
264334
}
265335

266-
private void AssertNotFoundFragmentRendered() =>
267-
Browser.Equal("There's nothing here", () => Browser.FindElement(By.Id("not-found-fragment")).Text);
336+
[Fact]
337+
public void NotFoundSetOnFormSubmit_ResponseStarted_CustomRouter_SSR()
338+
{
339+
string testUrl = $"{ServerPathBase}/reexecution/post-not-found-ssr-streaming?useCustomRouter=true";
340+
Navigate(testUrl);
341+
342+
AssertReExecutionPageRendered();
343+
AssertUrlNotChanged(testUrl);
344+
}
268345

269346
private void AssertNotFoundContentNotRendered() =>
270347
Browser.Equal("Any content", () => Browser.FindElement(By.Id("test-info")).Text);

src/Components/test/testassets/TestContentPackage/NotFound/ComponentThatPostsNotFound.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
@code{
1818
[Parameter]
19-
public bool StartStreaming { get; set; } = false;
19+
public bool DoAsyncOperationBeforeSettingNotFound { get; set; } = false;
2020

2121
[Parameter]
2222
public bool WaitForInteractivity { get; set; } = false;
2323

2424
private async Task HandleSubmit()
2525
{
26-
if (StartStreaming)
26+
if (DoAsyncOperationBeforeSettingNotFound)
2727
{
2828
await Task.Yield();
2929
}

src/Components/test/testassets/TestContentPackage/NotFound/ComponentThatSetsNotFound.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
@code{
1212
[Parameter]
13-
public bool StartStreaming { get; set; } = false;
13+
public bool DoAsyncOperationBeforeSettingNotFound { get; set; } = false;
1414

1515
[Parameter]
1616
public bool WaitForInteractivity { get; set; } = false;
1717

1818
protected async override Task OnInitializedAsync()
1919
{
20-
if (StartStreaming)
20+
if (DoAsyncOperationBeforeSettingNotFound)
2121
{
2222
await Task.Yield();
2323
}

src/Components/test/testassets/TestContentPackage/NotFound/PageThatPostsNotFound-no-streaming.razor

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
interactive later if interactivity was enabled in the app
99
*@
1010

11-
<TestContentPackage.NotFound.ComponentThatPostsNotFound />
11+
<TestContentPackage.NotFound.ComponentThatPostsNotFound DoAsyncOperationBeforeSettingNotFound="@DoAsync" />
12+
13+
@code{
14+
[SupplyParameterFromQuery(Name = "doAsync")]
15+
public bool DoAsync { get; set; } = false;
16+
}

src/Components/test/testassets/TestContentPackage/NotFound/PageThatPostsNotFound-streaming.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
interactive later if interactivity was enabled in the app
99
*@
1010

11-
<TestContentPackage.NotFound.ComponentThatPostsNotFound StartStreaming="true"/>
11+
<TestContentPackage.NotFound.ComponentThatPostsNotFound DoAsyncOperationBeforeSettingNotFound="true"/>

src/Components/test/testassets/TestContentPackage/NotFound/PageThatSetsNotFound-no-streaming.razor

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
interactive later if interactivity was enabled in the app
99
*@
1010

11-
<TestContentPackage.NotFound.ComponentThatSetsNotFound />
11+
<TestContentPackage.NotFound.ComponentThatSetsNotFound DoAsyncOperationBeforeSettingNotFound="@DoAsync" />
12+
13+
@code{
14+
[SupplyParameterFromQuery(Name = "doAsync")]
15+
public bool DoAsync { get; set; } = false;
16+
}

src/Components/test/testassets/TestContentPackage/NotFound/PageThatSetsNotFound-streaming.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
interactive later if interactivity was enabled in the app
99
*@
1010

11-
<TestContentPackage.NotFound.ComponentThatSetsNotFound StartStreaming="true"/>
11+
<TestContentPackage.NotFound.ComponentThatSetsNotFound DoAsyncOperationBeforeSettingNotFound="true"/>

0 commit comments

Comments
 (0)