Skip to content

Commit 9e3eb33

Browse files
PR feedback and some test fixes
1 parent 20311a2 commit 9e3eb33

File tree

7 files changed

+29
-46
lines changed

7 files changed

+29
-46
lines changed

src/Components/Blazor/Templates/src/content/BlazorWasm-CSharp/Client/wwwroot/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
<div id="error-ui">
1717
An unhandled error has occurred.
18-
<a href class='reload'>Reload</a>
19-
<a class='dismiss'>🗙</a>
18+
<a href class="reload">Reload</a>
19+
<a class="dismiss">🗙</a>
2020
</div>
2121
<script src="_framework/blazor.webassembly.js"></script>
2222
</body>

src/Components/Samples/BlazorServerApp/Shared/MainLayout.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
</div>
1717
<div id="error-ui">
1818
An unhandled error has occurred.
19-
<a class='reload'>Reload</a>
20-
<a class='dismiss'>X</a>
19+
<a class="reload">Reload</a>
20+
<a class="dismiss">X</a>
2121
</div>

src/Components/test/E2ETest/Tests/ErrorNotificationClientSideTest.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using BasicTestApp;
56
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
67
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
@@ -11,6 +12,7 @@
1112

1213
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
1314
{
15+
[Collection("ErrorNotification")] // When the clientside and serverside tests run together it seems to cause failures, possibly due to connection lose on exception.
1416
public class ErrorNotificationClientSideTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
1517
{
1618
public ErrorNotificationClientSideTest(
@@ -31,30 +33,34 @@ protected override void InitializeAsyncCore()
3133
}
3234

3335
[Fact]
34-
public void ShowsErrorNotificationClientSide_OnError()
36+
public void ShowsErroNotification_OnError_Dismiss()
3537
{
3638
var errorUi = Browser.FindElement(By.Id("error-ui"));
3739
Assert.Equal("none", errorUi.GetCssValue("display"));
3840

3941
var causeErrorButton = Browser.FindElement(By.TagName("button"));
4042
causeErrorButton.Click();
4143

42-
Browser.Exists(By.CssSelector("#error-ui[style='display: block;']"));
44+
Browser.Exists(By.CssSelector("#error-ui[style='display: block;']"), TimeSpan.FromSeconds(10));
4345

4446
var reload = Browser.FindElement(By.ClassName("reload"));
4547
reload.Click();
4648

47-
Browser.MountTestComponent<ErrorComponent>();
48-
causeErrorButton = Browser.Exists(By.TagName("button"));
49-
errorUi = Browser.FindElement(By.Id("error-ui"));
49+
Browser.DoesNotExist(By.TagName("button"));
50+
}
51+
52+
[Fact]
53+
public void ShowsErrorNotification_OnError_Reload()
54+
{
55+
var causeErrorButton = Browser.Exists(By.TagName("button"));
56+
var errorUi = Browser.FindElement(By.Id("error-ui"));
5057
Assert.Equal("none", errorUi.GetCssValue("display"));
5158

5259
causeErrorButton.Click();
53-
Assert.Equal("block", errorUi.GetCssValue("display"));
60+
Browser.Exists(By.CssSelector("#error-ui[style='display: block;']"));
5461

5562
var dismiss = Browser.FindElement(By.ClassName("dismiss"));
5663
dismiss.Click();
57-
Browser.Exists(By.CssSelector("#error-ui"));
5864
Browser.Exists(By.CssSelector("#error-ui[style='display: none;']"));
5965
}
6066
}

src/Components/test/E2ETest/Tests/ErrorNotificationServerSideTest.cs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using BasicTestApp;
5-
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
65
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
76
using Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests;
87
using Microsoft.AspNetCore.E2ETesting;
@@ -12,7 +11,8 @@
1211

1312
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
1413
{
15-
public class ErrorNotificationServerSideTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
14+
[Collection("ErrorNotification")] // When the clientside and serverside tests run together it seems to cause failures, possibly due to connection lose on exception.
15+
public class ErrorNotificationServerSideTest : ErrorNotificationClientSideTest
1616
{
1717
public ErrorNotificationServerSideTest(
1818
BrowserFixture browserFixture,
@@ -30,34 +30,5 @@ protected override void InitializeAsyncCore()
3030
Browser.Exists(By.Id("error-ui"));
3131
Browser.Exists(By.TagName("button"));
3232
}
33-
34-
[Fact]
35-
public void ShowsErrorNotificationServerSide_OnError()
36-
{
37-
var errorUi = Browser.FindElement(By.Id("error-ui"));
38-
Assert.Equal("none", errorUi.GetCssValue("display"));
39-
40-
var causeErrorButton = Browser.FindElement(By.TagName("button"));
41-
causeErrorButton.Click();
42-
43-
Browser.Exists(By.CssSelector("#error-ui[style='display: block;']"));
44-
45-
var reload = Browser.FindElement(By.ClassName("reload"));
46-
reload.Click();
47-
48-
Browser.MountTestComponent<ErrorComponent>();
49-
causeErrorButton = Browser.Exists(By.TagName("button"));
50-
errorUi = Browser.FindElement(By.Id("error-ui"));
51-
Assert.Equal("none", errorUi.GetCssValue("display"));
52-
53-
causeErrorButton.Click();
54-
Assert.Equal("block", errorUi.GetCssValue("display"));
55-
56-
var dismiss = Browser.FindElement(By.ClassName("dismiss"));
57-
dismiss.Click();
58-
Browser.Exists(By.CssSelector("#error-ui"));
59-
Browser.Exists(By.CssSelector("#error-ui[style='display: none;']"));
60-
Assert.Equal("none", errorUi.GetCssValue("display"));
61-
}
6233
}
6334
}

src/Components/test/testassets/BasicTestApp/Index.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<option value="BasicTestApp.DispatchingComponent">Dispatching to sync context</option>
2121
<option value="BasicTestApp.DuplicateAttributesComponent">Duplicate attributes</option>
2222
<option value="BasicTestApp.ElementRefComponent">Element ref component</option>
23+
<option value="BasicTestApp.ErrorComponent">Error throwing</option>
2324
<option value="BasicTestApp.EventBubblingComponent">Event bubbling</option>
2425
<option value="BasicTestApp.EventCallbackTest.EventCallbackCases">EventCallback</option>
2526
<option value="BasicTestApp.EventCasesComponent">Event cases</option>
@@ -67,7 +68,6 @@
6768
<option value="BasicTestApp.SvgWithChildComponent">SVG with child component</option>
6869
<option value="BasicTestApp.TextOnlyComponent">Plain text</option>
6970
<option value="BasicTestApp.TouchEventComponent">Touch events</option>
70-
<option value="BasicTestApp.ErrorComponent">Error throwing</option>
7171
</select>
7272

7373
<span id="runtime-info"><code><tt>@System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription</tt></code></span>
@@ -83,7 +83,6 @@
8383
@((RenderFragment)RenderSelectedComponent)
8484
</app>
8585

86-
8786
<div id="error-ui">
8887
An unhandled error has occurred.
8988
<a href class='reload'>Reload</a>

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/_Host.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<environment include="Development">
2525
An unhandled exception has occurred. See browser dev tools for details.
2626
</environment>
27-
<a href class='reload'>Reload</a>
28-
<a class='dismiss'>🗙</a>
27+
<a href class="reload">Reload</a>
28+
<a class="dismiss">🗙</a>
2929
</div>
3030

3131
<script src="_framework/blazor.server.js"></script>

src/Shared/E2ETesting/WaitAssert.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public static void Single(this IWebDriver driver, Func<IEnumerable> actualValues
4747
public static IWebElement Exists(this IWebDriver driver, By finder)
4848
=> Exists(driver, finder, default);
4949

50+
public static void DoesNotExist(this IWebDriver driver, By finder, TimeSpan timeout = default)
51+
=> WaitAssertCore(driver, () =>
52+
{
53+
var elements = driver.FindElements(finder);
54+
Assert.Empty(elements);
55+
}, timeout);
56+
5057
public static IWebElement Exists(this IWebDriver driver, By finder, TimeSpan timeout)
5158
=> WaitAssertCore(driver, () =>
5259
{

0 commit comments

Comments
 (0)