Skip to content

Commit d03bf14

Browse files
committed
Fix most of no interactivity tests.
1 parent d356b57 commit d03bf14

File tree

1 file changed

+77
-28
lines changed

1 file changed

+77
-28
lines changed

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

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,29 @@ private void AssertBrowserDefaultNotFoundViewRendered()
127127
);
128128
}
129129

130+
private void AssertOriginalPageRendered() =>
131+
Browser.Equal("Any content", () => Browser.FindElement(By.Id("test-info")).Text);
132+
130133
private void AssertNotFoundPageRendered()
131134
{
132135
Browser.Equal("Welcome On Custom Not Found Page", () => Browser.FindElement(By.Id("test-info")).Text);
133136
// custom page should have a custom layout
134137
Browser.Equal("About", () => Browser.FindElement(By.Id("about-link")).Text);
135138
}
136139

140+
private void AssertNotFoundContentNotRendered(bool responseHasStarted)
141+
{
142+
if (responseHasStarted)
143+
{
144+
AssertOriginalPageRendered();
145+
}
146+
else
147+
{
148+
AssertBrowserDefaultNotFoundViewRendered();
149+
}
150+
}
151+
152+
137153
private void AssertUrlNotChanged(string expectedUrl) =>
138154
Browser.True(() => Browser.Url.Contains(expectedUrl), $"Expected URL to contain '{expectedUrl}', but found '{Browser.Url}'");
139155

@@ -151,7 +167,15 @@ public void NotFoundSetOnInitialization_ResponseNotStarted_SSR(bool hasReExecuti
151167
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
152168
Navigate(testUrl);
153169

154-
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
170+
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
171+
if (notFoundContentForRenderingProvided)
172+
{
173+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
174+
}
175+
else
176+
{
177+
AssertNotFoundContentNotRendered(responseHasStarted: false);
178+
}
155179
AssertUrlNotChanged(testUrl);
156180
}
157181

@@ -166,7 +190,15 @@ public void NotFoundSetOnInitialization_AfterAsyncOperation_ResponseNotStarted_S
166190
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr?doAsync=true&useCustomNotFoundPage={hasCustomNotFoundPageSet}";
167191
Navigate(testUrl);
168192

169-
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
193+
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
194+
if (notFoundContentForRenderingProvided)
195+
{
196+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
197+
}
198+
else
199+
{
200+
AssertNotFoundContentNotRendered(responseHasStarted: false);
201+
}
170202
AssertUrlNotChanged(testUrl);
171203
}
172204

@@ -189,7 +221,7 @@ public void NotFoundSetOnInitialization_ResponseNotStarted_CustomRouter_SSR(bool
189221
// Apps that don't support re-execution and don't have blazor's router,
190222
// cannot render custom NotFound contents.
191223
// The browser will display default 404 page.
192-
AssertBrowserDefaultNotFoundViewRendered();
224+
AssertNotFoundContentNotRendered(responseHasStarted: false);
193225
}
194226
AssertUrlNotChanged(testUrl);
195227
}
@@ -204,7 +236,15 @@ public void NotFoundSetOnInitialization_ResponseStarted_SSR(bool hasReExecutionM
204236
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
205237
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
206238
Navigate(testUrl);
207-
AssertNotFoundRendered_ResponseStarted(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
239+
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
240+
if (notFoundContentForRenderingProvided)
241+
{
242+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
243+
}
244+
else
245+
{
246+
AssertNotFoundContentNotRendered(responseHasStarted: true);
247+
}
208248
AssertUrlNotChanged(testUrl);
209249
}
210250

@@ -218,7 +258,7 @@ public void NotFoundSetOnInitialization_ResponseStarted_EnhancedNavigationDisabl
218258
string reexecution = hasReExecutionMiddleware ? "/reexecution" : "";
219259
string testUrl = $"{ServerPathBase}{reexecution}/set-not-found-ssr-streaming?useCustomNotFoundPage={hasCustomNotFoundPageSet}";
220260
Navigate(testUrl);
221-
AssertNotFoundRendered_ResponseStarted(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
261+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
222262
AssertUrlChanged(testUrl);
223263
}
224264

@@ -234,31 +274,19 @@ public void NotFoundSetOnInitialization_ResponseStarted_CustomRouter_SSR(bool ha
234274

235275
if (hasReExecutionMiddleware)
236276
{
237-
AssertReExecutionPageRendered();
277+
AssertReExecutionPageRendered();
238278
}
239279
else
240280
{
241281
// Apps that don't support re-execution and don't have blazor's router,
242282
// cannot render custom NotFound contents.
243283
// The browser will display default 404 page.
244-
AssertBrowserDefaultNotFoundViewRendered();
284+
AssertNotFoundContentNotRendered(responseHasStarted: true);
245285
}
246286
AssertUrlNotChanged(testUrl);
247287
}
248288

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)
289+
private void AssertNotFoundRendered(bool hasReExecutionMiddleware, bool hasCustomNotFoundPageSet)
262290
{
263291
if (hasCustomNotFoundPageSet)
264292
{
@@ -270,8 +298,7 @@ private void AssertNotFoundRendered_ResponseStarted(bool hasReExecutionMiddlewar
270298
}
271299
else
272300
{
273-
// this throws an exception logged on the server
274-
AssertNotFoundContentNotRendered();
301+
throw new InvalidOperationException("NotFound page will not be rendered without re-execution middleware or custom NotFoundPage set. Use AssertNotFoundNotRendered in this case.");
275302
}
276303
}
277304

@@ -287,7 +314,15 @@ public void NotFoundSetOnFormSubmit_ResponseNotStarted_SSR(bool hasReExecutionMi
287314
Navigate(testUrl);
288315
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
289316

290-
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
317+
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
318+
if (notFoundContentForRenderingProvided)
319+
{
320+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
321+
}
322+
else
323+
{
324+
AssertNotFoundContentNotRendered(responseHasStarted: false);
325+
}
291326
AssertUrlNotChanged(testUrl);
292327
}
293328

@@ -303,7 +338,15 @@ public void NotFoundSetOnFormSubmit_AfterAsyncOperation_ResponseNotStarted_SSR(b
303338
Navigate(testUrl);
304339
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
305340

306-
AssertNotFoundRendered_ResponseNotStarted(hasCustomNotFoundPageSet);
341+
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
342+
if (notFoundContentForRenderingProvided)
343+
{
344+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
345+
}
346+
else
347+
{
348+
AssertNotFoundContentNotRendered(responseHasStarted: false);
349+
}
307350
AssertUrlNotChanged(testUrl);
308351
}
309352

@@ -329,7 +372,16 @@ public void NotFoundSetOnFormSubmit_ResponseStarted_SSR(bool hasReExecutionMiddl
329372
Navigate(testUrl);
330373
Browser.FindElement(By.Id("not-found-form")).FindElement(By.TagName("button")).Click();
331374

332-
AssertNotFoundRendered_ResponseStarted(hasReExecutionMiddleware, hasCustomNotFoundPageSet, testUrl);
375+
376+
bool notFoundContentForRenderingProvided = hasCustomNotFoundPageSet || hasReExecutionMiddleware;
377+
if (notFoundContentForRenderingProvided)
378+
{
379+
AssertNotFoundRendered(hasReExecutionMiddleware, hasCustomNotFoundPageSet);
380+
}
381+
else
382+
{
383+
AssertNotFoundContentNotRendered(responseHasStarted: true);
384+
}
333385
AssertUrlNotChanged(testUrl);
334386
}
335387

@@ -343,9 +395,6 @@ public void NotFoundSetOnFormSubmit_ResponseStarted_CustomRouter_SSR()
343395
AssertUrlNotChanged(testUrl);
344396
}
345397

346-
private void AssertNotFoundContentNotRendered() =>
347-
Browser.Equal("Any content", () => Browser.FindElement(By.Id("test-info")).Text);
348-
349398
[Fact]
350399
public void StatusCodePagesWithReExecution()
351400
{

0 commit comments

Comments
 (0)