-
Notifications
You must be signed in to change notification settings - Fork 43
Replaced unhandled exception footer with a critical banner that works along side the alert dialog system #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa11188
Migrate solution to .slnx format
jschick04 d9f293f
Add IBannerService and supporting models for app-level alerts
jschick04 336e24c
Extend IAlertDialogService with banner presentation and critical aler…
jschick04 9c91f1e
Move IClipboardService to UI and add CopyTextAsync
jschick04 702dc53
Add TryRestartAsync to IApplicationRestartService
jschick04 d5e5d64
Add BannerHost component for app-level alert surface
jschick04 2d79317
Wire UnhandledExceptionHandler to BannerService recovery via token-ba…
jschick04 92b9b7a
Batch empty-log alerts across multi-open call sites
jschick04 ecc82eb
Mount BannerHost above error boundary and drop dead Router from Main.…
jschick04 d77a600
Skip auto update checks after first attempt per session
jschick04 8bcc4f1
Focus reload button when error banner appears
jschick04 acee562
Extract BannerHost to Razor library with bUnit coverage
jschick04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| // // Copyright (c) Microsoft Corporation. | ||
| // // Licensed under the MIT License. | ||
|
|
||
| using Bunit; | ||
| using EventLogExpert.Eventing.Helpers; | ||
| using EventLogExpert.UI.Interfaces; | ||
| using EventLogExpert.UI.Models; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using NSubstitute; | ||
|
|
||
| namespace EventLogExpert.Components.Tests; | ||
|
|
||
| public sealed class BannerHostTests : BunitContext | ||
| { | ||
| private readonly IApplicationRestartService _applicationRestartService = | ||
| Substitute.For<IApplicationRestartService>(); | ||
| private readonly IBannerService _bannerService = Substitute.For<IBannerService>(); | ||
| private readonly IClipboardService _clipboardService = Substitute.For<IClipboardService>(); | ||
| private readonly ITraceLogger _traceLogger = Substitute.For<ITraceLogger>(); | ||
|
|
||
| public BannerHostTests() | ||
| { | ||
| _bannerService.UnhandledError.Returns((Exception?)null); | ||
| _bannerService.CriticalAlerts.Returns([]); | ||
| _bannerService.InfoBanners.Returns([]); | ||
|
|
||
| Services.AddSingleton(_bannerService); | ||
| Services.AddSingleton(_applicationRestartService); | ||
| Services.AddSingleton(_clipboardService); | ||
| Services.AddSingleton(_traceLogger); | ||
|
|
||
| JSInterop.Mode = JSRuntimeMode.Loose; | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_CopyDetailsClicked_CopiesExceptionAndShowsCopiedChip() | ||
| { | ||
| var error = new InvalidOperationException("kaboom"); | ||
| _bannerService.UnhandledError.Returns(error); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| // Sync Click() returns at the handler's first real async point (the 2s Task.Delay) with | ||
| // the chip rendered; ClickAsync would block for the full delay until the chip clears. | ||
| component.Find("aside.banner-error .banner-actions button:nth-child(3)").Click(); | ||
|
|
||
| await _clipboardService.Received(1) | ||
| .CopyTextAsync(Arg.Is<string>(s => s.Contains("InvalidOperationException") && s.Contains("kaboom"))); | ||
|
|
||
| Assert.Single(component.FindAll("aside.banner-error .banner-feedback .banner-chip")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_DismissCriticalClicked_CallsDismissCriticalWithEntryId() | ||
| { | ||
| var alert = new CriticalAlertEntry(Guid.NewGuid(), "Database", "Schema invalid", DateTime.UtcNow); | ||
| _bannerService.CriticalAlerts.Returns([alert]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
| await component.Find("aside.banner-critical button.banner-dismiss").ClickAsync(new()); | ||
|
|
||
| _bannerService.Received(1).DismissCritical(alert.Id); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_DismissInfoClicked_CallsDismissInfoBannerWithEntryId() | ||
| { | ||
| var info = new BannerInfoEntry(Guid.NewGuid(), "Notice", "Heads up", BannerSeverity.Info, DateTime.UtcNow); | ||
| _bannerService.InfoBanners.Returns([info]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
| await component.Find("aside.banner-info button.banner-dismiss").ClickAsync(new()); | ||
|
|
||
| _bannerService.Received(1).DismissInfoBanner(info.Id); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_ErrorAndCriticalAndInfoAllPresent_RendersOnlyError() | ||
| { | ||
| _bannerService.UnhandledError.Returns(new InvalidOperationException("kaboom")); | ||
|
|
||
| _bannerService.CriticalAlerts.Returns( | ||
| [new CriticalAlertEntry(Guid.NewGuid(), "Critical", "C", DateTime.UtcNow)]); | ||
|
|
||
| _bannerService.InfoBanners.Returns([ | ||
| new BannerInfoEntry(Guid.NewGuid(), "Info", "I", BannerSeverity.Info, DateTime.UtcNow) | ||
| ]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| Assert.Single(component.FindAll("aside.banner-error")); | ||
| Assert.Empty(component.FindAll("aside.banner-critical")); | ||
| Assert.Empty(component.FindAll("aside.banner-info")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_InfoSeverity_RendersInfoStyledBanner() | ||
| { | ||
| var info = new BannerInfoEntry(Guid.NewGuid(), "Notice", "Heads up", BannerSeverity.Info, DateTime.UtcNow); | ||
| _bannerService.InfoBanners.Returns([info]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| Assert.Single(component.FindAll("aside.banner.banner-info")); | ||
| Assert.Empty(component.FindAll("aside.banner.banner-warning")); | ||
| Assert.Contains("Notice: Heads up", component.Find("aside.banner-info").TextContent); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_MultipleCriticalAlerts_RendersFirstWithPagination() | ||
| { | ||
| var first = new CriticalAlertEntry(Guid.NewGuid(), "First", "First message", DateTime.UtcNow); | ||
| var second = new CriticalAlertEntry(Guid.NewGuid(), "Second", "Second message", DateTime.UtcNow); | ||
| _bannerService.CriticalAlerts.Returns([first, second]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| var banner = component.Find("aside.banner-critical"); | ||
| Assert.Contains("First: First message", banner.TextContent); | ||
| Assert.DoesNotContain("Second", banner.TextContent); | ||
|
|
||
| var pagination = component.Find("aside.banner-critical .banner-pagination"); | ||
| Assert.Equal("1 of 2", pagination.TextContent.Trim()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_NoState_RendersNothing() | ||
| { | ||
| var component = Render<BannerHost>(); | ||
|
|
||
| Assert.Equal(string.Empty, component.Markup.Trim()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_RecoveryThrows_ShowsRecoveryFailureSubtitle() | ||
| { | ||
| _bannerService.UnhandledError.Returns(new InvalidOperationException("kaboom")); | ||
| _bannerService.TryRecoverAsync().Returns(Task.FromException(new InvalidOperationException("recovery failed"))); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
| await component.Find("aside.banner-error .banner-actions button:nth-child(1)").ClickAsync(new()); | ||
|
|
||
| var subtitle = component.Find("aside.banner-error .banner-feedback .banner-subtitle"); | ||
| Assert.Contains("Recovery failed", subtitle.TextContent); | ||
| Assert.Contains("recovery failed", subtitle.TextContent); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_RelaunchClicked_InvokesTryRestartAsync() | ||
| { | ||
| _bannerService.UnhandledError.Returns(new InvalidOperationException("kaboom")); | ||
| _applicationRestartService.TryRestartAsync().Returns(true); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
| await component.Find("aside.banner-error .banner-actions button:nth-child(2)").ClickAsync(new()); | ||
|
|
||
| await _applicationRestartService.Received(1).TryRestartAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_RelaunchFails_ShowsRestartFailureSubtitle() | ||
| { | ||
| _bannerService.UnhandledError.Returns(new InvalidOperationException("kaboom")); | ||
| _applicationRestartService.TryRestartAsync().Returns(false); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
| await component.Find("aside.banner-error .banner-actions button:nth-child(2)").ClickAsync(new()); | ||
|
|
||
| var subtitle = component.Find("aside.banner-error .banner-feedback .banner-subtitle"); | ||
| Assert.Contains("Restart failed", subtitle.TextContent); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task BannerHost_ReloadClicked_InvokesTryRecoverAsync() | ||
| { | ||
| _bannerService.UnhandledError.Returns(new InvalidOperationException("kaboom")); | ||
| _bannerService.TryRecoverAsync().Returns(Task.CompletedTask); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
| await component.Find("aside.banner-error .banner-actions button:nth-child(1)").ClickAsync(new()); | ||
|
|
||
| await _bannerService.Received(1).TryRecoverAsync(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_SingleCriticalAlert_RendersWithoutPagination() | ||
| { | ||
| var alert = new CriticalAlertEntry(Guid.NewGuid(), "Database", "Schema invalid", DateTime.UtcNow); | ||
| _bannerService.CriticalAlerts.Returns([alert]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| var banner = component.Find("aside.banner-critical"); | ||
| Assert.Contains("Database: Schema invalid", banner.TextContent); | ||
| Assert.Empty(component.FindAll("aside.banner-critical .banner-pagination")); | ||
| Assert.Single(component.FindAll("aside.banner-critical button.banner-dismiss")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_UnhandledError_RendersErrorBannerWithThreeButtons() | ||
| { | ||
| var error = new InvalidOperationException("kaboom"); | ||
| _bannerService.UnhandledError.Returns(error); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| var banner = component.Find("aside.banner-error"); | ||
| Assert.Contains("InvalidOperationException", banner.TextContent); | ||
| Assert.Contains("kaboom", banner.TextContent); | ||
|
|
||
| var buttons = component.FindAll("aside.banner-error .banner-actions button"); | ||
| Assert.Equal(3, buttons.Count); | ||
| Assert.Contains("Reload", buttons[0].TextContent); | ||
| Assert.Contains("Relaunch", buttons[1].TextContent); | ||
| Assert.Contains("Copy details", buttons[2].TextContent); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BannerHost_WarningSeverity_RendersWarningStyledBanner() | ||
| { | ||
| var info = new BannerInfoEntry(Guid.NewGuid(), | ||
| "Slow", | ||
| "Performance dip", | ||
| BannerSeverity.Warning, | ||
| DateTime.UtcNow); | ||
|
|
||
| _bannerService.InfoBanners.Returns([info]); | ||
|
|
||
| var component = Render<BannerHost>(); | ||
|
|
||
| Assert.Single(component.FindAll("aside.banner.banner-warning")); | ||
| Assert.Empty(component.FindAll("aside.banner.banner-info")); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/EventLogExpert.Components.Tests/EventLogExpert.Components.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <IsPackable>false</IsPackable> | ||
| <IsTestProject>true</IsTestProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="bunit" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\EventLogExpert.Components\EventLogExpert.Components.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| global using Xunit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| @using EventLogExpert.UI.Services | ||
| @{ | ||
| Exception? error = BannerService.UnhandledError; | ||
| IReadOnlyList<CriticalAlertEntry> criticals = BannerService.CriticalAlerts; | ||
| IReadOnlyList<BannerInfoEntry> infos = BannerService.InfoBanners; | ||
| BannerView view = _currentView = BannerViewSelector.Select(error, criticals, infos); | ||
| } | ||
|
|
||
| @switch (view) | ||
| { | ||
| case BannerView.Error when error is { } unhandledError: | ||
| <aside class="banner banner-error" role="alert"> | ||
| <span class="banner-message">An unexpected error occurred: @unhandledError.GetType().Name: @unhandledError.Message</span> | ||
|
|
||
| <div class="banner-actions"> | ||
| <button class="button" @onclick="OnReloadClickedAsync" @ref="_reloadButtonRef" type="button"> | ||
| <i aria-hidden="true" class="bi bi-arrow-clockwise"></i> Reload | ||
| </button> | ||
| <button class="button" @onclick="OnRelaunchClickedAsync" type="button"> | ||
| <i aria-hidden="true" class="bi bi-power"></i> Relaunch | ||
| </button> | ||
| <button class="button" @onclick="() => OnCopyDetailsClickedAsync(unhandledError)" type="button"> | ||
| <i aria-hidden="true" class="bi bi-clipboard"></i> Copy details | ||
| </button> | ||
| </div> | ||
|
|
||
| <div class="banner-feedback" role="status"> | ||
| @if (_showCopiedFeedback) | ||
| { | ||
| <span class="banner-chip">Copied</span> | ||
| } | ||
| @if (!string.IsNullOrEmpty(_recoveryFailureMessage)) | ||
| { | ||
| <span class="banner-subtitle">@_recoveryFailureMessage</span> | ||
| } | ||
| @if (!string.IsNullOrEmpty(_restartFailureMessage)) | ||
| { | ||
| <span class="banner-subtitle">@_restartFailureMessage</span> | ||
| } | ||
| </div> | ||
| </aside> | ||
| break; | ||
|
|
||
| case BannerView.Critical: | ||
| { | ||
| CriticalAlertEntry alert = criticals[0]; | ||
| <aside class="banner banner-critical" role="alert"> | ||
| <span class="banner-message">@alert.Title: @alert.Message</span> | ||
|
|
||
| @if (criticals.Count > 1) | ||
| { | ||
| <span class="banner-pagination">1 of @criticals.Count</span> | ||
| } | ||
|
|
||
| <button aria-label="Dismiss critical alert" | ||
| class="button banner-dismiss" | ||
| @onclick="() => OnDismissCritical(alert.Id)" | ||
| type="button"> | ||
| <i aria-hidden="true" class="bi bi-x"></i> | ||
| </button> | ||
| </aside> | ||
| break; | ||
| } | ||
|
|
||
| case BannerView.Info: | ||
| { | ||
| BannerInfoEntry info = infos[0]; | ||
| string severityClass = info.Severity == BannerSeverity.Warning ? "banner-warning" : "banner-info"; | ||
| <aside class="banner @severityClass" role="status"> | ||
| <span class="banner-message">@info.Title: @info.Message</span> | ||
|
|
||
| @if (infos.Count > 1) | ||
| { | ||
| <span class="banner-pagination">1 of @infos.Count</span> | ||
| } | ||
|
|
||
| <button aria-label="Dismiss banner" | ||
| class="button banner-dismiss" | ||
| @onclick="() => OnDismissInfo(info.Id)" | ||
| type="button"> | ||
| <i aria-hidden="true" class="bi bi-x"></i> | ||
| </button> | ||
| </aside> | ||
| break; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.