diff --git a/src/DbcView.Web/Components/DbcCommandPalette.razor b/src/DbcView.Web/Components/DbcCommandPalette.razor index 92abe3a..6d08286 100644 --- a/src/DbcView.Web/Components/DbcCommandPalette.razor +++ b/src/DbcView.Web/Components/DbcCommandPalette.razor @@ -7,7 +7,7 @@
@@ -18,12 +18,12 @@ data-testid="dbc-palette-input" type="text" role="combobox" - aria-label="Search messages and signals" + aria-label="Search messages, signals and commands" aria-expanded="@(Model.ResultCount > 0 ? "true" : "false")" aria-controls="@(Model.ResultCount > 0 ? "dbc-palette-results" : null)" aria-autocomplete="list" aria-activedescendant="@ActiveDescendant" - placeholder="Search messages, signals, IDs, transmitter or receiver" + placeholder="Search messages, signals, IDs, or commands" value="@Model.Query" @oninput="OnInput" @onkeydown="OnKeyDown" /> @@ -40,7 +40,7 @@ @if (!Model.HasQuery) {

- Type a message or signal name, a decimal/0x ID, a transmitter, or a receiver. + Type a message or signal name, a decimal/0x ID, or a command such as “check”.

} else if (Model.ResultCount == 0) @@ -53,6 +53,31 @@ class="dbc-palette-results" role="listbox" aria-label="Search results"> + @if (Model.CommandResults.Count > 0) + { +
+ + @for (var index = 0; index < Model.CommandResults.Count; index++) + { + var optionIndex = index; + var command = Model.CommandResults[index]; + var active = optionIndex == _activeIndex; +
+ @command.Title + @command.Detail +
+ } +
+ } @if (Model.MessageResults.Count > 0) {
@@ -61,7 +86,7 @@
@for (var index = 0; index < Model.MessageResults.Count; index++) { - var optionIndex = index; + var optionIndex = Model.CommandResults.Count + index; var result = Model.MessageResults[index]; var active = optionIndex == _activeIndex;
@for (var index = 0; index < Model.SignalResults.Count; index++) { - var optionIndex = Model.MessageResults.Count + index; + var optionIndex = Model.CommandResults.Count + + Model.MessageResults.Count + + index; var result = Model.SignalResults[index]; var active = optionIndex == _activeIndex;
@Announcement
@@ -143,31 +170,46 @@ [Parameter] public EventCallback OnSelected { get; set; } + [Parameter] + public EventCallback OnCommandSelected { get; set; } + [Parameter] public EventCallback OnClosed { get; set; } + private DbcPaletteCommand? ActiveCommand + { + get + { + return _activeIndex >= 0 && _activeIndex < Model.CommandResults.Count + ? Model.CommandResults[_activeIndex] + : null; + } + } + private DbcPaletteResult? ActiveResult { get { - if (_activeIndex < 0) + var index = _activeIndex - Model.CommandResults.Count; + if (index < 0) { return null; } - if (_activeIndex < Model.MessageResults.Count) + if (index < Model.MessageResults.Count) { - return Model.MessageResults[_activeIndex]; + return Model.MessageResults[index]; } - var signalIndex = _activeIndex - Model.MessageResults.Count; + var signalIndex = index - Model.MessageResults.Count; return signalIndex < Model.SignalResults.Count ? Model.SignalResults[signalIndex] : null; } } - private string? ActiveDescendant => ActiveResult is null ? null : OptionId(_activeIndex); + private string? ActiveDescendant => + ActiveCommand is null && ActiveResult is null ? null : OptionId(_activeIndex); private string Announcement { @@ -183,9 +225,14 @@ return "No matches."; } - return Model.TotalMatchCount > Model.ResultCount - ? $"{Model.ResultCount} results shown of {Model.TotalMatchCount} matches." - : $"{Model.ResultCount} results."; + if (Model.TotalMatchCount > Model.ResultCount) + { + return Model.ResultCount == 1 + ? $"1 result shown of {Model.TotalMatchCount} matches." + : $"{Model.ResultCount} results shown of {Model.TotalMatchCount} matches."; + } + + return Model.ResultCount == 1 ? "1 result." : $"{Model.ResultCount} results."; } } @@ -275,7 +322,11 @@ break; case "Enter": - if (ActiveResult is { } result) + if (ActiveCommand is { } command) + { + await SelectCommandAsync(command); + } + else if (ActiveResult is { } result) { await SelectAsync(result); } @@ -310,6 +361,18 @@ await OnSelected.InvokeAsync(result); } + private async Task SelectCommandAsync(DbcPaletteCommand command) + { + if (_closing) + { + return; + } + + _closing = true; + await CloseDialogAsync(); + await OnCommandSelected.InvokeAsync(command); + } + private async Task CloseAsync() { if (_closing) diff --git a/src/DbcView.Web/Components/DbcEditorPanel.razor b/src/DbcView.Web/Components/DbcEditorPanel.razor index 171de68..6c55649 100644 --- a/src/DbcView.Web/Components/DbcEditorPanel.razor +++ b/src/DbcView.Web/Components/DbcEditorPanel.razor @@ -36,6 +36,11 @@ @onclick="() => Model.SetMode(DbcEditorModel.ViewMode.Table)">Table
+ } @if (WarningCount > 0) { - + } @if (!string.IsNullOrEmpty(Document)) { @@ -79,4 +87,7 @@ [Parameter] public string? Persistence { get; set; } + + [Parameter] + public EventCallback OnProblemsSelected { get; set; } } diff --git a/src/DbcView.Web/Components/DbcViewWorkspace.razor b/src/DbcView.Web/Components/DbcViewWorkspace.razor index 3e20920..b2e28be 100644 --- a/src/DbcView.Web/Components/DbcViewWorkspace.razor +++ b/src/DbcView.Web/Components/DbcViewWorkspace.razor @@ -43,6 +43,10 @@ data-testid="dbc-compact-properties" aria-pressed="@(activePanel == "properties" ? "true" : "false")" @onclick='() => SetActivePanel("properties")'>Properties + } @if (workspace is null) @@ -73,7 +77,8 @@ UndefinedByteCount="@currentUndefinedBytes" Persistence="@PersistenceStatus" ErrorCount="@errorCount" - WarningCount="@warningCount" /> + WarningCount="@warningCount" + OnProblemsSelected="FocusProblemsAsync" /> @@ -83,13 +88,20 @@ + OnSignalSelected="ShowSignalProperties" + OnCheck="CheckFromEditorAsync" /> + + + @@ -101,13 +113,14 @@ { } @if (persistenceDialogOpen) { @@ -144,6 +157,11 @@ private string? persistenceError; private string? persistenceNotice; private CancellationTokenSource? persistenceDebounce; + private IReadOnlyList problems = Array.Empty(); + private string? problemsDocumentKey; + private string? problemsCheckedContent; + private CancellationTokenSource? problemsDebounce; + private DbcProblemsPanel? problemsPanel; [Inject] private IAtlasWorkspaceFactory Factory { get; set; } = null!; @@ -285,6 +303,7 @@ currentEncoding = file.Encoding?.DisplayName; currentUndefinedBytes = file.Encoding?.UndefinedByteCount ?? 0; UpdateStatusDiagnostics(); + ShowProblemsForFile(documentId, file); operationStatus = $"Opened {documentId.Key}"; activePanel = "editor"; } @@ -659,6 +678,7 @@ } UpdateStatusDiagnostics(); + ShowProblemsForFile(documentId, file); activePanel = "editor"; } catch (Exception ex) @@ -834,6 +854,155 @@ operationStatus = "Local session could not be restored"; } + private void ResetProblems() + { + problems = Array.Empty(); + problemsDocumentKey = null; + problemsCheckedContent = null; + CancelScheduledCheck(); + } + + private void ShowProblemsForFile(DbcDocumentId documentId, DbcFileEntry file) + { + problems = file.ParseResult.Diagnostics; + problemsDocumentKey = documentId.Key; + problemsCheckedContent = file.Content; + CancelScheduledCheck(); + UpdateProblemCheckState(); + } + + private void UpdateProblemCheckState() + { + if (currentDocument is not { } documentId + || Sessions.Find(documentId) is not { } model) + { + return; + } + + if (string.Equals(model.EditedContent, problemsCheckedContent, StringComparison.Ordinal)) + { + return; + } + + ScheduleCheck(); + } + + private void ScheduleCheck() + { + var cancellation = new CancellationTokenSource(); + var previous = Interlocked.Exchange(ref problemsDebounce, cancellation); + previous?.Cancel(); + previous?.Dispose(); + _ = CheckAfterDelayAsync(cancellation.Token); + } + + private async Task CheckAfterDelayAsync(CancellationToken cancellationToken) + { + try + { + await Task.Delay(400, cancellationToken); + } + catch (OperationCanceledException) + { + return; + } + + await InvokeAsync(CheckCurrentDocumentAsync); + } + + private void CancelScheduledCheck() + { + var pending = Interlocked.Exchange(ref problemsDebounce, null); + pending?.Cancel(); + pending?.Dispose(); + } + + private async Task CheckFromEditorAsync() + { + await CheckCurrentDocumentAsync(); + await FocusProblemsAsync(); + } + + private async Task CheckCurrentDocumentAsync() + { + if (currentDocument is not { } documentId + || dbcWorkspace.Find(documentId) is not { } file) + { + return; + } + + CancelScheduledCheck(); + var model = Sessions.Find(documentId); + var content = model?.EditedContent ?? file.Content; + + DbcParseResult result; + try + { + result = model?.ValidateDownload() ?? dbcWorkspace.Parse(file.Content); + } + catch (Exception ex) + { + operationStatus = $"Check failed: {ex.Message}"; + await RefreshAsync(); + return; + } + + problems = result.Diagnostics; + problemsDocumentKey = documentId.Key; + problemsCheckedContent = content; + errorCount = result.ErrorCount; + warningCount = result.Diagnostics.Count( + diagnostic => diagnostic.Severity == DbcDiagnosticSeverity.Warning); + operationStatus = result.Diagnostics.Count == 0 + ? $"Checked {documentId.Key}: no problems" + : $"Checked {documentId.Key}: {result.ErrorCount} error(s), {warningCount} warning(s)"; + await RefreshAsync(); + } + + private async Task FocusProblemsAsync() + { + activePanel = "problems"; + await RefreshAsync(); + if (problemsPanel is not null) + { + await problemsPanel.FocusAsync(); + } + } + + private async Task OnPaletteCommandSelected(DbcPaletteCommand command) + { + paletteOpen = false; + if (string.Equals( + command.Id, + DbcCommandPaletteModel.CheckDocumentCommandId, + StringComparison.Ordinal)) + { + await CheckFromEditorAsync(); + } + + await RefreshAsync(); + } + + [JSInvokable] + public void CheckDocumentFromShortcut() + { + _ = InvokeAsync(async () => + { + await CheckFromEditorAsync(); + StateHasChanged(); + }); + } + + private async Task LocateProblemAsync(int lineNumber) + { + if (lineNumber <= 0 || currentDocument is null) + { + return; + } + + await LocateSourceAsync(lineNumber); + } + private async Task UndoAsync() { if (workspace is null) @@ -861,7 +1030,6 @@ private void OnWorkspaceChanged(object? sender, WorkspaceChangedEventArgs args) { revision = args.ChangeSet.AfterRevision; - UpdateStatusDiagnostics(); SchedulePersist(); _ = RefreshAsync(); } @@ -869,10 +1037,17 @@ private void OnDocumentStoreChanged() { UpdateStatusDiagnostics(); - if (currentDocument is { } documentId - && dbcWorkspace.Find(documentId) is { } file) + if (currentDocument is { } documentId) { - dbcProperty.Refresh(file); + if (dbcWorkspace.Find(documentId) is { } file) + { + dbcProperty.Refresh(file); + ShowProblemsForFile(documentId, file); + } + else + { + ResetProblems(); + } } SchedulePersist(); @@ -881,6 +1056,7 @@ private void OnEditorSessionsChanged() { + UpdateProblemCheckState(); SchedulePersist(); } @@ -902,6 +1078,11 @@ dbcProperty.ShowFile(file); currentEncoding = file.Encoding?.DisplayName; currentUndefinedBytes = file.Encoding?.UndefinedByteCount ?? 0; + ShowProblemsForFile(documentId, file); + } + else + { + ResetProblems(); } UpdateStatusDiagnostics(); @@ -923,6 +1104,7 @@ currentEncoding = null; currentUndefinedBytes = 0; paletteOpen = false; + ResetProblems(); operationStatus = "Ready"; SchedulePersist(); _ = RefreshAsync(); @@ -950,33 +1132,39 @@ private void UpdateStatusDiagnostics() { - errorCount = 0; - warningCount = 0; - - if (currentDocument is null) + if (currentDocument is not { } documentId) { + errorCount = 0; + warningCount = 0; return; } - var file = dbcWorkspace.Find(currentDocument.Value); + var file = dbcWorkspace.Find(documentId); if (file is null) { currentDocument = null; currentDocumentItemId = null; + errorCount = 0; + warningCount = 0; return; } + var errors = 0; + var warnings = 0; foreach (var diagnostic in file.ParseResult.Diagnostics) { if (diagnostic.Severity == DbcDiagnosticSeverity.Error) { - errorCount++; + errors++; } else { - warningCount++; + warnings++; } } + + errorCount = errors; + warningCount = warnings; } private async Task RefreshAsync() @@ -1007,6 +1195,9 @@ persistenceDebounce?.Cancel(); persistenceDebounce?.Dispose(); persistenceDebounce = null; + problemsDebounce?.Cancel(); + problemsDebounce?.Dispose(); + problemsDebounce = null; dbcTree.Dispose(); dbcWorkspace.Dispose(); await workspace.DisposeAsync(); diff --git a/src/DbcView.Web/Components/DbcViewWorkspaceDefinition.cs b/src/DbcView.Web/Components/DbcViewWorkspaceDefinition.cs index ee09321..1a524b5 100644 --- a/src/DbcView.Web/Components/DbcViewWorkspaceDefinition.cs +++ b/src/DbcView.Web/Components/DbcViewWorkspaceDefinition.cs @@ -17,12 +17,13 @@ internal static AtlasWorkspaceDefinition Create(string workspaceName) var dbcTree = Tool("dbc-tree", "DBC Explorer", contentKind: DbcContentKinds.DbcTree); var dbcProperty = Tool("dbc-property", "Properties", contentKind: DbcContentKinds.DbcProperty); + var dbcProblems = Tool("dbc-problems", "Problems", contentKind: DbcContentKinds.DbcProblems); var dbcEditor = Document("dbc-editor", "DBC Editor", isPinned: true, contentKind: DbcContentKinds.DbcEditor); - // The six LogicalRegion slots are preserved as tool groups. Only the - // explorer and properties carry content; the remaining four groups are - // intentionally empty (no DockItems), keeping the Atlas six-region - // toolbar demonstration intact while the DBC demo fills three panels. + // The six LogicalRegion slots are preserved as tool groups. The + // explorer, properties and bottom Problems group carry content; the + // remaining three groups are intentionally empty (no DockItems), + // keeping the Atlas six-region toolbar demonstration intact. var leftUpper = ToolGroup("left-upper", LogicalRegion.InlineStartUpper, dbcTree.Id); var leftLower = EmptyToolGroup("left-lower", LogicalRegion.InlineStartLower); var editor = new GroupNode( @@ -34,7 +35,10 @@ internal static AtlasWorkspaceDefinition Create(string workspaceName) dbcEditor.Id); var rightUpper = ToolGroup("right-upper", LogicalRegion.InlineEndUpper, dbcProperty.Id); var rightLower = EmptyToolGroup("right-lower", LogicalRegion.InlineEndLower); - var bottomLeft = EmptyToolGroup("bottom-left", LogicalRegion.BlockEndInlineStart); + var bottomLeft = ToolGroup( + "bottom-left", + LogicalRegion.BlockEndInlineStart, + dbcProblems.Id); var bottomRight = EmptyToolGroup("bottom-right", LogicalRegion.BlockEndInlineEnd); var leftDock = Split( @@ -100,6 +104,7 @@ internal static AtlasWorkspaceDefinition Create(string workspaceName) { dbcTree, dbcProperty, + dbcProblems, dbcEditor, }; var toolBars = new[] @@ -111,6 +116,7 @@ internal static AtlasWorkspaceDefinition Create(string workspaceName) { new ToolBarOrderState(LogicalRegion.InlineStartUpper, new[] { dbcTree.Id }), new ToolBarOrderState(LogicalRegion.InlineEndUpper, new[] { dbcProperty.Id }), + new ToolBarOrderState(LogicalRegion.BlockEndInlineStart, new[] { dbcProblems.Id }), }; return new AtlasWorkspaceDefinition( diff --git a/src/DbcView.Web/DbcContentKinds.cs b/src/DbcView.Web/DbcContentKinds.cs index 89ff1d7..01632dd 100644 --- a/src/DbcView.Web/DbcContentKinds.cs +++ b/src/DbcView.Web/DbcContentKinds.cs @@ -11,4 +11,5 @@ public static class DbcContentKinds public const string DbcTree = "dbc-tree"; public const string DbcEditor = "dbc-editor"; public const string DbcProperty = "dbc-property"; + public const string DbcProblems = "dbc-problems"; } diff --git a/src/DbcView.Web/ViewModels/DbcCommandPaletteModel.cs b/src/DbcView.Web/ViewModels/DbcCommandPaletteModel.cs index f5533bd..55e63c6 100644 --- a/src/DbcView.Web/ViewModels/DbcCommandPaletteModel.cs +++ b/src/DbcView.Web/ViewModels/DbcCommandPaletteModel.cs @@ -40,18 +40,38 @@ public sealed record DbcPaletteResult( $"0x{Message.Id:X} · {Message.Name} · {Signal.Receiver}"); } +/// A workspace command offered by the palette (for example, re-run validation). +public sealed record DbcPaletteCommand( + string Id, + string Title, + string Detail, + DbcPaletteMatchRank Rank); + /// -/// Deterministic search over the active document's messages and signals. -/// Matching is exact > prefix > substring, ties keep source order, and -/// the grouped result list is capped at 50 entries. +/// Deterministic search over the active document's messages, signals and +/// workspace commands. Matching is exact > prefix > substring, ties keep +/// source order, and the grouped result list is capped at 50 entries. /// public sealed class DbcCommandPaletteModel { public const int MaxResults = 50; + public const string CheckDocumentCommandId = "check-document"; + + private const int CommandMinimumQueryLength = 3; + + private static readonly CommandDefinition[] Commands = + { + new( + CheckDocumentCommandId, + "Check current document", + "Re-run DBC validation for the active file (Ctrl+Enter)", + "check validate validation recheck problems diagnostics"), + }; private DbcDocument? _document; private List?[] _messageCommentsByIndex = Array.Empty?>(); private List?[][] _signalCommentsByIndex = Array.Empty?[]>(); + private IReadOnlyList _commandResults = Array.Empty(); private IReadOnlyList _messageResults = Array.Empty(); private IReadOnlyList _signalResults = Array.Empty(); @@ -61,11 +81,14 @@ public sealed class DbcCommandPaletteModel public bool HasQuery => !string.IsNullOrWhiteSpace(Query); + public IReadOnlyList CommandResults => _commandResults; + public IReadOnlyList MessageResults => _messageResults; public IReadOnlyList SignalResults => _signalResults; - public int ResultCount => _messageResults.Count + _signalResults.Count; + public int ResultCount => + _commandResults.Count + _messageResults.Count + _signalResults.Count; public int TotalMatchCount { get; private set; } @@ -134,6 +157,7 @@ public void SetDocument(DbcDocument? document, DbcSemanticIndex? semantics = nul } Query = string.Empty; + _commandResults = Array.Empty(); _messageResults = Array.Empty(); _signalResults = Array.Empty(); TotalMatchCount = 0; @@ -157,15 +181,17 @@ private void Refresh() var needle = Query.Trim(); if (_document is null || needle.Length == 0) { + _commandResults = Array.Empty(); _messageResults = Array.Empty(); _signalResults = Array.Empty(); return; } + _commandResults = MatchCommands(needle); var exact = new List(MaxResults); var prefix = new List(MaxResults); var substring = new List(MaxResults); - var total = 0; + var total = _commandResults.Count; var numericQuery = TryParseMessageId(needle, out var numericMessageId); for (var messageIndex = 0; messageIndex < _document.Messages.Count; messageIndex++) @@ -280,6 +306,50 @@ private static void AppendBounded( } } + private static IReadOnlyList MatchCommands(string query) + { + // Short queries are almost always message/signal lookups; matching + // commands there would hijack Enter and hide the intended result. + if (query.Length < CommandMinimumQueryLength) + { + return Array.Empty(); + } + + List? matches = null; + foreach (var command in Commands) + { + var rank = MatchCommand(command, query); + if (rank is null) + { + continue; + } + + matches ??= new List(Commands.Length); + matches.Add(new DbcPaletteCommand( + command.Id, + command.Title, + command.Detail, + rank.Value)); + } + + return matches is null ? Array.Empty() : matches; + } + + private static DbcPaletteMatchRank? MatchCommand( + CommandDefinition command, + string query) + { + var rank = MatchText(command.Title, query); + foreach (var keyword in command.Keywords.Split( + ' ', + StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + { + rank = Best(rank, MatchText(keyword, query)); + } + + return Best(rank, MatchText(command.Detail, query)); + } + private static DbcPaletteMatchRank? MatchMessage( DbcMessage message, string query, @@ -391,4 +461,10 @@ private static bool TryParseMessageId(string query, out uint messageId) return candidate < current ? candidate : current; } + + private readonly record struct CommandDefinition( + string Id, + string Title, + string Detail, + string Keywords); } diff --git a/src/DbcView.Web/_Imports.razor b/src/DbcView.Web/_Imports.razor index 952c882..d946884 100644 --- a/src/DbcView.Web/_Imports.razor +++ b/src/DbcView.Web/_Imports.razor @@ -6,3 +6,4 @@ @using DbcView.Domain @using DbcView.Web.Components @using Astrea.Components.Tree +@using Astrea.Components.ResourceTable diff --git a/src/DbcView.Web/wwwroot/css/app.css b/src/DbcView.Web/wwwroot/css/app.css index 178a532..1828f67 100644 --- a/src/DbcView.Web/wwwroot/css/app.css +++ b/src/DbcView.Web/wwwroot/css/app.css @@ -525,6 +525,25 @@ textarea { color: var(--dv-warning-text); } +.dbc-statusbar-button { + border: 0; + padding: 0; + background: transparent; + color: inherit; + font: inherit; + cursor: pointer; +} + +.dbc-statusbar-button:hover { + text-decoration: underline; +} + +.dbc-statusbar-button:focus-visible { + border-radius: 2px; + outline: 2px solid var(--dv-focus); + outline-offset: 2px; +} + .dbc-view-verification { display: grid; width: 100vw; @@ -870,6 +889,104 @@ textarea { overflow-wrap: anywhere; } +/* ============================================================ + Problems panel (Astrea ResourceTable). + ============================================================ */ +.dbc-problems-panel { + display: flex; + flex-direction: column; + height: 100%; + min-height: 0; + box-sizing: border-box; + padding: 0.5rem 0.625rem; + background: var(--dv-surface); + color: var(--dv-text); + font-size: 0.75rem; +} + +/* Astrea defines --ast-rt-* on its own root element, so the theme override + must land on that same element (via ContainerCss), not on an ancestor. */ +.dbc-problems-panel .dbc-problems-table { + --ast-rt-font-family: var(--dv-font-sans); + --ast-rt-font-size: 0.75rem; + --ast-rt-color-text: var(--dv-text); + --ast-rt-color-bg: var(--dv-surface); + --ast-rt-color-header-bg: var(--dv-sunken); + --ast-rt-color-border: var(--dv-divider); + --ast-rt-color-border-strong: var(--dv-border); + --ast-rt-color-accent: var(--dv-accent); + --ast-rt-color-hover-bg: var(--dv-hover); + --ast-rt-color-selected-bg: var(--dv-selection); + --ast-rt-color-scroll-thumb: var(--dv-border); + --ast-rt-color-scroll-track: var(--dv-sunken); + --ast-rt-th-content-padding: 0.5rem; + flex: 1 1 auto; + height: auto; + min-height: 0; + padding-left: 0; +} + +.dbc-problems-panel:focus-visible { + outline: 2px solid var(--dv-focus); + outline-offset: -2px; +} + +.dbc-problems-panel .ast-rt-table th, +.dbc-problems-panel .ast-rt-table td { + padding: 0 0.5rem; + text-align: start; +} + +.dbc-problems-panel .ast-rt-table td { + height: 1.75rem; + line-height: 1.75rem; +} + +.dbc-problems-panel .ast-rt-th-content { + padding-right: 0.5rem; + text-align: start; +} + +.dbc-problem-row { + cursor: pointer; +} + +.dbc-problem-row:hover td { + background: var(--dv-hover); +} + +.dbc-problem-row:focus-visible { + outline: 2px solid var(--dv-focus); + outline-offset: -2px; +} + +.dbc-problem-row[data-severity="error"] .dbc-problem-severity { + color: var(--dv-danger-text); + font-weight: 600; +} + +.dbc-problem-row[data-severity="warning"] .dbc-problem-severity { + color: var(--dv-warning-text); + font-weight: 600; +} + +.dbc-problem-line, +.dbc-problem-code { + color: var(--dv-text-secondary); + font-family: var(--dv-font-mono); + font-size: 0.6875rem; +} + +.dbc-problem-message { + color: var(--dv-text); +} + +.dbc-problems-panel .dbc-problems-empty { + padding: 0.75rem 0.5rem; + color: var(--dv-text-muted); + text-align: start; +} + /* ============================================================ Editor. ============================================================ */ @@ -1326,7 +1443,8 @@ textarea { .dbc-view-shell[data-compact-active="explorer"] [data-atlas-group-id="left-upper"], .dbc-view-shell[data-compact-active="editor"] [data-atlas-group-id="editor"], - .dbc-view-shell[data-compact-active="properties"] [data-atlas-group-id="right-upper"] { + .dbc-view-shell[data-compact-active="properties"] [data-atlas-group-id="right-upper"], + .dbc-view-shell[data-compact-active="problems"] [data-atlas-group-id="bottom-left"] { display: grid; } diff --git a/src/DbcView.Web/wwwroot/index.html b/src/DbcView.Web/wwwroot/index.html index c15b7ae..7b16bae 100644 --- a/src/DbcView.Web/wwwroot/index.html +++ b/src/DbcView.Web/wwwroot/index.html @@ -9,6 +9,7 @@ + DbcView diff --git a/src/DbcView.Web/wwwroot/js/dbc-palette.js b/src/DbcView.Web/wwwroot/js/dbc-palette.js index 4acb40b..b4da9e7 100644 --- a/src/DbcView.Web/wwwroot/js/dbc-palette.js +++ b/src/DbcView.Web/wwwroot/js/dbc-palette.js @@ -5,21 +5,30 @@ export function installShortcut(dotNetReference) { disposeShortcut(); const handler = event => { - if (event.key !== "/" || event.ctrlKey || event.metaKey || event.altKey) { + const shell = document.querySelector("[data-testid='dbc-view-shell']"); + if (!shell || shell.dataset.documentOpen !== "true") { return; } - if (isEditable(event.target)) { + if (document.querySelector("dialog[open]")) { return; } - const shell = document.querySelector("[data-testid='dbc-view-shell']"); - if (!shell || shell.dataset.documentOpen !== "true") { + if (event.ctrlKey + && !event.shiftKey + && !event.metaKey + && !event.altKey + && event.key === "Enter") { + event.preventDefault(); + dotNetReference.invokeMethodAsync("CheckDocumentFromShortcut").catch(() => { }); return; } - const palette = document.querySelector(paletteSelector); - if (palette && palette.open) { + if (event.key !== "/" || event.ctrlKey || event.metaKey || event.altKey) { + return; + } + + if (isEditable(event.target)) { return; } diff --git a/tests/DbcView.BrowserTests/ProblemsBrowserTests.cs b/tests/DbcView.BrowserTests/ProblemsBrowserTests.cs new file mode 100644 index 0000000..b19b141 --- /dev/null +++ b/tests/DbcView.BrowserTests/ProblemsBrowserTests.cs @@ -0,0 +1,69 @@ +using System.Text; +using Microsoft.Playwright; +using Xunit; +using static Microsoft.Playwright.Assertions; + +namespace DbcView.BrowserTests; + +public sealed class ProblemsBrowserTests : IClassFixture +{ + private readonly WebAppFixture _fixture; + + public ProblemsBrowserTests(WebAppFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public async Task Warnings_render_and_auto_check_reparses_unsaved_text() + { + await using var context = await _fixture.Browser.NewContextAsync( + new BrowserNewContextOptions + { + ViewportSize = new ViewportSize { Width = 1440, Height = 900 }, + }); + var page = await context.NewPageAsync(); + await page.GotoAsync(_fixture.BaseUrl); + await Expect(page.Locator("[data-testid='dbc-view-shell']")).ToBeVisibleAsync(); + + await page.SetInputFilesAsync( + "input[type=file]", + new FilePayload + { + Name = "problems.dbc", + MimeType = "text/plain", + Buffer = Encoding.UTF8.GetBytes( + "VERSION \"\"\nBU_: XXX\n\nBO_ 100 M: 1 XXX\n" + + " SG_ TooWide : 7|2@0+ (1,0) [0|3] \"\" XXX\n"), + }); + var file = page.Locator( + "[data-testid='dbc-file'][data-file-key='DBC/problems.dbc']"); + await Expect(file).ToBeVisibleAsync(); + await file.ClickAsync(); + await Expect(page.Locator("[data-testid='dbc-table']")).ToBeVisibleAsync(); + + await Expect(page.Locator("[data-testid='dbc-parse-warnings']")).ToHaveCountAsync(0); + await Expect(page.Locator("[data-testid='dbc-problems-check']")).ToHaveCountAsync(0); + await Expect(page.Locator("[data-testid='dbc-check-document']")).ToBeVisibleAsync(); + var row = page.Locator("[data-testid='dbc-problem-row']"); + await Expect(row).ToHaveCountAsync(1); + await Expect(row).ToHaveAttributeAsync("data-severity", "warning"); + await Expect(page.Locator("[data-testid='dbc-problem-line']")).ToHaveTextAsync("5"); + await Expect(page.Locator("[data-testid='dbc-problem-code']")).ToHaveTextAsync("DBC006"); + await Expect(page.Locator("[data-testid='dbc-problem-message']")) + .ToContainTextAsync("spans bits"); + + await page.Locator("[data-testid='dbc-mode-text']").ClickAsync(); + await page.Locator("textarea").FillAsync("this is not a DBC file"); + await Expect(page.Locator("[data-testid='dbc-problem-code']").First) + .ToHaveTextAsync("DBC001"); + await Expect(page.Locator("[data-testid='dbc-problem-code']").Nth(1)) + .ToHaveTextAsync("DBC002"); + await Expect(page.Locator("[data-testid='dbc-status-errors']")) + .ToContainTextAsync("2 errors"); + + await page.Keyboard.PressAsync("Control+Enter"); + await Expect(page.Locator("[data-testid='dbc-view-status-bar']")) + .ToContainTextAsync("Checked DBC/problems.dbc"); + } +} diff --git a/tests/DbcView.Tests/AtlasJsInteropSetup.cs b/tests/DbcView.Tests/AtlasJsInteropSetup.cs index 30bfcaf..64b2e74 100644 --- a/tests/DbcView.Tests/AtlasJsInteropSetup.cs +++ b/tests/DbcView.Tests/AtlasJsInteropSetup.cs @@ -26,6 +26,10 @@ public static BunitJSModuleInterop Setup(BunitJSInterop jsInterop) // keep the rest of the runtime strict and let this third-party module // answer with defaults. astrea.Mode = JSRuntimeMode.Loose; + + var resourceTable = jsInterop.SetupModule( + "./_content/Astrea.Components/astrea-resource-table.js"); + resourceTable.Mode = JSRuntimeMode.Loose; return module; } } diff --git a/tests/DbcView.Tests/DbcCommandPaletteModelTests.cs b/tests/DbcView.Tests/DbcCommandPaletteModelTests.cs index 3050013..70ced2e 100644 --- a/tests/DbcView.Tests/DbcCommandPaletteModelTests.cs +++ b/tests/DbcView.Tests/DbcCommandPaletteModelTests.cs @@ -158,6 +158,7 @@ public void Empty_query_returns_no_results_and_no_hint_rows() model.SetQuery(" "); Assert.False(model.HasQuery); + Assert.Empty(model.CommandResults); Assert.Empty(model.MessageResults); Assert.Empty(model.SignalResults); Assert.Equal(0, model.TotalMatchCount); @@ -203,12 +204,42 @@ public void SetDocument_resets_the_query_and_results() model.SetDocument(Document); + Assert.Empty(model.CommandResults); Assert.Empty(model.MessageResults); Assert.Empty(model.SignalResults); Assert.Equal(string.Empty, model.Query); Assert.Equal(0, model.TotalMatchCount); } + [Fact] + public void Check_command_matches_name_and_keyword_queries() + { + var model = new DbcCommandPaletteModel(); + model.SetDocument(Document); + + model.SetQuery("check"); + + var command = Assert.Single(model.CommandResults); + Assert.Equal(DbcCommandPaletteModel.CheckDocumentCommandId, command.Id); + Assert.Equal(1, model.ResultCount); + Assert.Equal(1, model.TotalMatchCount); + + model.SetQuery("validate"); + Assert.Single(model.CommandResults); + + model.SetQuery("c"); + Assert.Empty(model.CommandResults); + + model.SetQuery("ch"); + Assert.Empty(model.CommandResults); + + model.SetQuery("che"); + Assert.Single(model.CommandResults); + + model.SetQuery("speed"); + Assert.Empty(model.CommandResults); + } + private static DbcMessage Message( uint id, string name, diff --git a/tests/DbcView.Tests/DbcCommandPaletteTests.cs b/tests/DbcView.Tests/DbcCommandPaletteTests.cs index 3c9cdbf..da5962c 100644 --- a/tests/DbcView.Tests/DbcCommandPaletteTests.cs +++ b/tests/DbcView.Tests/DbcCommandPaletteTests.cs @@ -83,6 +83,31 @@ public async Task Keyboard_moves_the_active_descendant_and_enter_selects() Assert.Equal("SpeedWheel", model.SignalResults[0].PrimaryText); } + [Fact] + public async Task Command_results_are_rendered_first_and_enter_runs_them() + { + DbcPaletteCommand? selectedCommand = null; + var cut = RenderPalette( + out _, + out _, + onCommandSelected: command => selectedCommand = command); + + var input = cut.Find("[data-testid='dbc-palette-input']"); + input.Input("check"); + + Assert.Empty(cut.FindAll("[data-testid='dbc-palette-result']")); + var command = cut.Find("[data-testid='dbc-palette-command']"); + Assert.Equal("check-document", command.GetAttribute("data-command-id")); + Assert.Equal("true", command.GetAttribute("aria-selected")); + Assert.Equal("dbc-palette-option-0", input.GetAttribute("aria-activedescendant")); + Assert.Contains("Commands", cut.Markup, StringComparison.Ordinal); + + await input.KeyDownAsync(new KeyboardEventArgs { Key = "Enter" }); + + Assert.NotNull(selectedCommand); + Assert.Equal(DbcCommandPaletteModel.CheckDocumentCommandId, selectedCommand!.Id); + } + [Fact] public async Task Escape_closes_the_palette() { @@ -121,7 +146,8 @@ public async Task Close_button_closes_the_palette() private IRenderedComponent RenderPalette( out DbcCommandPaletteModel model, out SelectedResult selected, - Action? onClosed = null) + Action? onClosed = null, + Action? onCommandSelected = null) { var paletteModel = new DbcCommandPaletteModel(); paletteModel.SetDocument(Document); @@ -144,6 +170,15 @@ private IRenderedComponent RenderPalette( component => component.OnClosed, EventCallback.Factory.Create(this, onClosed)); } + + if (onCommandSelected is not null) + { + parameters.Add( + component => component.OnCommandSelected, + EventCallback.Factory.Create( + this, + onCommandSelected)); + } }); } diff --git a/tests/DbcView.Tests/DbcPanelsTests.cs b/tests/DbcView.Tests/DbcPanelsTests.cs index 38fa646..c6da158 100644 --- a/tests/DbcView.Tests/DbcPanelsTests.cs +++ b/tests/DbcView.Tests/DbcPanelsTests.cs @@ -344,7 +344,7 @@ public void EditorPanel_save_updates_workspace_content() } [Fact] - public void EditorPanel_save_invalid_draft_shows_errors_and_keeps_raw_text() + public void EditorPanel_save_invalid_draft_keeps_raw_text_and_blocks_table() { using var workspace = TestWorkspace.Create(); var entry = workspace.AddFile("can-a", "a.dbc", ValidDbc); @@ -360,11 +360,9 @@ public void EditorPanel_save_invalid_draft_shows_errors_and_keeps_raw_text() cut.WaitForAssertion( () => { - var alert = cut.Find("[data-testid='dbc-parse-errors']"); - Assert.Equal("alert", alert.GetAttribute("role")); - Assert.Contains("unvalidated draft", alert.TextContent, StringComparison.Ordinal); - Assert.Contains("DBC001", alert.TextContent, StringComparison.Ordinal); + Assert.False(workspace.Find(entry.Id)!.ParseResult.IsValid); Assert.Equal(InvalidDbc, workspace.Find(entry.Id)!.Content); + Assert.Empty(cut.FindAll("[data-testid='dbc-parse-errors']")); }); cut.Find("[data-testid='dbc-mode-table']").Click(); @@ -375,7 +373,7 @@ public void EditorPanel_save_invalid_draft_shows_errors_and_keeps_raw_text() } [Fact] - public void EditorPanel_shows_parse_errors_for_invalid_file_instead_of_empty_document() + public void EditorPanel_blocks_table_for_invalid_file_instead_of_empty_document() { using var workspace = TestWorkspace.Create(); var entry = workspace.AddFile("can-a", "bad.dbc", InvalidDbc); @@ -384,9 +382,9 @@ public void EditorPanel_shows_parse_errors_for_invalid_file_instead_of_empty_doc var cut = Render(p => p.Add(x => x.Model, model)); - Assert.NotEmpty(cut.FindAll("[data-testid='dbc-parse-errors']")); - Assert.Contains("DBC001", cut.Markup, StringComparison.Ordinal); + Assert.Contains("Table view is unavailable", cut.Markup, StringComparison.Ordinal); Assert.DoesNotContain("No messages in this DBC file", cut.Markup, StringComparison.Ordinal); + Assert.Empty(cut.FindAll("[data-testid='dbc-parse-errors']")); } [Fact] @@ -400,11 +398,10 @@ public void EditorPanel_still_reports_valid_empty_file_as_no_messages() var cut = Render(p => p.Add(x => x.Model, model)); Assert.Contains("No messages in this DBC file.", cut.Markup, StringComparison.Ordinal); - Assert.Empty(cut.FindAll("[data-testid='dbc-parse-errors']")); } [Fact] - public void EditorPanel_shows_bit_range_warnings_without_hiding_the_table() + public void EditorPanel_keeps_table_usable_when_file_has_warnings() { using var workspace = TestWorkspace.Create(); var entry = workspace.AddFile( @@ -417,7 +414,7 @@ public void EditorPanel_shows_bit_range_warnings_without_hiding_the_table() var cut = Render(p => p.Add(x => x.Model, model)); - Assert.NotEmpty(cut.FindAll("[data-testid='dbc-parse-warnings']")); + Assert.Empty(cut.FindAll("[data-testid='dbc-parse-warnings']")); Assert.Empty(cut.FindAll("[data-testid='dbc-parse-errors']")); cut.Find("[data-testid='dbc-toggle-message']").Click(); diff --git a/tests/DbcView.Tests/DbcProblemsPanelTests.cs b/tests/DbcView.Tests/DbcProblemsPanelTests.cs new file mode 100644 index 0000000..ed83d08 --- /dev/null +++ b/tests/DbcView.Tests/DbcProblemsPanelTests.cs @@ -0,0 +1,104 @@ +#nullable enable +using System; +using DbcView.Domain; +using DbcView.Web.Components; +using Bunit; +using Xunit; + +namespace DbcView.Tests; + +public sealed class DbcProblemsPanelTests : BunitContext +{ + public DbcProblemsPanelTests() + { + JSInterop.Mode = JSRuntimeMode.Strict; + AtlasJsInteropSetup.Setup(JSInterop); + } + + [Fact] + public void Renders_severity_line_code_and_message_for_each_diagnostic() + { + var diagnostics = new[] + { + new DbcDiagnostic( + DbcDiagnosticSeverity.Error, + "DBC001", + "Missing VERSION section.", + 0), + new DbcDiagnostic( + DbcDiagnosticSeverity.Warning, + "DBC006", + "Signal 'TooWide' spans bits 31..38.", + 61), + }; + + var cut = Render(p => p + .Add(x => x.DocumentKey, "DBC/bmw.dbc") + .Add(x => x.Diagnostics, diagnostics)); + + var rows = cut.FindAll("[data-testid='dbc-problem-row']"); + Assert.Equal(2, rows.Count); + + Assert.Equal("error", rows[0].GetAttribute("data-severity")); + Assert.Contains("Error", rows[0].TextContent, StringComparison.Ordinal); + Assert.Contains("DBC001", rows[0].TextContent, StringComparison.Ordinal); + Assert.Contains("Missing VERSION section.", rows[0].TextContent, StringComparison.Ordinal); + Assert.Equal( + "—", + cut.FindAll("[data-testid='dbc-problem-line']")[0].TextContent.Trim()); + + Assert.Equal("warning", rows[1].GetAttribute("data-severity")); + Assert.Equal( + "61", + cut.FindAll("[data-testid='dbc-problem-line']")[1].TextContent.Trim()); + Assert.Contains("spans bits", rows[1].TextContent, StringComparison.Ordinal); + } + + [Fact] + public void Empty_state_explains_when_no_document_is_open() + { + var cut = Render(p => p + .Add(x => x.Diagnostics, Array.Empty())); + + Assert.Contains( + "Open a .dbc file", + cut.Find("[data-testid='dbc-problems-empty']").TextContent, + StringComparison.Ordinal); + } + + [Fact] + public void Empty_state_reports_no_problems_for_an_open_document() + { + var cut = Render(p => p + .Add(x => x.DocumentKey, "DBC/a.dbc") + .Add(x => x.Diagnostics, Array.Empty())); + + Assert.Contains( + "No problems found.", + cut.Find("[data-testid='dbc-problems-empty']").TextContent, + StringComparison.Ordinal); + } + + [Fact] + public void Row_click_reports_the_line_number() + { + int? located = null; + var diagnostics = new[] + { + new DbcDiagnostic( + DbcDiagnosticSeverity.Warning, + "DBC006", + "Out of range.", + 12), + }; + + var cut = Render(p => p + .Add(x => x.DocumentKey, "DBC/a.dbc") + .Add(x => x.Diagnostics, diagnostics) + .Add(x => x.OnLocate, line => located = line)); + + cut.Find("[data-testid='dbc-problem-row']").Click(); + + Assert.Equal(12, located); + } +} diff --git a/tests/DbcView.Tests/DbcViewWorkspaceTests.cs b/tests/DbcView.Tests/DbcViewWorkspaceTests.cs index 7e56019..6314508 100644 --- a/tests/DbcView.Tests/DbcViewWorkspaceTests.cs +++ b/tests/DbcView.Tests/DbcViewWorkspaceTests.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Globalization; using DbcView.Web; using DbcView.Web.Components; @@ -269,7 +270,7 @@ public void Workspace_compact_panel_switcher_selects_reachable_panels() var cut = Render(); cut.WaitForAssertion( - () => Assert.Equal(3, cut.FindAll(".dbc-compact-nav button").Count)); + () => Assert.Equal(4, cut.FindAll(".dbc-compact-nav button").Count)); var shell = cut.Find("[data-testid='dbc-view-shell']"); Assert.Equal("editor", shell.GetAttribute("data-compact-active")); @@ -289,6 +290,154 @@ public void Workspace_compact_panel_switcher_selects_reachable_panels() Assert.Equal( "true", cut.Find("[data-testid='dbc-compact-properties']").GetAttribute("aria-pressed")); + + cut.Find("[data-testid='dbc-compact-problems']").Click(); + Assert.Equal( + "problems", + cut.Find("[data-testid='dbc-view-shell']").GetAttribute("data-compact-active")); + Assert.Equal( + "true", + cut.Find("[data-testid='dbc-compact-problems']").GetAttribute("aria-pressed")); + } + + [Fact] + public void Workspace_lists_dbc_warnings_in_the_problems_panel() + { + var cut = Render(); + cut.FindComponent().UploadFiles(InputFileContent.CreateFromText( + "VERSION \"\"\nBU_: XXX\n\nBO_ 100 M: 1 XXX\n" + + " SG_ TooWide : 7|2@0+ (1,0) [0|3] \"\" XXX\n", + "warning.dbc")); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-file']"))); + TreeTestHelpers.ClickFile(cut); + + cut.WaitForAssertion( + () => + { + Assert.Empty(cut.FindAll("[data-testid='dbc-parse-warnings']")); + Assert.Contains( + "1 warning", + cut.Find("[data-testid='dbc-status-warnings']").TextContent, + StringComparison.Ordinal); + + var row = cut.Find("[data-testid='dbc-problem-row']"); + Assert.Equal("warning", row.GetAttribute("data-severity")); + Assert.Equal( + "DBC006", + cut.Find("[data-testid='dbc-problem-code']").TextContent.Trim()); + Assert.Equal( + "5", + cut.Find("[data-testid='dbc-problem-line']").TextContent.Trim()); + Assert.Contains( + "spans bits", + cut.Find("[data-testid='dbc-problem-message']").TextContent, + StringComparison.Ordinal); + }); + } + + [Fact] + public void Workspace_auto_checks_unsaved_editor_text() + { + var cut = Render(); + cut.FindComponent() + .UploadFiles(InputFileContent.CreateFromText(ValidDbc, "check.dbc")); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-file']"))); + TreeTestHelpers.ClickFile(cut); + cut.WaitForAssertion(() => Assert.NotNull(cut.Find("[data-testid='dbc-table']"))); + + cut.Find("[data-testid='dbc-mode-text']").Click(); + cut.Find("textarea").Change(InvalidDbc); + + cut.WaitForAssertion( + () => + { + var problems = cut.Find("[data-testid='dbc-problems']").TextContent; + Assert.Contains("DBC001", problems, StringComparison.Ordinal); + Assert.Contains("DBC002", problems, StringComparison.Ordinal); + Assert.Contains( + "2 errors", + cut.Find("[data-testid='dbc-status-errors']").TextContent, + StringComparison.Ordinal); + }, + TimeSpan.FromSeconds(5)); + } + + [Fact] + public void Workspace_check_button_runs_manual_validation() + { + var cut = Render(); + cut.FindComponent().UploadFiles(InputFileContent.CreateFromText( + "VERSION \"\"\nBU_: XXX\n\nBO_ 100 M: 1 XXX\n" + + " SG_ TooWide : 7|2@0+ (1,0) [0|3] \"\" XXX\n", + "warning.dbc")); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-file']"))); + TreeTestHelpers.ClickFile(cut); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-problem-row']"))); + + cut.Find("[data-testid='dbc-check-document']").Click(); + + cut.WaitForAssertion( + () => Assert.Contains( + "Checked DBC/warning.dbc", + cut.Find("[data-testid='dbc-view-status-bar']").TextContent, + StringComparison.Ordinal)); + } + + [Fact] + public void Workspace_status_diagnostics_open_the_problems_panel() + { + var cut = Render(); + cut.FindComponent().UploadFiles(InputFileContent.CreateFromText( + "VERSION \"\"\nBU_: XXX\n\nBO_ 100 M: 1 XXX\n" + + " SG_ TooWide : 7|2@0+ (1,0) [0|3] \"\" XXX\n", + "warning.dbc")); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-file']"))); + TreeTestHelpers.ClickFile(cut); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-status-warnings']"))); + + cut.Find("[data-testid='dbc-status-warnings']").Click(); + + cut.WaitForAssertion( + () => Assert.Equal( + "problems", + cut.Find("[data-testid='dbc-view-shell']").GetAttribute("data-compact-active"))); + } + + [Fact] + public void Workspace_palette_runs_the_check_command() + { + var cut = Render(); + cut.FindComponent().UploadFiles(InputFileContent.CreateFromText( + "VERSION \"\"\nBU_: XXX\n\nBO_ 100 M: 1 XXX\n" + + " SG_ TooWide : 7|2@0+ (1,0) [0|3] \"\" XXX\n", + "warning.dbc")); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-file']"))); + TreeTestHelpers.ClickFile(cut); + cut.WaitForAssertion( + () => Assert.Single(cut.FindAll("[data-testid='dbc-problem-row']"))); + + cut.Find("[data-testid='dbc-open-palette']").Click(); + cut.WaitForAssertion( + () => Assert.NotNull(cut.Find("[data-testid='dbc-palette-input']"))); + cut.Find("[data-testid='dbc-palette-input']").Input("check"); + + var command = cut.Find("[data-testid='dbc-palette-command']"); + Assert.Equal("check-document", command.GetAttribute("data-command-id")); + command.Click(); + + cut.WaitForAssertion( + () => Assert.Contains( + "Checked DBC/warning.dbc", + cut.Find("[data-testid='dbc-view-status-bar']").TextContent, + StringComparison.Ordinal)); + Assert.Empty(cut.FindAll("[data-testid='dbc-command-palette']")); } [Fact] @@ -651,11 +800,11 @@ public void Empty_slots_keep_toolbar_regions_without_panels() cut.WaitForAssertion( () => { - // The four empty tool groups still own their LogicalRegion slot. - Assert.Equal(4, cut.FindAll("[data-atlas-region-empty='true']").Count); + // The three empty tool groups still own their LogicalRegion slot. + Assert.Equal(3, cut.FindAll("[data-atlas-region-empty='true']").Count); // Their panels are collapsed: hidden with no content extent. - Assert.Equal(4, cut.FindAll(".atlas-v2-group-collapsed").Count); - Assert.Equal(4, cut.FindAll(".atlas-v2-group-collapsed .atlas-v2-empty-state").Count); + Assert.Equal(3, cut.FindAll(".atlas-v2-group-collapsed").Count); + Assert.Equal(3, cut.FindAll(".atlas-v2-group-collapsed .atlas-v2-empty-state").Count); }); } @@ -672,13 +821,13 @@ public void Workspace_exposes_named_aria_relationships() .ToArray(); Assert.Equal(7, groups.Length); - // Content-bearing groups (explorer, editor, properties) expose - // a named header; empty groups intentionally render no header. + // Content-bearing groups (explorer, editor, properties, problems) + // expose a named header; empty groups intentionally render no header. var contentGroups = groups .Where(group => !string.IsNullOrWhiteSpace(group.GetAttribute("aria-labelledby"))) .ToArray(); - Assert.Equal(3, contentGroups.Length); - Assert.Equal(4, groups.Length - contentGroups.Length); + Assert.Equal(4, contentGroups.Length); + Assert.Equal(3, groups.Length - contentGroups.Length); var documentTabList = cut.Find("[data-atlas-group-kind='document'] [role='tablist']"); Assert.False(string.IsNullOrWhiteSpace(documentTabList.GetAttribute("aria-label"))); @@ -726,8 +875,8 @@ public void Workspace_exposes_all_supported_interaction_sources() cut.WaitForAssertion( () => { - Assert.Equal(2, cut.FindAll("[data-atlas-panel-header='true'][data-atlas-drag-kind='panel-header']").Count); - Assert.Equal(2, cut.FindAll("[data-atlas-toolbar-entry='true'][data-atlas-drag-kind='toolbar-entry']").Count); + Assert.Equal(3, cut.FindAll("[data-atlas-panel-header='true'][data-atlas-drag-kind='panel-header']").Count); + Assert.Equal(3, cut.FindAll("[data-atlas-toolbar-entry='true'][data-atlas-drag-kind='toolbar-entry']").Count); Assert.Equal(6, cut.FindAll("[role='separator'][data-atlas-split-id]").Count); Assert.All( cut.FindAll("[role='separator'][data-atlas-split-id]"), diff --git a/tests/DbcView.Tests/UiChromeTests.cs b/tests/DbcView.Tests/UiChromeTests.cs index 6d9e1bf..5a60012 100644 --- a/tests/DbcView.Tests/UiChromeTests.cs +++ b/tests/DbcView.Tests/UiChromeTests.cs @@ -105,7 +105,10 @@ public void Status_bar_renders_only_real_derived_state() .Add(component => component.WarningCount, 1)); var status = cut.Find("footer"); - Assert.Equal("status", status.GetAttribute("role")); + Assert.Null(status.GetAttribute("role")); + var message = cut.Find(".dbc-statusbar-message"); + Assert.Equal("status", message.GetAttribute("role")); + Assert.Equal("polite", message.GetAttribute("aria-live")); Assert.Contains("Opened DBC/engine.dbc", status.TextContent, StringComparison.Ordinal); Assert.Contains("2 errors", cut.Find("[data-testid='dbc-status-errors']").TextContent, StringComparison.Ordinal); Assert.Contains("1 warning", cut.Find("[data-testid='dbc-status-warnings']").TextContent, StringComparison.Ordinal); @@ -137,6 +140,21 @@ public void Status_bar_omits_items_that_are_not_real_state() } } + [Fact] + public void Status_bar_diagnostics_raise_the_problems_callback() + { + var selected = 0; + var cut = Render(parameters => parameters + .Add(component => component.ErrorCount, 2) + .Add(component => component.WarningCount, 1) + .Add(component => component.OnProblemsSelected, () => selected++)); + + cut.Find("[data-testid='dbc-status-errors']").Click(); + cut.Find("[data-testid='dbc-status-warnings']").Click(); + + Assert.Equal(2, selected); + } + [Fact] public void Status_bar_uses_singular_labels_for_single_diagnostics() {