diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 6d1b2b2c..cfc25ef5 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -427,8 +427,11 @@ Pages, routes and what each page shows or triggers are specified in
fairly wide surface (one method per page/section).
- **`Components\Common`** holds cross-page building blocks: loading
skeletons and the vulnerability widgets shared between the
- Vulnerabilities page and image/container detail pages, and the
- `ContainerActionConfirmation` dialog.
+ Vulnerabilities page and image/container detail pages, the
+ `ContainerActionConfirmation` dialog, and the status chip, scan status
+ indicator, severity bar, page header and section panel, which take their
+ tone from `UI\StatusToneFormatter`
+ ([decision 0079](decisions/0079-statuses-map-to-tones-in-one-mapping-beside-the-chip-colors-of-unconverted-pages.md)).
- **`IContainerActionService` (`Portainer\ContainerActionService`)** backs
the *Container actions* section of `RuntimeContainerDetail`. It is a
singleton that opens its own `IServiceScopeFactory` scope for every
diff --git a/docs/areas/web-ui.md b/docs/areas/web-ui.md
index 6605f700..a878e6be 100644
--- a/docs/areas/web-ui.md
+++ b/docs/areas/web-ui.md
@@ -52,6 +52,24 @@ to read the state the other areas compute and to start manual scans; it computes
availability answer that arrives for an earlier route. A re-render with the same route identifier keeps the shown
record until its reload completes.
+### Shared display
+
+- The shared components show a status as a chip in the tone of its text, compared ignoring letter case: green for
+ `Succeeded`, `Up to date` and `No findings`; orange for `Partial`, `Update available`, `Paused` and `Restarting`;
+ red for `Failed`; blue for `Running` and `Manual review required`; every other text, an unknown, empty or missing
+ one included, is neutral. A status chip takes its colors from the theme's chip color pairs; the scan status
+ indicator shows a dot in the tone's color beside the status text, which alone carries the meaning.
+- The status of a vulnerability assessment, `Findings detected`, takes the tone of its highest severity with at least
+ one finding (critical, high, medium or low); without a counted known severity it is low. Any other status ignores
+ the severities, so `Failed` stays red. A severity chip uses the tone of its own severity; an unknown one is low.
+- The severity bar shows the active findings as segments in the order critical, high, medium, low, each as wide as
+ its count and at least 4 px; findings of an unknown severity count as low. A legend lists the counts and the bar
+ is announced as `Severity distribution: ...`. Without findings nothing is shown.
+- Tables use a sentence-case head with hairlines, hairline rows, tabular figures and a subtle hovered row. Below 960
+ px each row is a bordered card with the large radius.
+- Buttons are not uppercase. Primary and secondary buttons and the fields are at least 44 px high; error and
+ disabled buttons keep MudBlazor's look. The per-image rescan button is announced as `Rescan vulnerabilities`.
+
### Pages and routes
| Route | Page | Shows |
@@ -88,7 +106,7 @@ to read the state the other areas compute and to start manual scans; it computes
| Register and scan | Observed Images | Registers an image from name (trimmed), image reference and optional description ([Image catalog](image-catalog.md)), scans it immediately as a manual observed-image scan and opens its detail page; a reference already tracked as an enabled own image is rejected with an `Open own image` link to that image and starts no scan |
| Check image updates | Runtime Containers | Runs a manual runtime container scan of all enabled Docker instances |
| Refresh vulnerabilities | Scan History, shown only when vulnerability scanning is enabled | Runs a manual vulnerability refresh of all live images; the page also shows when the next scheduled refresh is expected |
-| Rescan (per image) | Observed Images, My Images, Runtime Containers | Runs a manual vulnerability refresh of that one image version; next to it the time of the last check or "Never scanned" |
+| Rescan (per image) | Observed Images, My Images, Runtime Containers | Runs a manual vulnerability refresh of that one image version; next to it the time of the last check or "Never scanned"; the button is announced as `Rescan vulnerabilities` |
| Select / Clear selection | Runtime Container detail | Stores or removes a manual tag preference for that container ([Update detection](update-detection.md)); it does not change or redeploy the container |
| Start / Stop / Restart | Runtime Container detail, *Container actions* section | Starts, stops or restarts that container through Portainer after a confirmation, and records the action as an action run ([Container actions](container-actions.md)) |
@@ -178,8 +196,9 @@ never their values.
the drawer and filled buttons), and no lift, scaling or shadow when a card, link or button is hovered or pressed.
Menus, popovers (tooltips excepted) and dialogs are separated from the content by a hairline border; dialogs and snackbars also keep the drop shadow MudBlazor's own stylesheet gives them.
- In the dark theme the dark values apply to the whole document, so menus, popovers and dialogs are dark too.
-- Text and status labels keep a contrast of at least 4.5:1 against their background in both themes; filled status
- chips and buttons of the dark theme draw their label in the dark page color.
+- Text and status labels keep a contrast of at least 4.5:1 against their background in both themes; filled
+ buttons and MudBlazor status chips of the dark theme draw their label in the dark page color; the shared
+ status chips take theirs from the tone's chip color pair.
- Text is set in Inter; page titles, entity names, the figures of the dashboard's metric cards and the product name
are set in Space Grotesk. Both fonts and the styles are served by the application itself; the browser loads
nothing from another host for them, and until a font has loaded the text shows in a fallback font.
@@ -273,6 +292,9 @@ never their values.
- [0078](../decisions/0078-mudblazor-elevation-shadows-are-switched-off-in-the-theme.md) — MudBlazor elevation
shadows are switched off in the theme.
+- [0079](../decisions/0079-statuses-map-to-tones-in-one-mapping-beside-the-chip-colors-of-unconverted-pages.md) — Statuses
+ map to tones in one mapping, beside the chip colors of unconverted pages.
+
## Not here
- How update states, recommended tags, tag candidates and manual tag preferences are evaluated in
diff --git a/docs/decisions/0079-statuses-map-to-tones-in-one-mapping-beside-the-chip-colors-of-unconverted-pages.md b/docs/decisions/0079-statuses-map-to-tones-in-one-mapping-beside-the-chip-colors-of-unconverted-pages.md
new file mode 100644
index 00000000..409b1516
--- /dev/null
+++ b/docs/decisions/0079-statuses-map-to-tones-in-one-mapping-beside-the-chip-colors-of-unconverted-pages.md
@@ -0,0 +1,39 @@
+# 0079: Statuses map to tones in one mapping, beside the chip colors of unconverted pages
+
+- **Status:** Accepted
+- **Date:** 2026-11-28
+- **Area:** Web UI
+- **Source:** Issue #452
+- **Supersedes:** —
+
+## Context
+
+The flat refresh (#450) colors statuses from the design tokens of #451 through plain elements, not MudBlazor chips.
+Today scan statuses get a MudBlazor `Color` from `UI/ScanStatusDisplayFormatter.cs`, vulnerability statuses and
+severities from `UI/VulnerabilityDisplayFormatter.cs`, update states from two private copies in the runtime container
+pages, and every runtime status is a fixed info chip. Issue #452 builds the shared components but converts no page:
+the pages keep binding MudBlazor colors until their own sub-issues.
+
+## Options considered
+
+1. **A new tone type and one tone mapping in `UI/`, next to the existing formatters, which stay until no page uses
+ them (chosen)** — the components get one mapping for every status kind and severity; the pages and their tests stay
+ untouched. Two mappings live side by side until the page sub-issues remove the old ones.
+2. **Rename `VulnerabilityDisplayFormatter` and make it return tones** — one formatter at once, but every page that
+ binds its MudBlazor colors (four list pages, three detail pages, the Vulnerabilities page) would have to change
+ now, which the issue rules out.
+3. **Let each formatter return a tone besides its color** — no new type of mapping, but the mapping of one status
+ would stay spread over three classes plus the page copies, which is what #452 removes.
+
+## Decision
+
+Statuses and severities map to a `StatusTone` in `UI/StatusToneFormatter.cs`, the only mapping the shared components
+use; `ScanStatusDisplayFormatter` and `VulnerabilityDisplayFormatter` stay unchanged for the pages that have not
+adopted the components. The tones of each value are stated in [Web UI](../areas/web-ui.md).
+
+## Consequences
+
+Until the last page sub-issue of #450, a scan status can be colored by both mappings, and they differ for `Pending`
+(orange in the old one, neutral in the new one; the application never stores it) and for update states and
+vulnerability statuses the old mappings default to blue. Each page sub-issue removes the page's private mappings, and
+the last one deletes the two old formatters with their tests.
diff --git a/docs/decisions/README.md b/docs/decisions/README.md
index c3479c23..c30ec413 100644
--- a/docs/decisions/README.md
+++ b/docs/decisions/README.md
@@ -139,4 +139,5 @@ once in the [area document](../areas/README.md) of the record's area, and the re
| [0076](0076-the-dotnet-release-index-is-parsed-as-a-remote-json-object-and-an-entry-that-is-not-one-is-left-out.md) | The .NET release index is parsed as a remote JSON object, and an entry that is not one is left out | Accepted | 2026-11-28 |
| [0077](0077-the-dark-theme-tokens-apply-to-the-whole-document-while-the-layout-is-dark.md) | The dark theme's tokens apply to the whole document while the layout is dark | Accepted | 2026-11-28 |
| [0078](0078-mudblazor-elevation-shadows-are-switched-off-in-the-theme.md) | MudBlazor elevation shadows are switched off in the theme | Accepted | 2026-11-28 |
+| [0079](0079-statuses-map-to-tones-in-one-mapping-beside-the-chip-colors-of-unconverted-pages.md) | Statuses map to tones in one mapping, beside the chip colors of unconverted pages | Accepted | 2026-11-28 |
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/PageHeader.razor b/src/DockerUpdateGuard/Components/Common/PageHeader.razor
new file mode 100644
index 00000000..94ba293d
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/PageHeader.razor
@@ -0,0 +1,22 @@
+
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/PageHeader.razor.cs b/src/DockerUpdateGuard/Components/Common/PageHeader.razor.cs
new file mode 100644
index 00000000..bd46648f
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/PageHeader.razor.cs
@@ -0,0 +1,44 @@
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Components.Common;
+
+///
+/// Page header with title, description, breadcrumb and actions
+///
+public partial class PageHeader
+{
+ #region Properties
+
+ ///
+ /// Page title
+ ///
+ [Parameter]
+ [EditorRequired]
+ public string Title { get; set; } = string.Empty;
+
+ ///
+ /// Description below the title
+ ///
+ [Parameter]
+ public string? Description { get; set; }
+
+ ///
+ /// Actions shown beside the title
+ ///
+ [Parameter]
+ public RenderFragment? Actions { get; set; }
+
+ ///
+ /// Breadcrumb shown above the title
+ ///
+ [Parameter]
+ public RenderFragment? Breadcrumb { get; set; }
+
+ ///
+ /// Content shown next to the title in the title row
+ ///
+ [Parameter]
+ public RenderFragment? TitleContent { get; set; }
+
+ #endregion // Properties
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor b/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor
index 473133dc..7cdac9cc 100644
--- a/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor
+++ b/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor
@@ -1,7 +1,10 @@
-
-
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor.cs b/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor.cs
index 741014a1..6caaa23b 100644
--- a/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor.cs
+++ b/src/DockerUpdateGuard/Components/Common/PageHeaderSkeleton.razor.cs
@@ -1,6 +1,6 @@
namespace DockerUpdateGuard.Components.Common;
///
-/// Skeleton placeholder that mirrors the hero page header while data is loading
+/// Skeleton placeholder that mirrors the page header while data is loading
///
public sealed partial class PageHeaderSkeleton;
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/ScanStatusIndicator.razor b/src/DockerUpdateGuard/Components/Common/ScanStatusIndicator.razor
new file mode 100644
index 00000000..e7c7b938
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/ScanStatusIndicator.razor
@@ -0,0 +1 @@
+@Status
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/ScanStatusIndicator.razor.cs b/src/DockerUpdateGuard/Components/Common/ScanStatusIndicator.razor.cs
new file mode 100644
index 00000000..dafb2bb4
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/ScanStatusIndicator.razor.cs
@@ -0,0 +1,26 @@
+using DockerUpdateGuard.UI;
+
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Components.Common;
+
+///
+/// Status dot with text for a scan status
+///
+public partial class ScanStatusIndicator
+{
+ #region Properties
+
+ ///
+ /// Scan status text
+ ///
+ [Parameter]
+ public string? Status { get; set; }
+
+ ///
+ /// CSS classes of the indicator
+ ///
+ private string CssClass => $"dug-status dug-status--{StatusToneFormatter.GetCssName(StatusToneFormatter.GetStatusTone(Status))}";
+
+ #endregion // Properties
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/SectionPanel.razor b/src/DockerUpdateGuard/Components/Common/SectionPanel.razor
new file mode 100644
index 00000000..5ed3b465
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/SectionPanel.razor
@@ -0,0 +1,14 @@
+
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/SectionPanel.razor.cs b/src/DockerUpdateGuard/Components/Common/SectionPanel.razor.cs
new file mode 100644
index 00000000..ba274c2d
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/SectionPanel.razor.cs
@@ -0,0 +1,49 @@
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Components.Common;
+
+///
+/// Panel with a titled header and a body
+///
+public partial class SectionPanel
+{
+ #region Properties
+
+ ///
+ /// Panel title
+ ///
+ [Parameter]
+ [EditorRequired]
+ public string Title { get; set; } = string.Empty;
+
+ ///
+ /// Meta text beside the title
+ ///
+ [Parameter]
+ public string? Meta { get; set; }
+
+ ///
+ /// Header content shown instead of the meta text
+ ///
+ [Parameter]
+ public RenderFragment? HeaderContent { get; set; }
+
+ ///
+ /// Panel body
+ ///
+ [Parameter]
+ public RenderFragment? ChildContent { get; set; }
+
+ ///
+ /// Indicates whether the body has no padding
+ ///
+ [Parameter]
+ public bool Flush { get; set; }
+
+ ///
+ /// CSS classes of the panel
+ ///
+ private string CssClass => Flush ? "dug-panel dug-panel--flush" : "dug-panel";
+
+ #endregion // Properties
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/SeverityBar.razor b/src/DockerUpdateGuard/Components/Common/SeverityBar.razor
new file mode 100644
index 00000000..aa49ce4e
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/SeverityBar.razor
@@ -0,0 +1,17 @@
+@if (Segments.Count > 0)
+{
+
+
+ @foreach (var segment in Segments)
+ {
+
+ }
+
+
+ @foreach (var segment in Segments)
+ {
+ @segment.Count @segment.Name
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/SeverityBar.razor.cs b/src/DockerUpdateGuard/Components/Common/SeverityBar.razor.cs
new file mode 100644
index 00000000..c5f01414
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/SeverityBar.razor.cs
@@ -0,0 +1,67 @@
+using DockerUpdateGuard.UI;
+
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Components.Common;
+
+///
+/// Weighted bar of the active findings by severity
+///
+public partial class SeverityBar
+{
+ #region Properties
+
+ ///
+ /// Severity summary to show
+ ///
+ [Parameter]
+ public VulnerabilitySeveritySummaryViewData? Summary { get; set; }
+
+ ///
+ /// Segments of the severities with at least one finding, in the order critical, high, medium, low
+ ///
+ private List<(string Name, int Count)> Segments
+ {
+ get
+ {
+ var segments = new List<(string Name, int Count)>();
+
+ if (Summary is null)
+ {
+ return segments;
+ }
+
+ AddSegment(segments, "critical", Summary.CriticalCount);
+ AddSegment(segments, "high", Summary.HighCount);
+ AddSegment(segments, "medium", Summary.MediumCount);
+ AddSegment(segments, "low", Summary.LowCount + Summary.OtherCount);
+
+ return segments;
+ }
+ }
+
+ ///
+ /// Spoken label of the severity distribution
+ ///
+ private string Label => $"Severity distribution: {string.Join(", ", Segments.Select(segment => $"{segment.Count} {segment.Name}"))}";
+
+ #endregion // Properties
+
+ #region Static methods
+
+ ///
+ /// Add a segment when its count is above zero
+ ///
+ /// Segments
+ /// Severity name
+ /// Number of findings
+ private static void AddSegment(List<(string Name, int Count)> segments, string name, int count)
+ {
+ if (count > 0)
+ {
+ segments.Add((name, count));
+ }
+ }
+
+ #endregion // Static methods
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/StatusChip.razor b/src/DockerUpdateGuard/Components/Common/StatusChip.razor
new file mode 100644
index 00000000..a9c7db00
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/StatusChip.razor
@@ -0,0 +1 @@
+@Text
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/StatusChip.razor.cs b/src/DockerUpdateGuard/Components/Common/StatusChip.razor.cs
new file mode 100644
index 00000000..b22bd70a
--- /dev/null
+++ b/src/DockerUpdateGuard/Components/Common/StatusChip.razor.cs
@@ -0,0 +1,32 @@
+using DockerUpdateGuard.UI;
+
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Components.Common;
+
+///
+/// Colored chip showing a status text in a tone
+///
+public partial class StatusChip
+{
+ #region Properties
+
+ ///
+ /// Chip text
+ ///
+ [Parameter]
+ public string? Text { get; set; }
+
+ ///
+ /// Tone of the chip
+ ///
+ [Parameter]
+ public StatusTone Tone { get; set; }
+
+ ///
+ /// CSS classes of the chip
+ ///
+ private string CssClass => $"dug-chip dug-chip--{StatusToneFormatter.GetCssName(Tone)}";
+
+ #endregion // Properties
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor b/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor
index d172ce3b..b3d17940 100644
--- a/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor
+++ b/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor
@@ -1,9 +1,6 @@
@{
- RenderFragment placeholders =@
- @if (Title is not null)
- {
-
- }
+ RenderFragment titlePlaceholder =@ ;
+ RenderFragment rowPlaceholders =@
@for (var index = 0; index < Rows; index++)
{
@@ -12,11 +9,23 @@
}
@if (Embedded)
{
- @placeholders
+ @if (Title is not null)
+ {
+ @titlePlaceholder
+ }
+ @rowPlaceholders
}
else
{
-
- @placeholders
-
+
+ @if (Title is not null)
+ {
+
+ }
+
+ @rowPlaceholders
+
+
}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor.cs b/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor.cs
index 59b972c1..2e33fbc5 100644
--- a/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor.cs
+++ b/src/DockerUpdateGuard/Components/Common/TableSkeleton.razor.cs
@@ -22,7 +22,7 @@ public sealed partial class TableSkeleton
public string? Title { get; set; }
///
- /// When true, the placeholder rows are rendered without the surrounding section paper, for embedding inside an existing panel
+ /// When true, the placeholder rows are rendered without the surrounding panel, for embedding inside an existing panel
///
[Parameter]
public bool Embedded { get; set; }
diff --git a/src/DockerUpdateGuard/Components/Common/VulnerabilityAssessmentCard.razor b/src/DockerUpdateGuard/Components/Common/VulnerabilityAssessmentCard.razor
index 7e5bde80..75022636 100644
--- a/src/DockerUpdateGuard/Components/Common/VulnerabilityAssessmentCard.razor
+++ b/src/DockerUpdateGuard/Components/Common/VulnerabilityAssessmentCard.razor
@@ -6,7 +6,7 @@
{
@RemediationSummary
}
- @Assessment.Status
+
@if (HasCollapsibleDetail)
{
@@ -20,11 +20,11 @@
@if (Assessment.NewFindingCount > 0)
{
- @($"+{Assessment.NewFindingCount} since last scan")
+
}
@if (Assessment.ResolvedFindingCount > 0)
{
- @($"−{Assessment.ResolvedFindingCount} fixed since last scan")
+
}
}
diff --git a/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor b/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor
index 14521d3a..e12a712b 100644
--- a/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor
+++ b/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor
@@ -15,7 +15,9 @@ else
Placeholder="Filter by advisory, package, or title"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
- Clearable="true" />
+ Clearable="true"
+ Variant="Variant.Outlined"
+ Margin="Margin.Dense" />
@if (HasResolvedFindings)
{
@@ -46,7 +48,7 @@ else
}
@if (context.IsNewSinceLastScan)
{
- New
+
}
@if (string.IsNullOrWhiteSpace(context.Title) == false)
{
@@ -54,7 +56,7 @@ else
}
- @context.Severity
+
@if (context.CvssScore.HasValue)
{
CVSS @context.CvssScore.Value.ToString("F1")
@@ -70,9 +72,7 @@ else
@(context.FixedVersion ?? "—")
@TimestampFormatter.Format(context.DetectedAtUtc)
-
- @(context.IsActive ? "Active" : "Resolved")
-
+
@if (context.ResolvedAtUtc is DateTimeOffset resolvedAtUtc)
{
@TimestampFormatter.Format(resolvedAtUtc)
diff --git a/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor.cs b/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor.cs
index 971c5a18..8427c901 100644
--- a/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor.cs
+++ b/src/DockerUpdateGuard/Components/Common/VulnerabilityFindingsTable.razor.cs
@@ -50,20 +50,6 @@ public partial class VulnerabilityFindingsTable
#endregion // Properties
- #region Static methods
-
- ///
- /// Resolve the chip color for a vulnerability severity label
- ///
- /// Severity label
- /// Chip color
- private static Color GetSeverityColor(string severity)
- {
- return VulnerabilityDisplayFormatter.GetSeverityColor(severity);
- }
-
- #endregion // Static methods
-
#region Methods
///
diff --git a/src/DockerUpdateGuard/Components/Common/VulnerabilityRescanControl.razor b/src/DockerUpdateGuard/Components/Common/VulnerabilityRescanControl.razor
index 9f38059f..54e4296e 100644
--- a/src/DockerUpdateGuard/Components/Common/VulnerabilityRescanControl.razor
+++ b/src/DockerUpdateGuard/Components/Common/VulnerabilityRescanControl.razor
@@ -2,7 +2,8 @@
@(CheckedAtUtc is DateTimeOffset checkedAtUtc ? $"Checked {TimestampFormatter.Format(checkedAtUtc)}" : "Never scanned")
diff --git a/src/DockerUpdateGuard/Components/Common/VulnerabilitySeverityChips.razor b/src/DockerUpdateGuard/Components/Common/VulnerabilitySeverityChips.razor
index 3e0d3174..c4c864fb 100644
--- a/src/DockerUpdateGuard/Components/Common/VulnerabilitySeverityChips.razor
+++ b/src/DockerUpdateGuard/Components/Common/VulnerabilitySeverityChips.razor
@@ -2,29 +2,29 @@
{
@if (Summary.CriticalCount > 0)
{
- @($"{Summary.CriticalCount} Critical")
+
}
@if (Summary.HighCount > 0)
{
- @($"{Summary.HighCount} High")
+
}
@if (Compact == false)
{
@if (Summary.MediumCount > 0)
{
- @($"{Summary.MediumCount} Medium")
+
}
@if (Summary.LowCount > 0)
{
- @($"{Summary.LowCount} Low")
+
}
@if (Summary.OtherCount > 0)
{
- @($"{Summary.OtherCount} Unknown")
+
}
}
else if (FoldedCount > 0)
{
- @($"+{FoldedCount} more")
+
}
}
diff --git a/src/DockerUpdateGuard/UI/StatusTone.cs b/src/DockerUpdateGuard/UI/StatusTone.cs
new file mode 100644
index 00000000..72f1534e
--- /dev/null
+++ b/src/DockerUpdateGuard/UI/StatusTone.cs
@@ -0,0 +1,52 @@
+namespace DockerUpdateGuard.UI;
+
+///
+/// Color tone of a status chip, status indicator or severity segment
+///
+public enum StatusTone
+{
+ ///
+ /// Neutral tone for unknown or informational-less values
+ ///
+ Neutral = 0,
+
+ ///
+ /// Informational tone
+ ///
+ Info,
+
+ ///
+ /// Success tone
+ ///
+ Success,
+
+ ///
+ /// Warning tone
+ ///
+ Warning,
+
+ ///
+ /// Danger tone for failures
+ ///
+ Danger,
+
+ ///
+ /// Critical vulnerability severity tone
+ ///
+ Critical,
+
+ ///
+ /// High vulnerability severity tone
+ ///
+ High,
+
+ ///
+ /// Medium vulnerability severity tone
+ ///
+ Medium,
+
+ ///
+ /// Low vulnerability severity tone
+ ///
+ Low
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/UI/StatusToneFormatter.cs b/src/DockerUpdateGuard/UI/StatusToneFormatter.cs
new file mode 100644
index 00000000..d048b594
--- /dev/null
+++ b/src/DockerUpdateGuard/UI/StatusToneFormatter.cs
@@ -0,0 +1,159 @@
+namespace DockerUpdateGuard.UI;
+
+///
+/// Maps status texts and vulnerability severities to the tone of their chip
+///
+internal static class StatusToneFormatter
+{
+ #region Constants
+
+ ///
+ /// Status text of detected findings, whose tone follows the severity summary
+ ///
+ private const string FindingsDetected = "Findings detected";
+
+ #endregion // Constants
+
+ #region Fields
+
+ ///
+ /// Tone per status text, compared case-insensitively
+ ///
+ private static readonly Dictionary _statusTones = new(StringComparer.OrdinalIgnoreCase)
+ {
+ ["Succeeded"] = StatusTone.Success,
+ ["Partial"] = StatusTone.Warning,
+ ["Failed"] = StatusTone.Danger,
+ ["Running"] = StatusTone.Info,
+ ["Pending"] = StatusTone.Neutral,
+ ["NotSet"] = StatusTone.Neutral,
+ ["NotScanned"] = StatusTone.Neutral,
+ ["Update available"] = StatusTone.Warning,
+ ["Up to date"] = StatusTone.Success,
+ ["Manual review required"] = StatusTone.Info,
+ ["No tag data"] = StatusTone.Neutral,
+ ["Not evaluated"] = StatusTone.Neutral,
+ ["Unsupported"] = StatusTone.Neutral,
+ ["No findings"] = StatusTone.Success,
+ ["Not scanned"] = StatusTone.Neutral,
+ ["Not configured"] = StatusTone.Neutral,
+ ["Unavailable"] = StatusTone.Neutral,
+ ["Paused"] = StatusTone.Warning,
+ ["Restarting"] = StatusTone.Warning,
+ ["Exited"] = StatusTone.Neutral,
+ ["Dead"] = StatusTone.Neutral,
+ };
+
+ #endregion // Fields
+
+ #region Static methods
+
+ ///
+ /// Resolve the tone for a status text
+ ///
+ /// Status text
+ /// Tone
+ public static StatusTone GetStatusTone(string? status)
+ {
+ return GetStatusTone(status, null);
+ }
+
+ ///
+ /// Resolve the tone for a status text, using the severity summary for detected findings
+ ///
+ /// Status text
+ /// Severity summary of the findings
+ /// Tone
+ public static StatusTone GetStatusTone(string? status, VulnerabilitySeveritySummaryViewData? severitySummary)
+ {
+ if (string.IsNullOrWhiteSpace(status))
+ {
+ return StatusTone.Neutral;
+ }
+
+ if (string.Equals(status, FindingsDetected, StringComparison.OrdinalIgnoreCase))
+ {
+ return GetHighestSeverityTone(severitySummary);
+ }
+
+ return _statusTones.GetValueOrDefault(status, StatusTone.Neutral);
+ }
+
+ ///
+ /// Resolve the tone for a vulnerability severity
+ ///
+ /// Severity text
+ /// Tone
+ public static StatusTone GetSeverityTone(string? severity)
+ {
+ if (string.Equals(severity, "Critical", StringComparison.OrdinalIgnoreCase))
+ {
+ return StatusTone.Critical;
+ }
+
+ if (string.Equals(severity, "High", StringComparison.OrdinalIgnoreCase))
+ {
+ return StatusTone.High;
+ }
+
+ if (string.Equals(severity, "Medium", StringComparison.OrdinalIgnoreCase))
+ {
+ return StatusTone.Medium;
+ }
+
+ return StatusTone.Low;
+ }
+
+ ///
+ /// Resolve the lowercase CSS name of a tone
+ ///
+ /// Tone
+ /// CSS name
+ public static string GetCssName(StatusTone tone)
+ {
+ return tone switch
+ {
+ StatusTone.Info => "info",
+ StatusTone.Success => "success",
+ StatusTone.Warning => "warning",
+ StatusTone.Danger => "danger",
+ StatusTone.Critical => "critical",
+ StatusTone.High => "high",
+ StatusTone.Medium => "medium",
+ StatusTone.Low => "low",
+ _ => "neutral",
+ };
+ }
+
+ ///
+ /// Resolve the tone of the highest severity with a count above zero
+ ///
+ /// Severity summary of the findings
+ /// Tone, low when no known severity is counted
+ private static StatusTone GetHighestSeverityTone(VulnerabilitySeveritySummaryViewData? severitySummary)
+ {
+ if (severitySummary is null)
+ {
+ return StatusTone.Low;
+ }
+
+ if (severitySummary.CriticalCount > 0)
+ {
+ return StatusTone.Critical;
+ }
+
+ if (severitySummary.HighCount > 0)
+ {
+ return StatusTone.High;
+ }
+
+ if (severitySummary.MediumCount > 0)
+ {
+ return StatusTone.Medium;
+ }
+
+ return StatusTone.Low;
+ }
+
+ #endregion // Static methods
+}
\ No newline at end of file
diff --git a/src/DockerUpdateGuard/wwwroot/app.css b/src/DockerUpdateGuard/wwwroot/app.css
index 712169ae..39d78656 100644
--- a/src/DockerUpdateGuard/wwwroot/app.css
+++ b/src/DockerUpdateGuard/wwwroot/app.css
@@ -595,8 +595,8 @@ a {
.table-secondary {
display: block;
margin-top: 0.15rem;
- color: var(--dug-text-faint);
- font-size: 0.82rem;
+ color: var(--dug-text-muted);
+ font-size: 13px;
}
.vulnerability-rescan-control {
@@ -611,38 +611,393 @@ a {
margin-top: 0;
}
+.section-table {
+ font-variant-numeric: tabular-nums;
+}
+
.section-table .mud-table-container {
- border-radius: var(--dug-radius-md);
+ border-radius: var(--dug-radius-lg);
border: 1px solid var(--dug-border);
background: var(--dug-surface);
}
+.dug-panel--flush .section-table .mud-table-container {
+ border: none;
+ border-radius: 0;
+ background: transparent;
+}
+
.section-table .mud-table-head .mud-table-cell {
color: var(--dug-text-muted);
+ border-top: 1px solid var(--dug-border);
border-bottom: 1px solid var(--dug-border);
- font-size: 0.8rem;
- font-weight: 700;
- letter-spacing: 0.05em;
- text-transform: uppercase;
+ font-size: 13px;
+ font-weight: 500;
+ letter-spacing: normal;
+ text-transform: none;
}
.section-table .mud-table-body .mud-table-cell {
color: var(--dug-text);
- padding-top: 0.95rem;
- padding-bottom: 0.95rem;
+ padding: 12px 16px;
+ border-bottom: 1px solid var(--dug-border-inner);
vertical-align: top;
}
.section-table .mud-table-head .mud-table-cell,
.section-table .mud-table-footer .mud-table-cell {
- padding-top: 0.95rem;
- padding-bottom: 0.95rem;
+ padding: 12px 16px;
+}
+
+.section-table .mud-table-body .mud-table-row:hover,
+.section-table .mud-table-body .mud-table-row:hover .mud-table-cell {
+ background: var(--dug-surface-subtle);
}
.section-table .mud-chip {
font-weight: 600;
}
+.dug-chip {
+ display: inline-flex;
+ align-items: center;
+ padding: 1px 8px;
+ border-radius: var(--dug-radius-sm);
+ font-size: 12px;
+ font-weight: 600;
+ line-height: 1.5;
+ white-space: nowrap;
+}
+
+.dug-chip--neutral {
+ background: var(--dug-chip-low-bg);
+ color: var(--dug-chip-low-fg);
+}
+
+.dug-chip--info {
+ background: var(--dug-chip-info-bg);
+ color: var(--dug-chip-info-fg);
+}
+
+.dug-chip--success {
+ background: var(--dug-chip-success-bg);
+ color: var(--dug-chip-success-fg);
+}
+
+.dug-chip--warning {
+ background: var(--dug-chip-high-bg);
+ color: var(--dug-chip-high-fg);
+}
+
+.dug-chip--danger,
+.dug-chip--critical {
+ background: var(--dug-chip-critical-bg);
+ color: var(--dug-chip-critical-fg);
+}
+
+.dug-chip--high {
+ background: var(--dug-chip-high-bg);
+ color: var(--dug-chip-high-fg);
+}
+
+.dug-chip--medium {
+ background: var(--dug-chip-medium-bg);
+ color: var(--dug-chip-medium-fg);
+}
+
+.dug-chip--low {
+ background: var(--dug-chip-low-bg);
+ color: var(--dug-chip-low-fg);
+}
+
+.dug-status {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.dug-status__dot {
+ flex: 0 0 auto;
+ width: 8px;
+ height: 8px;
+ border-radius: 50%;
+}
+
+.dug-status--success .dug-status__dot {
+ background: var(--dug-success);
+}
+
+.dug-status--success .dug-status__text {
+ color: var(--dug-text);
+ font-weight: 400;
+}
+
+.dug-status--warning .dug-status__dot {
+ background: var(--dug-attention);
+}
+
+.dug-status--warning .dug-status__text {
+ color: var(--dug-chip-high-fg);
+ font-weight: 600;
+}
+
+.dug-status--danger .dug-status__dot {
+ background: var(--dug-danger);
+}
+
+.dug-status--danger .dug-status__text {
+ color: var(--dug-danger);
+ font-weight: 600;
+}
+
+.dug-status--info .dug-status__dot {
+ background: var(--dug-primary);
+}
+
+.dug-status--info .dug-status__text {
+ color: var(--dug-link);
+ font-weight: 600;
+}
+
+.dug-status--neutral .dug-status__dot {
+ background: var(--dug-text-muted);
+}
+
+.dug-status--neutral .dug-status__text {
+ color: var(--dug-text-muted);
+ font-weight: 400;
+}
+
+.dug-severity {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+}
+
+.dug-severity__bar {
+ display: flex;
+ gap: 2px;
+ height: 8px;
+ border-radius: 4px;
+ overflow: hidden;
+}
+
+.dug-severity__segment {
+ flex-basis: 0;
+ min-width: 4px;
+}
+
+.dug-severity__segment--critical {
+ background: var(--dug-sev-critical);
+}
+
+.dug-severity__segment--high {
+ background: var(--dug-sev-high);
+}
+
+.dug-severity__segment--medium {
+ background: var(--dug-sev-medium);
+}
+
+.dug-severity__segment--low {
+ background: var(--dug-sev-low);
+}
+
+.dug-severity__legend {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 2px 12px;
+ color: var(--dug-text-muted);
+ font-size: 12.5px;
+}
+
+.dug-page-header {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+}
+
+.dug-page-header__breadcrumb {
+ color: var(--dug-text-muted);
+ font-size: 13px;
+}
+
+.dug-page-header__main {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: flex-end;
+ justify-content: space-between;
+ gap: 12px 24px;
+}
+
+.dug-page-header__text {
+ flex: 1 1 24rem;
+ min-width: 0;
+}
+
+.dug-page-header__title-row {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 8px 12px;
+}
+
+.dug-page-header__title {
+ margin: 0;
+ font-family: var(--dug-font-display);
+ font-size: 28px;
+ font-weight: 600;
+ line-height: 1.2;
+ letter-spacing: -0.01em;
+}
+
+.dug-page-header__description {
+ margin-top: 4px;
+ margin-bottom: 0;
+ max-width: 70ch;
+ color: var(--dug-text-muted);
+ font-size: 14px;
+}
+
+.dug-page-header__actions {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 8px;
+}
+
+.dug-panel {
+ background: var(--dug-surface);
+ border: 1px solid var(--dug-border);
+ border-radius: var(--dug-radius-lg);
+ box-shadow: none;
+}
+
+.dug-panel__header {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: baseline;
+ justify-content: space-between;
+ gap: 4px 12px;
+ padding: 16px 20px;
+}
+
+.dug-panel__title {
+ margin: 0;
+ font-family: var(--dug-font-text);
+ font-size: 15px;
+ font-weight: 600;
+}
+
+.dug-panel__meta {
+ color: var(--dug-text-muted);
+ font-size: 13px;
+}
+
+.dug-panel__header-content {
+ min-width: 0;
+}
+
+.dug-panel__body {
+ padding: 0 20px 20px;
+}
+
+.dug-panel > .dug-panel__body:first-child {
+ padding-top: 20px;
+}
+
+.dug-panel--flush .dug-panel__body {
+ padding: 0;
+}
+
+.mud-button-root {
+ text-transform: none;
+}
+
+.mud-button-filled.mud-button-filled-primary {
+ min-height: 44px;
+ padding: 0 18px;
+ border-radius: var(--dug-radius-md);
+ font-weight: 600;
+}
+
+.mud-button-filled.mud-button-filled-primary:not(:disabled) {
+ background: var(--dug-primary);
+ color: var(--dug-on-primary);
+}
+
+.mud-button-filled.mud-button-filled-primary:not(:disabled):hover,
+.mud-button-filled.mud-button-filled-primary:not(:disabled):focus-visible {
+ background: color-mix(in srgb, var(--dug-primary) 86%, var(--dug-text));
+}
+
+.mud-button-filled.mud-button-filled-primary:not(:disabled):active {
+ background: color-mix(in srgb, var(--dug-primary) 72%, var(--dug-text));
+}
+
+.mud-button-outlined.mud-button-outlined-default,
+.mud-button-outlined.mud-button-outlined-primary {
+ min-height: 44px;
+ padding: 0 18px;
+ border-radius: var(--dug-radius-md);
+ font-weight: 600;
+}
+
+.mud-button-outlined.mud-button-outlined-default:not(:disabled),
+.mud-button-outlined.mud-button-outlined-primary:not(:disabled) {
+ background: var(--dug-surface);
+ color: var(--dug-text);
+ border: 1px solid var(--dug-border-control);
+}
+
+.mud-button-outlined.mud-button-outlined-default:not(:disabled):hover,
+.mud-button-outlined.mud-button-outlined-default:not(:disabled):focus-visible,
+.mud-button-outlined.mud-button-outlined-primary:not(:disabled):hover,
+.mud-button-outlined.mud-button-outlined-primary:not(:disabled):focus-visible {
+ background: var(--dug-surface-subtle);
+}
+
+.mud-button-outlined.mud-button-outlined-default:not(:disabled):active,
+.mud-button-outlined.mud-button-outlined-primary:not(:disabled):active {
+ background: var(--dug-border-inner);
+}
+
+.section-table .mud-table-body .mud-icon-button,
+.dug-icon-button {
+ width: 44px;
+ height: 44px;
+ border-radius: var(--dug-radius-md);
+}
+
+.section-table .mud-table-body .mud-icon-button:not(:disabled),
+.dug-icon-button:not(:disabled) {
+ color: var(--dug-icon);
+ border: 1px solid var(--dug-border);
+}
+
+.mud-input-control .mud-input {
+ min-height: 44px;
+}
+
+.mud-input.mud-input-outlined .mud-input-outlined-border {
+ border-color: var(--dug-border-control);
+ border-radius: var(--dug-radius-md);
+}
+
+.mud-input-control > .mud-input-control-input-container > .mud-input-label {
+ font-size: 13px;
+ font-weight: 500;
+}
+
+.mud-shrink ~ label.mud-input-label.mud-input-label-inputcontrol,
+.mud-input:focus-within ~ label.mud-input-label.mud-input-label-inputcontrol {
+ font-size: 16px;
+}
+
+.mud-input:has(:-webkit-autofill) ~ label.mud-input-label.mud-input-label-inputcontrol {
+ font-size: 16px;
+}
+
.dug-rail-critical {
box-shadow: inset 3px 0 0 var(--dug-sev-critical);
}
@@ -761,6 +1116,24 @@ a {
}
}
+@media (min-width: 960px) {
+ .section-table .mud-table-body .mud-table-cell:first-child {
+ padding-left: 20px;
+ }
+
+ .section-table .mud-table-body .mud-table-cell:last-child {
+ padding-right: 20px;
+ }
+
+ .section-table .mud-table-head .mud-table-cell:first-child {
+ padding-left: 20px;
+ }
+
+ .section-table .mud-table-head .mud-table-cell:last-child {
+ padding-right: 20px;
+ }
+}
+
@media (min-width: 1280px) {
.runtime-containers-table .runtime-containers-table__update-state {
min-width: 18rem;
@@ -778,7 +1151,7 @@ a {
padding: 0.9rem 1rem;
background: var(--dug-surface);
border: 1px solid var(--dug-border);
- border-radius: var(--dug-radius-md);
+ border-radius: var(--dug-radius-lg);
}
.section-table .mud-table-body .mud-table-cell {
@@ -792,10 +1165,10 @@ a {
.section-table .mud-table-body .mud-table-cell::before {
color: var(--dug-text-faint);
- font-size: 0.75rem;
- font-weight: 600;
- letter-spacing: 0.05em;
- text-transform: uppercase;
+ font-size: 12px;
+ font-weight: 500;
+ letter-spacing: normal;
+ text-transform: none;
}
.section-table .mud-table-body .mud-table-cell:empty {
diff --git a/src/Tests/DockerUpdateGuard.Tests/AppStylesheetSharedComponentsTests.cs b/src/Tests/DockerUpdateGuard.Tests/AppStylesheetSharedComponentsTests.cs
new file mode 100644
index 00000000..4f4b13eb
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/AppStylesheetSharedComponentsTests.cs
@@ -0,0 +1,1090 @@
+using System.Globalization;
+using System.Text.RegularExpressions;
+
+using Bunit;
+
+using DockerUpdateGuard.Tests.Helper;
+
+using MudBlazor;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for the rules of wwwroot/app.css that style the shared components (chip, status indicator, severity bar, page header, section panel), the global table style and the global button and field style of the flat refresh
+///
+[TestClass]
+public class AppStylesheetSharedComponentsTests
+{
+ #region Constants
+
+ ///
+ /// Shipped stylesheet below the host project directory
+ ///
+ private const string StylesheetPath = "wwwroot/app.css";
+
+ ///
+ /// Value of a panel's hairline border
+ ///
+ private const string HairlineBorder = "1px solid var(--dug-border)";
+
+ ///
+ /// Media context of the card layout of table rows
+ ///
+ private const string RowCardContext = "@media (max-width: 959.98px)";
+
+ ///
+ /// Media context of the table layout of wide screens
+ ///
+ private const string WideContext = "@media (min-width: 960px)";
+
+ ///
+ /// Pseudo class a rule needs so that a disabled button keeps MudBlazor's disabled look
+ ///
+ private const string EnabledOnly = ":not(:disabled)";
+
+ ///
+ /// Selector prefix of the icon buttons in table body rows
+ ///
+ private const string RowIconButton = ".section-table .mud-table-body .mud-icon-button";
+
+ ///
+ /// Selector prefix of the icon buttons that carry the shared class
+ ///
+ private const string SharedIconButton = ".dug-icon-button";
+
+ #endregion // Constants
+
+ #region Fields
+
+ ///
+ /// Severity names of the segment classes
+ ///
+ private static readonly string[] _severities = ["critical", "high", "medium", "low"];
+
+ ///
+ /// Selectors of the floating label of a field that is shrunk, focused or autofilled
+ ///
+ private static readonly string[] _shrunkLabelSelectors = [
+ ".mud-shrink ~ label.mud-input-label.mud-input-label-inputcontrol",
+ ".mud-input:focus-within ~ label.mud-input-label.mud-input-label-inputcontrol",
+ ".mud-input:has(:-webkit-autofill) ~ label.mud-input-label.mud-input-label-inputcontrol",
+ ];
+
+ ///
+ /// Pseudo classes of an interaction state a button reacts to
+ ///
+ private static readonly string[] _interactionStates = [":hover", ":active", ":focus-visible"];
+
+ ///
+ /// Properties that take a color of a button
+ ///
+ private static readonly string[] _buttonColorProperties = ["color", "background", "background-color", "border", "border-color"];
+
+ ///
+ /// A negation pseudo class, with its argument as group 1
+ ///
+ private static readonly Regex _notGroupPattern = new(@":not\(([^)]*)\)",
+ RegexOptions.CultureInvariant,
+ TimeSpan.FromSeconds(5));
+
+ ///
+ /// A filled or outlined MudBlazor button class, with or without a color
+ ///
+ private static readonly Regex _buttonVariantPattern = new(@"\.mud-button-(filled|outlined)(?![\w-])|\.mud-button-(filled|outlined)-(?!size|root)[a-z]+(?![\w-])",
+ RegexOptions.CultureInvariant,
+ TimeSpan.FromSeconds(5));
+
+ ///
+ /// The color class of a filled or outlined MudBlazor button, with the color as group 2
+ ///
+ private static readonly Regex _buttonColorPattern = new(@"\.mud-button-(filled|outlined)-(?!size|root)([a-z]+)(?![\w-])",
+ RegexOptions.CultureInvariant,
+ TimeSpan.FromSeconds(5));
+
+ ///
+ /// A first or last child pseudo class
+ ///
+ private static readonly Regex _edgePattern = new(@":(first|last)-(child|of-type)",
+ RegexOptions.CultureInvariant,
+ TimeSpan.FromSeconds(5));
+
+ ///
+ /// A length in pixels or rem, or a plain number
+ ///
+ private static readonly Regex _lengthPattern = new(@"^(-?\d*\.?\d+)(px|rem)?$",
+ RegexOptions.CultureInvariant,
+ TimeSpan.FromSeconds(5));
+
+ #endregion // Fields
+
+ #region Methods
+
+ ///
+ /// Verify each chip class takes the background and text of the chip token pair issue #452 section 2 assigns its tone, and the base chip is small, semibold and slightly rounded
+ ///
+ /// Tone class suffix
+ /// Chip token pair name
+ [TestMethod]
+ [TestCategory("AC3")]
+ [DataRow("neutral", "low")]
+ [DataRow("info", "info")]
+ [DataRow("success", "success")]
+ [DataRow("warning", "high")]
+ [DataRow("danger", "critical")]
+ [DataRow("critical", "critical")]
+ [DataRow("high", "high")]
+ [DataRow("medium", "medium")]
+ [DataRow("low", "low")]
+ public void AppStylesheetChipClassesUseTheirTokenPair(string tone, string pair)
+ {
+ var selector = $".dug-chip--{tone}";
+ var declarations = GetDeclarations(selector);
+
+ var mismatches = FindExactMismatches(selector, ReadBackground(declarations), [("background", $"var(--dug-chip-{pair}-bg)")]).Concat(FindExactMismatches(selector, declarations, [("color", $"var(--dug-chip-{pair}-fg)")]))
+ .Concat(FindLengthMismatches(".dug-chip", GetDeclarations(".dug-chip"), [("font-size", "12px"), ("padding", "1px 8px")]))
+ .Concat(FindExactMismatches(".dug-chip", GetDeclarations(".dug-chip"), [("font-weight", "600"), ("border-radius", "var(--dug-radius-sm)")]))
+ .ToList();
+
+ AssertNoMismatches(mismatches, $"The {tone} chip must use the {pair} chip tokens");
+ }
+
+ ///
+ /// Verify each status indicator tone draws its dot, weight and text color as issue #452 section 3 says, and the dot is 8 px with an 8 px gap
+ ///
+ /// Tone class suffix
+ /// Token of the dot
+ /// Accepted font weights of the text, separated by a bar
+ /// Token of the text
+ [TestMethod]
+ [TestCategory("AC4")]
+ [DataRow("success", "--dug-success", "400|normal", "--dug-text")]
+ [DataRow("warning", "--dug-attention", "600", "--dug-chip-high-fg")]
+ [DataRow("danger", "--dug-danger", "600", "--dug-danger")]
+ [DataRow("info", "--dug-primary", "600", "--dug-link")]
+ [DataRow("neutral", "--dug-text-muted", "400|normal", "--dug-text-muted")]
+ public void AppStylesheetStatusIndicatorTonesUseIssueColors(string tone, string dotToken, string weights, string textToken)
+ {
+ var dotSelector = $".dug-status--{tone} .dug-status__dot";
+ var textSelector = $".dug-status--{tone} .dug-status__text";
+ var text = GetDeclarations(textSelector);
+
+ var mismatches = FindExactMismatches(dotSelector, ReadBackground(GetDeclarations(dotSelector)), [("background", $"var({dotToken})")]).Concat(FindExactMismatches(textSelector, text, [("color", $"var({textToken})")]))
+ .Concat(FindAnyOfMismatches(textSelector, text, "font-weight", weights.Split('|')))
+ .Concat(FindLengthMismatches(".dug-status__dot", GetDeclarations(".dug-status__dot"), [("width", "8px"), ("height", "8px")]))
+ .Concat(FindLengthMismatches(".dug-status", GetDeclarations(".dug-status"), [("gap", "8px")]))
+ .ToList();
+
+ AssertNoMismatches(mismatches, $"The {tone} status indicator must use the colors and weight of the issue");
+ }
+
+ ///
+ /// Verify the severity bar is an 8 px flex bar whose segments weigh by their count with a minimum width and take the severity colors, and the legend is 12.5 px muted text
+ ///
+ [TestMethod]
+ [TestCategory("AC5")]
+ public void AppStylesheetSeverityBarSegmentsHaveMinimumWidth()
+ {
+ var segment = GetDeclarations(".dug-severity__segment");
+
+ var mismatches = FindLengthMismatches(".dug-severity__segment", segment, [("min-width", "4px")]).Concat(FindAnyOfMismatches(".dug-severity__segment", segment, "flex-basis", "0", "0px", "0%"))
+ .Concat(FindExactMismatches(".dug-severity__bar", GetDeclarations(".dug-severity__bar"), [("display", "flex")]))
+ .Concat(FindLengthMismatches(".dug-severity__bar", GetDeclarations(".dug-severity__bar"), [("height", "8px"), ("border-radius", "4px"), ("gap", "2px")]))
+ .Concat(FindLengthMismatches(".dug-severity__legend", GetDeclarations(".dug-severity__legend"), [("font-size", "12.5px")]))
+ .Concat(FindExactMismatches(".dug-severity__legend", GetDeclarations(".dug-severity__legend"), [("color", "var(--dug-text-muted)")]))
+ .Concat(_severities.SelectMany(FindSeverityColorMismatches))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "Every severity segment must stay visible and use its severity color");
+ }
+
+ ///
+ /// Verify the page header title is 28 px semibold in the display font, the description is 14 px muted and at most 70 characters wide, the main row wraps and the header has no background or border
+ ///
+ [TestMethod]
+ [TestCategory("AC6")]
+ public void AppStylesheetPageHeaderUsesDisplayFontAndMeasure()
+ {
+ var description = GetDeclarations(".dug-page-header__description");
+ var header = GetDeclarations(".dug-page-header");
+
+ var mismatches = FindExactMismatches(".dug-page-header__title", GetDeclarations(".dug-page-header__title"), [("font-family", "var(--dug-font-display)"), ("font-weight", "600")]).Concat(FindLengthMismatches(".dug-page-header__title", GetDeclarations(".dug-page-header__title"), [("font-size", "28px")]))
+ .Concat(FindExactMismatches(".dug-page-header__description", description, [("color", "var(--dug-text-muted)"), ("max-width", "70ch")]))
+ .Concat(FindLengthMismatches(".dug-page-header__description", description, [("font-size", "14px"), ("margin-top", "4px")]))
+ .Concat(FindExactMismatches(".dug-page-header__main", GetDeclarations(".dug-page-header__main"), [("display", "flex"), ("flex-wrap", "wrap")]))
+ .Concat(header.Where(declaration => declaration.Key.StartsWith("background", StringComparison.Ordinal) || declaration.Key.StartsWith("border", StringComparison.Ordinal))
+ .Where(declaration => declaration.Value is not ("none" or "0" or "transparent"))
+ .Select(declaration => $".dug-page-header sets {declaration.Key}: {declaration.Value}"))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "The page header must be plain text with the display font title and a limited description measure");
+ }
+
+ ///
+ /// Verify the section panel is a flat bordered surface with a wrapping baseline header, a 15 px title, 13 px muted meta, and a body without padding at the top that is edge to edge when flush
+ ///
+ [TestMethod]
+ [TestCategory("AC7")]
+ public void AppStylesheetSectionPanelIsFlatBorderedSurface()
+ {
+ var panel = GetDeclarations(".dug-panel");
+ var title = GetDeclarations(".dug-panel__title");
+
+ var mismatches = FindExactMismatches(".dug-panel", panel, [("border", HairlineBorder), ("border-radius", "var(--dug-radius-lg)")]).Concat(FindExactMismatches(".dug-panel", ReadBackground(panel), [("background", "var(--dug-surface)")]))
+ .Concat(FindExactMismatches(".dug-panel__header", GetDeclarations(".dug-panel__header"), [("display", "flex"), ("flex-wrap", "wrap"), ("align-items", "baseline"), ("justify-content", "space-between")]))
+ .Concat(FindLengthMismatches(".dug-panel__header", GetDeclarations(".dug-panel__header"), [("padding", "16px 20px")]))
+ .Concat(FindExactMismatches(".dug-panel__title", title, [("font-weight", "600"), ("font-family", "var(--dug-font-text)")]))
+ .Concat(FindLengthMismatches(".dug-panel__title", title, [("font-size", "15px")]))
+ .Concat(FindExactMismatches(".dug-panel__meta", GetDeclarations(".dug-panel__meta"), [("color", "var(--dug-text-muted)")]))
+ .Concat(FindLengthMismatches(".dug-panel__meta", GetDeclarations(".dug-panel__meta"), [("font-size", "13px")]))
+ .Concat(FindLengthMismatches(".dug-panel__body", GetDeclarations(".dug-panel__body"), [("padding", "0 20px 20px")]))
+ .Concat(FindLengthMismatches(".dug-panel--flush .dug-panel__body", GetDeclarations(".dug-panel--flush .dug-panel__body"), [("padding", "0")]))
+ .ToList();
+
+ Assert.IsFalse(panel.TryGetValue("box-shadow", out var shadow) && shadow != "none", "The panel must have no shadow");
+ AssertNoMismatches(mismatches, "The section panel must be a flat bordered surface");
+ }
+
+ ///
+ /// Verify the table head is sentence case, 13 px, weight 500, muted, without letter spacing, with a hairline above and below
+ ///
+ [TestMethod]
+ [TestCategory("AC8")]
+ public void AppStylesheetTableHeadIsSentenceCaseWithHairlines()
+ {
+ const string selector = ".section-table .mud-table-head .mud-table-cell";
+
+ var head = GetDeclarations(selector);
+
+ var mismatches = FindExactMismatches(selector, head, [("color", "var(--dug-text-muted)"), ("font-weight", "500"), ("text-transform", "none"), ("border-top", HairlineBorder), ("border-bottom", HairlineBorder)]).Concat(FindLengthMismatches(selector, head, [("font-size", "13px")]))
+ .Concat(FindAnyOfMismatches(selector, head, "letter-spacing", "normal", "0", "0px"))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "The table head must read in sentence case with hairlines above and below");
+ }
+
+ ///
+ /// Verify body rows are separated by the inner border with 12 px by 16 px cells, top aligned, a subtle hover row, tabular figures and a 13 px muted secondary line
+ ///
+ [TestMethod]
+ [TestCategory("AC8")]
+ public void AppStylesheetTableRowsUseInnerBorderPaddingAndTabularFigures()
+ {
+ const string selector = ".section-table .mud-table-body .mud-table-cell";
+
+ var cell = GetDeclarations(selector);
+ var secondary = GetDeclarations(".table-secondary");
+
+ var mismatches = FindExactMismatches(selector, cell, [("border-bottom", "1px solid var(--dug-border-inner)"), ("vertical-align", "top")]).Concat(FindLengthMismatches(selector, cell, [("padding", "12px 16px")]))
+ .Concat(FindExactMismatches(".section-table", GetDeclarations(".section-table"), [("font-variant-numeric", "tabular-nums")]))
+ .Concat(FindExactMismatches(".table-secondary", secondary, [("color", "var(--dug-text-muted)")]))
+ .Concat(FindLengthMismatches(".table-secondary", secondary, [("font-size", "13px")]))
+ .Concat(FindHoverRowMismatches())
+ .ToList();
+
+ AssertNoMismatches(mismatches, "Body rows must use hairlines, the cell padding of the issue and tabular figures");
+ }
+
+ ///
+ /// Verify the first and last body cell get their 20 px padding only where the table layout is shown, so that the row cards below 960 px keep their own padding
+ ///
+ [TestMethod]
+ [TestCategory("AC8")]
+ public void AppStylesheetFirstAndLastCellPaddingDoesNotReachRowCards()
+ {
+ var edgeRules = GetEntries().Where(rule => IsBodyEdgeCellEntry(rule.Entry) && rule.Body.Contains("padding", StringComparison.Ordinal))
+ .ToList();
+
+ var leaking = edgeRules.Where(rule => rule.Context != WideContext && rule.Context != RowCardContext)
+ .Select(rule => rule.Entry)
+ .ToList();
+
+ var mismatches = FindMissingEdgePadding(edgeRules).ToList();
+
+ if (leaking.Count > 0 && edgeRules.Any(rule => rule.Context == RowCardContext) == false)
+ {
+ mismatches.AddRange(leaking.Select(entry => $"{entry} sets padding outside @media (min-width: 960px) and the card rule does not reset it"));
+ }
+
+ AssertNoMismatches(mismatches, "The 20 px edge padding of the first and last cell must stay out of the row cards");
+ }
+
+ ///
+ /// Verify a table inside a flush panel has no frame, radius or background of its own
+ ///
+ [TestMethod]
+ [TestCategory("AC8")]
+ public void AppStylesheetFlushPanelTableHasNoOwnFrame()
+ {
+ const string selector = ".dug-panel--flush .section-table .mud-table-container";
+
+ var container = GetDeclarations(selector);
+
+ var mismatches = FindAnyOfMismatches(selector, container, "border", "none", "0").Concat(FindAnyOfMismatches(selector, container, "border-radius", "0", "0px"))
+ .Concat(FindAnyOfMismatches(selector, container, "background", "none", "transparent"))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "A table inside a flush panel must not draw its own border, radius or background");
+ }
+
+ ///
+ /// Verify the label in front of a value of a row card is 12 px, weight 500, sentence case, without letter spacing and faint
+ ///
+ [TestMethod]
+ [TestCategory("AC8")]
+ public void AppStylesheetRowCardLabelIsSentenceCaseFaint()
+ {
+ const string selector = ".section-table .mud-table-body .mud-table-cell::before";
+
+ var label = GetEntries().Where(rule => rule.Context == RowCardContext && rule.Entry == selector)
+ .Select(rule => ToDeclarationMap(rule.Body))
+ .FirstOrDefault();
+
+ Assert.IsNotNull(label, "The row card label rule must stay below 960 px");
+
+ var mismatches = FindExactMismatches(selector, label, [("color", "var(--dug-text-faint)"), ("font-weight", "500"), ("text-transform", "none")]).Concat(FindLengthMismatches(selector, label, [("font-size", "12px")]))
+ .Concat(FindAnyOfMismatches(selector, label, "letter-spacing", "normal", "0", "0px"))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "The row card label must be small, sentence case and faint");
+ }
+
+ ///
+ /// Verify no button label is uppercase
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetButtonsAreNotUppercase()
+ {
+ var mismatches = FindExactMismatches(".mud-button-root", GetDeclarations(".mud-button-root"), [("text-transform", "none")]);
+
+ AssertNoMismatches(mismatches, "Every MudBlazor button must draw its label as written");
+ }
+
+ ///
+ /// Verify every color rule of a filled or outlined button names only the colors it styles (filled primary, outlined default and primary), excludes disabled buttons, and names no other color such as error
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetPrimaryAndSecondaryRulesMatchOnlyTheirColors()
+ {
+ var buttonRules = GetEntries().Where(rule => _buttonVariantPattern.IsMatch(rule.Entry) && HasColorProperty(rule.Body))
+ .ToList();
+
+ var mismatches = buttonRules.SelectMany(rule => FindButtonSelectorMismatches(rule.Entry)).ToList();
+
+ mismatches.AddRange(FindMissingButtonRule(buttonRules, "filled", "primary"));
+ mismatches.AddRange(FindMissingButtonRule(buttonRules, "outlined", "default"));
+ mismatches.AddRange(FindMissingButtonRule(buttonRules, "outlined", "primary"));
+
+ AssertNoMismatches(mismatches, "The button color rules must match only filled primary and outlined default and primary buttons that are not disabled");
+ }
+
+ ///
+ /// Verify the primary and secondary button rules keep MudBlazor's hover, active and focus feedback: in each state either no rule of the stylesheet sets a background, or it differs from the resting one
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetButtonColorRulesKeepHoverActiveAndFocusFeedback()
+ {
+ var mismatches = new[] { ("filled", "primary"), ("outlined", "default"), ("outlined", "primary") }.SelectMany(kind => FindFeedbackMismatches(kind.Item1, kind.Item2))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "A button must still look different when hovered, pressed or focused");
+ }
+
+ ///
+ /// Verify the primary button uses the primary tokens and the secondary button the surface and control border tokens
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetPrimaryAndSecondaryButtonsUseTokenColors()
+ {
+ var primary = GetRestingButtonDeclarations("filled", "primary");
+ var mismatches = FindPrimaryButtonMismatches(primary).ToList();
+
+ mismatches.AddRange(FindSecondaryButtonMismatches("default"));
+ mismatches.AddRange(FindSecondaryButtonMismatches("primary"));
+
+ AssertNoMismatches(mismatches, "The buttons must use the flat token colors of the issue");
+ }
+
+ ///
+ /// Verify the shape of filled primary, outlined default and outlined primary buttons (44 px height, 18 px padding, radius, weight) comes from rules that also reach disabled buttons, and the rules that exclude disabled buttons set no shape
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetButtonShapeRulesReachDisabledButtonsAndColorRulesDoNot()
+ {
+ var mismatches = new[] { ("filled", "primary"), ("outlined", "default"), ("outlined", "primary") }.SelectMany(kind => FindShapeMismatches(kind.Item1, kind.Item2))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "The button shape must not depend on the button being enabled");
+ }
+
+ ///
+ /// Verify the row icon button rules style only icon buttons in table body rows and the shared icon button class, never a disabled one where they set a color or border, and give them 44 px, the hairline border, radius and icon color
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetRowIconButtonsAreBodyRowsOnly()
+ {
+ var entries = GetEntries().Where(rule => rule.Entry.Contains(".mud-icon-button", StringComparison.Ordinal) || rule.Entry.Contains(SharedIconButton, StringComparison.Ordinal))
+ .ToList();
+
+ var mismatches = entries.Where(rule => IsOutsideBodyRows(rule.Entry))
+ .Select(rule => $"{rule.Entry} styles an icon button outside table body rows")
+ .ToList();
+
+ mismatches.AddRange(entries.Where(rule => HasColorProperty(rule.Body) && rule.Entry.Contains(EnabledOnly, StringComparison.Ordinal) == false)
+ .Select(rule => $"{rule.Entry} sets a color or border without {EnabledOnly}"));
+ mismatches.AddRange(FindIconButtonMismatches(entries, RowIconButton));
+ mismatches.AddRange(FindIconButtonMismatches(entries, SharedIconButton));
+
+ AssertNoMismatches(mismatches, "Row icon buttons must be styled in table body rows and by their own class only");
+ }
+
+ ///
+ /// Verify text fields and selects are at least 44 px high, outlined fields have the control border and radius, and labels are 13 px with weight 500, in rules at least as specific as MudBlazor's own, and the shrunk floating label (shrunk, focused, autofilled) is 16 px
+ ///
+ [TestMethod]
+ [TestCategory("AC9")]
+ public void AppStylesheetFieldsAreAtLeastControlHeight()
+ {
+ const string borderSelector = ".mud-input.mud-input-outlined .mud-input-outlined-border";
+ const string labelSelector = ".mud-input-control > .mud-input-control-input-container > .mud-input-label";
+
+ var border = GetDeclarations(borderSelector);
+ var label = GetDeclarations(labelSelector);
+
+ var mismatches = FindLengthMismatches(".mud-input-control .mud-input", GetDeclarations(".mud-input-control .mud-input"), [("min-height", "44px")]).Concat(FindBorderMismatches(borderSelector, border, "--dug-border-control"))
+ .Concat(FindExactMismatches(borderSelector, border, [("border-radius", "var(--dug-radius-md)")]))
+ .Concat(FindLengthMismatches(labelSelector, label, [("font-size", "13px")]))
+ .Concat(FindExactMismatches(labelSelector, label, [("font-weight", "500")]))
+ .Concat(_shrunkLabelSelectors.SelectMany(selector => FindLengthMismatches(selector, GetDeclarations(selector), [("font-size", "16px")])))
+ .ToList();
+
+ AssertNoMismatches(mismatches, "Fields must be control height with the control border and a medium weight label");
+ }
+
+ ///
+ /// Verify a rendered MudBlazor button carries the classes the stylesheet selectors rely on, and a disabled one a disabled attribute
+ ///
+ /// Button variant
+ /// Button color
+ /// Variant in the class name
+ /// Color in the class name
+ /// Task
+ [TestMethod]
+ [TestCategory("AC9")]
+ [DataRow(Variant.Filled, Color.Primary, "filled", "primary")]
+ [DataRow(Variant.Filled, Color.Default, "filled", "default")]
+ [DataRow(Variant.Filled, Color.Error, "filled", "error")]
+ [DataRow(Variant.Outlined, Color.Primary, "outlined", "primary")]
+ [DataRow(Variant.Outlined, Color.Default, "outlined", "default")]
+ [DataRow(Variant.Outlined, Color.Error, "outlined", "error")]
+ public async Task AppStylesheetButtonClassesMatchRenderedButtons(Variant variant, Color color, string variantName, string colorName)
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var enabled = testContext.Render(parameters => parameters.Add(button => button.Variant, variant)
+ .Add(button => button.Color, color));
+ var disabled = testContext.Render(parameters => parameters.Add(button => button.Variant, variant)
+ .Add(button => button.Color, color)
+ .Add(button => button.Disabled, true));
+
+ var enabledButton = enabled.Find("button");
+ var classes = enabledButton.ClassList.ToList();
+
+ Assert.Contains("mud-button-root", classes, "The button must carry the root class the uppercase rule targets");
+ Assert.Contains($"mud-button-{variantName}", classes, "The button must carry its variant class");
+ Assert.Contains($"mud-button-{variantName}-{colorName}", classes, "The button must carry its variant and color class");
+ Assert.IsFalse(enabledButton.HasAttribute("disabled"), "An enabled button must not carry the disabled attribute");
+ Assert.IsTrue(disabled.Find("button").HasAttribute("disabled"), "A disabled button must carry the disabled attribute that :not(:disabled) tests");
+ }
+ }
+
+ #endregion // Methods
+
+ #region Helper methods
+
+ ///
+ /// Read the declarations of the top-level rules that name a selector
+ ///
+ /// One selector of a rule's selector list
+ /// Property name to collapsed value
+ private static Dictionary GetDeclarations(string selector)
+ {
+ return StylesheetReader.GetDeclarations(StylesheetReader.ReadHostFile(StylesheetPath), selector);
+ }
+
+ ///
+ /// Read every selector of every rule of the stylesheet, in every media context
+ ///
+ /// Selector, rule body and media context
+ private static List<(string Entry, string Body, string Context)> GetEntries()
+ {
+ return StylesheetReader.GetRules(StylesheetReader.ReadHostFile(StylesheetPath))
+ .SelectMany(rule => StylesheetReader.SplitTopLevel(rule.Selector, ',').Select(entry => (entry, rule.Body, rule.Context)))
+ .ToList();
+ }
+
+ ///
+ /// Read the declarations of a rule body into a map, a later declaration overriding an earlier one
+ ///
+ /// Rule body
+ /// Property name to collapsed value
+ private static Dictionary ToDeclarationMap(string body)
+ {
+ var declarations = new Dictionary(StringComparer.Ordinal);
+
+ foreach (var (name, value) in StylesheetReader.GetDeclarationList(body))
+ {
+ declarations[name] = value;
+ }
+
+ return declarations;
+ }
+
+ ///
+ /// Pick the background declaration of a rule, as background , whichever of background and background-color it uses
+ ///
+ /// Declarations of the rule
+ /// Map with the background entry, empty when the rule sets none
+ private static Dictionary ReadBackground(Dictionary declarations)
+ {
+ var background = new Dictionary(StringComparer.Ordinal);
+
+ if (declarations.TryGetValue("background-color", out var color))
+ {
+ background["background"] = color;
+ }
+ else if (declarations.TryGetValue("background", out var shorthand))
+ {
+ background["background"] = shorthand;
+ }
+
+ return background;
+ }
+
+ ///
+ /// Tell whether a rule body sets a color of a button
+ ///
+ /// Rule body
+ /// true when a declaration sets a text, background or border color
+ private static bool HasColorProperty(string body)
+ {
+ return StylesheetReader.GetDeclarationList(body)
+ .Any(declaration => _buttonColorProperties.Contains(declaration.Name));
+ }
+
+ ///
+ /// Normalize a length of a declaration: pixels and rem to pixels, a box shorthand to four values
+ ///
+ /// Property name
+ /// Declaration value
+ /// Normalized value
+ private static string NormalizeLength(string name, string value)
+ {
+ var parts = value.Split(' ', StringSplitOptions.RemoveEmptyEntries)
+ .Select(NormalizeLengthToken)
+ .ToList();
+
+ if (name is "padding" or "margin")
+ {
+ parts = ExpandBox(parts);
+ }
+
+ return string.Join(' ', parts);
+ }
+
+ ///
+ /// Normalize one token of a length declaration
+ ///
+ /// Token
+ /// Number of pixels, or the token when it is not a length
+ private static string NormalizeLengthToken(string token)
+ {
+ var match = _lengthPattern.Match(token);
+
+ if (match.Success == false)
+ {
+ return token;
+ }
+
+ var number = decimal.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
+
+ if (match.Groups[2].Value == "rem")
+ {
+ number *= 16;
+ }
+
+ return number.ToString("0.###", CultureInfo.InvariantCulture);
+ }
+
+ ///
+ /// Expand the one to four values of a box shorthand to top, right, bottom and left
+ ///
+ /// Values
+ /// Four values, or the values when there are not one to four
+ private static List ExpandBox(List parts)
+ {
+ return parts.Count switch
+ {
+ 1 => [parts[0], parts[0], parts[0], parts[0]],
+ 2 => [parts[0], parts[1], parts[0], parts[1]],
+ 3 => [parts[0], parts[1], parts[2], parts[1]],
+ _ => parts,
+ };
+ }
+
+ ///
+ /// Compare declarations with expected values exactly, ignoring the letter case
+ ///
+ /// Name of what is checked
+ /// Declared properties
+ /// Expected property and value pairs
+ /// One text per missing or different declaration
+ private static List FindExactMismatches(string subject, Dictionary actual, (string Name, string Value)[] expected)
+ {
+ return FindMismatches(subject, actual, expected, (name, value) => value);
+ }
+
+ ///
+ /// Compare declarations with expected lengths, pixels and rem counting alike
+ ///
+ /// Name of what is checked
+ /// Declared properties
+ /// Expected property and length pairs
+ /// One text per missing or different declaration
+ private static List FindLengthMismatches(string subject, Dictionary actual, (string Name, string Value)[] expected)
+ {
+ return FindMismatches(subject, actual, expected, NormalizeLength);
+ }
+
+ ///
+ /// Compare declarations with expected values after a normalization
+ ///
+ /// Name of what is checked
+ /// Declared properties
+ /// Expected property and value pairs
+ /// Normalization of a property name and value
+ /// One text per missing or different declaration
+ private static List FindMismatches(string subject,
+ Dictionary actual,
+ (string Name, string Value)[] expected,
+ Func normalize)
+ {
+ var mismatches = new List();
+
+ foreach (var (name, value) in expected)
+ {
+ if (actual.TryGetValue(name, out var declared) == false)
+ {
+ mismatches.Add($"{subject}: {name} is missing");
+ }
+ else if (string.Equals(normalize(name, declared), normalize(name, value), StringComparison.OrdinalIgnoreCase) == false)
+ {
+ mismatches.Add($"{subject}: {name} is '{declared}', expected '{value}'");
+ }
+ }
+
+ return mismatches;
+ }
+
+ ///
+ /// Compare one declaration with a set of accepted values
+ ///
+ /// Name of what is checked
+ /// Declared properties
+ /// Property name
+ /// Accepted values
+ /// One text when the declaration is missing or not accepted
+ private static IEnumerable FindAnyOfMismatches(string subject, Dictionary actual, string name, params string[] allowed)
+ {
+ if (actual.TryGetValue(name, out var declared) == false)
+ {
+ return [$"{subject}: {name} is missing"];
+ }
+
+ return allowed.Contains(declared, StringComparer.OrdinalIgnoreCase) ? [] : [$"{subject}: {name} is '{declared}', expected one of {string.Join(", ", allowed)}"];
+ }
+
+ ///
+ /// Compare the border of a rule: either a 1 px solid border of the token, or a border color of the token
+ ///
+ /// Name of what is checked
+ /// Declared properties
+ /// Border color token
+ /// One text when neither declaration uses the token
+ private static IEnumerable FindBorderMismatches(string subject, Dictionary actual, string token)
+ {
+ var shorthand = actual.GetValueOrDefault("border");
+ var color = actual.GetValueOrDefault("border-color");
+
+ if (shorthand == $"1px solid var({token})" || color == $"var({token})")
+ {
+ return [];
+ }
+
+ return [$"{subject}: border is '{shorthand}' and border-color '{color}', expected a 1px solid border of var({token})"];
+ }
+
+ ///
+ /// Compare the background of a severity segment with its token
+ ///
+ /// Severity name
+ /// One text per missing or different declaration
+ private static IEnumerable FindSeverityColorMismatches(string severity)
+ {
+ var selector = $".dug-severity__segment--{severity}";
+
+ return FindExactMismatches(selector, ReadBackground(GetDeclarations(selector)), [("background", $"var(--dug-sev-{severity})")]);
+ }
+
+ ///
+ /// Find the missing background of a hovered body row
+ ///
+ /// One text when no hover rule of a table row sets the subtle surface
+ private static IEnumerable FindHoverRowMismatches()
+ {
+ var hovered = GetEntries().Where(rule => rule.Context.Length == 0
+ && rule.Entry.Contains(".section-table", StringComparison.Ordinal)
+ && rule.Entry.Contains("mud-table-row", StringComparison.Ordinal)
+ && rule.Entry.Contains(":hover", StringComparison.Ordinal))
+ .Select(rule => ReadBackground(ToDeclarationMap(rule.Body)).GetValueOrDefault("background"))
+ .ToList();
+
+ return hovered.Contains("var(--dug-surface-subtle)") ? [] : [".section-table: a hovered body row must take var(--dug-surface-subtle)"];
+ }
+
+ ///
+ /// Tell whether a selector is a first or last body cell of a table
+ ///
+ /// Selector
+ /// true for a first or last child body cell selector
+ private static bool IsBodyEdgeCellEntry(string entry)
+ {
+ return entry.Contains(".mud-table-body", StringComparison.Ordinal)
+ && entry.Contains(".mud-table-cell", StringComparison.Ordinal)
+ && _edgePattern.IsMatch(entry);
+ }
+
+ ///
+ /// Find the missing 20 px padding of the first and the last body cell
+ ///
+ /// Rules of first and last body cells that set a padding
+ /// One text per missing side
+ private static IEnumerable FindMissingEdgePadding(List<(string Entry, string Body, string Context)> edgeRules)
+ {
+ foreach (var edge in new[] { "first", "last" })
+ {
+ var found = edgeRules.Where(rule => rule.Context != RowCardContext && rule.Entry.Contains($":{edge}-", StringComparison.Ordinal))
+ .SelectMany(rule => StylesheetReader.GetDeclarationList(rule.Body))
+ .Any(declaration => declaration.Name.StartsWith("padding", StringComparison.Ordinal) && NormalizeLength(declaration.Name, declaration.Value).Contains("20", StringComparison.Ordinal));
+
+ if (found == false)
+ {
+ yield return $"No rule gives the {edge} body cell 20px padding";
+ }
+ }
+ }
+
+ ///
+ /// Check a selector of a button color rule: it names a color the rule styles, no other, and excludes disabled buttons
+ ///
+ /// Selector
+ /// One text per problem
+ private static List FindButtonSelectorMismatches(string entry)
+ {
+ var mismatches = new List();
+ var colors = _buttonColorPattern.Matches(entry)
+ .Select(match => (Variant: match.Groups[1].Value, Color: match.Groups[2].Value))
+ .ToList();
+
+ if (colors.Count == 0)
+ {
+ mismatches.Add($"{entry} sets a button color without naming a color");
+ }
+
+ mismatches.AddRange(colors.Where(color => IsStyledColor(color.Variant, color.Color) == false)
+ .Select(color => $"{entry} matches {color.Variant} buttons of the color {color.Color}"));
+
+ if (entry.Contains(EnabledOnly, StringComparison.Ordinal) == false)
+ {
+ mismatches.Add($"{entry} does not exclude disabled buttons");
+ }
+
+ return mismatches;
+ }
+
+ ///
+ /// Tell whether the stylesheet styles buttons of a variant and color
+ ///
+ /// Variant class suffix
+ /// Color class suffix
+ /// true for filled primary, outlined default and outlined primary
+ private static bool IsStyledColor(string variant, string color)
+ {
+ return (variant == "filled" && color == "primary")
+ || (variant == "outlined" && color is "default" or "primary");
+ }
+
+ ///
+ /// Find the missing color rule of a variant and color
+ ///
+ /// Color rules of buttons
+ /// Variant class suffix
+ /// Color class suffix
+ /// One text when no rule names the variant and color
+ private static IEnumerable FindMissingButtonRule(List<(string Entry, string Body, string Context)> buttonRules, string variant, string color)
+ {
+ var found = buttonRules.Any(rule => IsButtonKind(rule.Entry, variant, color));
+
+ return found ? [] : [$"No color rule matches {variant} buttons of the color {color}"];
+ }
+
+ ///
+ /// Tell whether a selector names the button class of a variant and color
+ ///
+ /// Selector
+ /// Variant class suffix
+ /// Color class suffix
+ /// true when the selector names .mud-button-{variant}-{color}
+ private static bool IsButtonKind(string entry, string variant, string color)
+ {
+ return Regex.IsMatch(entry, $@"\.mud-button-{variant}-{color}(?![\w-])", RegexOptions.CultureInvariant, TimeSpan.FromSeconds(5));
+ }
+
+ ///
+ /// Tell whether a selector applies to a button in a state: its positive state pseudo classes are at most the state, and it does not negate the state
+ ///
+ /// Selector
+ /// State pseudo class, empty for the resting state
+ /// true when the rule reaches a button in that state
+ private static bool AppliesToState(string entry, string state)
+ {
+ var negated = _notGroupPattern.Matches(entry)
+ .Select(match => match.Groups[1].Value)
+ .ToList();
+
+ if (state.Length > 0 && negated.Contains(state))
+ {
+ return false;
+ }
+
+ var positive = _notGroupPattern.Replace(entry, string.Empty);
+
+ return _interactionStates.Where(pseudo => positive.Contains(pseudo, StringComparison.Ordinal))
+ .All(pseudo => pseudo == state);
+ }
+
+ ///
+ /// Find the background a button of a variant and color gets from the stylesheet in a state
+ ///
+ /// Variant class suffix
+ /// Color class suffix
+ /// State pseudo class, empty for the resting state
+ /// Background value, null when no rule of the stylesheet sets one in that state
+ private static string? FindStateBackground(string variant, string color, string state)
+ {
+ var candidates = GetEntries().Where(rule => rule.Context.Length == 0
+ && IsButtonKind(rule.Entry, variant, color)
+ && AppliesToState(rule.Entry, state)
+ && ReadBackground(ToDeclarationMap(rule.Body)).Count > 0)
+ .ToList();
+
+ var specific = candidates.Where(rule => state.Length > 0 && _notGroupPattern.Replace(rule.Entry, string.Empty).Contains(state, StringComparison.Ordinal))
+ .ToList();
+
+ var chosen = specific.Count > 0 ? specific : candidates;
+
+ return chosen.Count == 0 ? null : ReadBackground(ToDeclarationMap(chosen[^1].Body))["background"];
+ }
+
+ ///
+ /// Find the states of a button kind whose background the stylesheet sets to the resting one
+ ///
+ /// Variant class suffix
+ /// Color class suffix
+ /// One text per state that shows no feedback, and one when the resting background is missing
+ private static IEnumerable FindFeedbackMismatches(string variant, string color)
+ {
+ var resting = FindStateBackground(variant, color, string.Empty);
+
+ if (resting is null)
+ {
+ return [$"{variant} {color} buttons have no resting background rule"];
+ }
+
+ return _interactionStates.Where(state => FindStateBackground(variant, color, state) == resting)
+ .Select(state => $"{variant} {color} buttons keep the resting background {resting} in the state {state}");
+ }
+
+ ///
+ /// Merge the declarations of the rules that style a button of a variant and color at rest
+ ///
+ /// Variant class suffix
+ /// Color class suffix
+ /// Property name to value
+ private static Dictionary GetRestingButtonDeclarations(string variant, string color)
+ {
+ var declarations = new Dictionary(StringComparer.Ordinal);
+
+ foreach (var rule in GetEntries().Where(rule => rule.Context.Length == 0 && IsButtonKind(rule.Entry, variant, color) && AppliesToState(rule.Entry, string.Empty)))
+ {
+ foreach (var (name, value) in ToDeclarationMap(rule.Body))
+ {
+ declarations[name] = value;
+ }
+ }
+
+ return declarations;
+ }
+
+ ///
+ /// Find the differences of the shape rules of a button kind: the rules without the enabled-only exclusion carry the shape, those with it carry none
+ ///
+ /// Variant class suffix
+ /// Color class suffix
+ /// One text per missing or different declaration or misplaced shape declaration
+ private static IEnumerable FindShapeMismatches(string variant, string color)
+ {
+ var subject = $"{variant} {color} button";
+ var kindRules = GetEntries().Where(rule => rule.Context.Length == 0 && IsButtonKind(rule.Entry, variant, color) && AppliesToState(rule.Entry, string.Empty))
+ .ToList();
+
+ var shape = new Dictionary(StringComparer.Ordinal);
+
+ foreach (var (name, value) in kindRules.Where(rule => rule.Entry.Contains(EnabledOnly, StringComparison.Ordinal) == false).SelectMany(rule => ToDeclarationMap(rule.Body)))
+ {
+ shape[name] = value;
+ }
+
+ var padding = GetHorizontalPadding(shape);
+ var misplaced = kindRules.Where(rule => rule.Entry.Contains(EnabledOnly, StringComparison.Ordinal))
+ .SelectMany(rule => ToDeclarationMap(rule.Body).Keys.Where(IsShapeProperty).Select(name => $"{rule.Entry} sets {name}, which belongs in a rule that reaches disabled buttons"));
+
+ return FindLengthMismatches(subject, shape, [("min-height", "44px")]).Concat(FindExactMismatches(subject, shape, [("border-radius", "var(--dug-radius-md)"), ("font-weight", "600")]))
+ .Concat(padding == ("18", "18") ? [] : [$"{subject}: horizontal padding is {padding}, expected 18px on both sides"])
+ .Concat(misplaced);
+ }
+
+ ///
+ /// Tell whether a property belongs to the shape of a button
+ ///
+ /// Property name
+ /// true for height, padding, radius and weight
+ private static bool IsShapeProperty(string name)
+ {
+ return name.StartsWith("padding", StringComparison.Ordinal) || name is "min-height" or "height" or "border-radius" or "font-weight";
+ }
+
+ ///
+ /// Find the differences of the primary button from the issue
+ ///
+ /// Declarations of the primary button at rest
+ /// One text per missing or different declaration
+ private static IEnumerable FindPrimaryButtonMismatches(Dictionary primary)
+ {
+ return FindExactMismatches("filled primary button", ReadBackground(primary), [("background", "var(--dug-primary)")]).Concat(FindExactMismatches("filled primary button", primary, [("color", "var(--dug-on-primary)")]));
+ }
+
+ ///
+ /// Find the differences of a secondary button from the issue
+ ///
+ /// Color class suffix of the outlined button
+ /// One text per missing or different declaration
+ private static IEnumerable FindSecondaryButtonMismatches(string color)
+ {
+ var subject = $"outlined {color} button";
+ var secondary = GetRestingButtonDeclarations("outlined", color);
+
+ return FindExactMismatches(subject, ReadBackground(secondary), [("background", "var(--dug-surface)")]).Concat(FindExactMismatches(subject, secondary, [("color", "var(--dug-text)")]))
+ .Concat(FindBorderMismatches(subject, secondary, "--dug-border-control"));
+ }
+
+ ///
+ /// Resolve the left and right padding of a rule
+ ///
+ /// Declarations
+ /// Left and right padding in pixels, empty where none is declared
+ private static (string Left, string Right) GetHorizontalPadding(Dictionary declarations)
+ {
+ var left = string.Empty;
+ var right = string.Empty;
+
+ if (declarations.TryGetValue("padding", out var padding))
+ {
+ var box = NormalizeLength("padding", padding).Split(' ');
+
+ left = box[^1];
+ right = box[Math.Min(1, box.Length - 1)];
+ }
+
+ if (declarations.TryGetValue("padding-inline", out var inline))
+ {
+ var pair = NormalizeLength(string.Empty, inline).Split(' ');
+
+ left = pair[0];
+ right = pair[^1];
+ }
+
+ left = declarations.TryGetValue("padding-left", out var paddingLeft) ? NormalizeLength(string.Empty, paddingLeft) : left;
+ right = declarations.TryGetValue("padding-right", out var paddingRight) ? NormalizeLength(string.Empty, paddingRight) : right;
+
+ return (left, right);
+ }
+
+ ///
+ /// Tell whether a selector styles an icon button outside the body rows of a table and apart from the shared class
+ ///
+ /// Selector
+ /// true when the selector names MudBlazor's icon button class without a body row or the shared class
+ private static bool IsOutsideBodyRows(string entry)
+ {
+ return entry.Contains(".mud-icon-button", StringComparison.Ordinal)
+ && entry.Contains(".section-table .mud-table-body ", StringComparison.Ordinal) == false
+ && entry.Contains(SharedIconButton, StringComparison.Ordinal) == false;
+ }
+
+ ///
+ /// Find the differences of an icon button family from the issue: 44 px, hairline border, radius and icon color, and that a rule of the family exists
+ ///
+ /// Icon button selectors with their rule bodies
+ /// Selector prefix of the family
+ /// One text per missing or different declaration
+ private static IEnumerable FindIconButtonMismatches(List<(string Entry, string Body, string Context)> entries, string prefix)
+ {
+ var family = entries.Where(rule => rule.Entry.StartsWith(prefix, StringComparison.Ordinal)).ToList();
+
+ if (family.Count == 0)
+ {
+ return [$"No rule styles {prefix}"];
+ }
+
+ var declarations = new Dictionary(StringComparer.Ordinal);
+
+ foreach (var (name, value) in family.SelectMany(rule => ToDeclarationMap(rule.Body)))
+ {
+ declarations[name] = value;
+ }
+
+ var sized = (declarations.ContainsKey("width") && declarations.ContainsKey("height")) ? ("width", "height") : ("min-width", "min-height");
+
+ return FindLengthMismatches(prefix, declarations, [(sized.Item1, "44px"), (sized.Item2, "44px")]).Concat(FindExactMismatches(prefix, declarations, [("border", HairlineBorder), ("border-radius", "var(--dug-radius-md)"), ("color", "var(--dug-icon)")]));
+ }
+
+ ///
+ /// Assert there is nothing to report
+ ///
+ /// Findings
+ /// What must hold
+ private static void AssertNoMismatches(IEnumerable mismatches, string message)
+ {
+ Assert.AreEqual(string.Empty, string.Join("; ", mismatches), message);
+ }
+
+ #endregion // Helper methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/AppStylesheetTests.cs b/src/Tests/DockerUpdateGuard.Tests/AppStylesheetTests.cs
index ef5909ca..051772d2 100644
--- a/src/Tests/DockerUpdateGuard.Tests/AppStylesheetTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/AppStylesheetTests.cs
@@ -192,6 +192,8 @@ public static IEnumerable GetContrastPairs()
yield return [theme, "--dug-on-primary", "--dug-primary"];
+ yield return [theme, "--dug-chip-high-fg", "--dug-surface"];
+
foreach (var chip in _chips)
{
yield return [theme, $"--dug-chip-{chip.Chip}-fg", $"--dug-chip-{chip.Chip}-bg"];
@@ -592,7 +594,7 @@ public void AppStylesheetWarningAndDangerCardsColorOnlyFigureAndIcon()
}
///
- /// Verify below 960 px a table row is a flat card: surface, hairline border, control radius
+ /// Verify below 960 px a table row is a flat card: surface, hairline border, panel radius
///
[TestMethod]
[TestCategory("AC7")]
@@ -607,7 +609,7 @@ public void AppStylesheetRowCardsBelowBreakpointAreFlatSurfaceCards()
var declarations = StylesheetReader.GetDeclarationList(body).ToDictionary(declaration => declaration.Name, declaration => declaration.Value);
- var mismatches = FindDeclarationMismatches("row card", declarations, [("border", HairlineBorder), ("border-radius", "var(--dug-radius-md)")]).Concat(FindDeclarationMismatches("row card", ReadBackground(declarations), [("background", "var(--dug-surface)")]))
+ var mismatches = FindDeclarationMismatches("row card", declarations, [("border", HairlineBorder), ("border-radius", "var(--dug-radius-lg)")]).Concat(FindDeclarationMismatches("row card", ReadBackground(declarations), [("background", "var(--dug-surface)")]))
.ToList();
AssertNoMismatches(mismatches, "A row card must be flat");
diff --git a/src/Tests/DockerUpdateGuard.Tests/PageHeaderSkeletonTests.cs b/src/Tests/DockerUpdateGuard.Tests/PageHeaderSkeletonTests.cs
index f37ccd53..c6a2b45d 100644
--- a/src/Tests/DockerUpdateGuard.Tests/PageHeaderSkeletonTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/PageHeaderSkeletonTests.cs
@@ -14,11 +14,12 @@ public class PageHeaderSkeletonTests
#region Methods
///
- /// Verify the header skeleton renders a hero panel with three placeholder bars
+ /// Verify the header skeleton has the shape of the page header with two placeholder bars
///
/// Task
[TestMethod]
- public async Task PageHeaderSkeletonRendersHeroPanelWithThreeBars()
+ [TestCategory("AC6")]
+ public async Task PageHeaderSkeletonRendersPageHeaderShape()
{
var testContext = BlazorTestContextFactory.Create();
@@ -27,8 +28,9 @@ public async Task PageHeaderSkeletonRendersHeroPanelWithThreeBars()
var component = testContext.Render();
var markup = component.Markup;
- Assert.Contains("hero-panel", markup, "The header skeleton must render inside the hero panel");
- Assert.AreEqual(3, MarkupTestHelper.CountSkeletons(markup), "The header skeleton must render three placeholder bars");
+ Assert.HasCount(1, component.FindAll("header.dug-page-header"), "The header skeleton must render the page header element");
+ Assert.DoesNotContain("hero-panel", markup, "The header skeleton must no longer render the hero panel");
+ Assert.AreEqual(2, MarkupTestHelper.CountSkeletons(markup), "The header skeleton must render a title and a description bar");
}
}
diff --git a/src/Tests/DockerUpdateGuard.Tests/PageHeaderTests.cs b/src/Tests/DockerUpdateGuard.Tests/PageHeaderTests.cs
new file mode 100644
index 00000000..b152906b
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/PageHeaderTests.cs
@@ -0,0 +1,85 @@
+using Bunit;
+
+using DockerUpdateGuard.Components.Common;
+using DockerUpdateGuard.Tests.Helper;
+
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for
+///
+[TestClass]
+public class PageHeaderTests
+{
+ #region Methods
+
+ ///
+ /// Verify a header with a title only renders one heading and none of the optional parts
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC6")]
+ public async Task PageHeaderTitleOnlyRendersOneHeadingWithoutOptionalParts()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(header => header.Title, "Dashboard"));
+ var headings = component.FindAll("h1");
+
+ Assert.HasCount(1, component.FindAll("header.dug-page-header"), "The header must render one header element");
+ Assert.HasCount(1, headings, "The header must render exactly one h1");
+ Assert.AreEqual("Dashboard", headings[0].TextContent, "The h1 must hold the title");
+ Assert.IsEmpty(component.FindAll(".dug-page-header__description"), "No description must render without one");
+ Assert.IsEmpty(component.FindAll(".dug-page-header__actions"), "No actions must render without any");
+ Assert.IsEmpty(component.FindAll(".dug-page-header__breadcrumb"), "No breadcrumb must render without one");
+ Assert.IsEmpty(component.FindAll("[class*=eyebrow]"), "The header must have no eyebrow label");
+ }
+ }
+
+ ///
+ /// Verify a header with every part renders each one in its place
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC6")]
+ public async Task PageHeaderAllPartsRendersDescriptionActionsBreadcrumbAndTitleContent()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(header => header.Title, "Images")
+ .Add(header => header.Description, "All observed images")
+ .Add(header => header.Actions, CreateFragment("Go "))
+ .Add(header => header.Breadcrumb, CreateFragment("Home "))
+ .Add(header => header.TitleContent, CreateFragment("")));
+
+ Assert.HasCount(1, component.FindAll("h1"), "The header must still render exactly one h1");
+ Assert.AreEqual("Images", component.Find("h1").TextContent, "The h1 must hold the title");
+ Assert.AreEqual("All observed images", component.Find("p.dug-page-header__description").TextContent, "The description must render below the title");
+ Assert.AreEqual("Go", component.Find(".dug-page-header__actions #act").TextContent, "The actions must render in the actions area");
+ Assert.AreEqual("Home", component.Find(".dug-page-header__breadcrumb #crumb").TextContent, "The breadcrumb must render in the breadcrumb area");
+ Assert.AreEqual("Beta", component.Find(".dug-page-header__title-row #extra").TextContent, "The title content must render in the title row");
+ }
+ }
+
+ #endregion // Methods
+
+ #region Static methods
+
+ ///
+ /// Create a render fragment from markup
+ ///
+ /// Markup
+ /// Fragment
+ private static RenderFragment CreateFragment(string markup)
+ {
+ return builder => builder.AddMarkupContent(0, markup);
+ }
+
+ #endregion // Static methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/ScanStatusIndicatorTests.cs b/src/Tests/DockerUpdateGuard.Tests/ScanStatusIndicatorTests.cs
new file mode 100644
index 00000000..00cec06b
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/ScanStatusIndicatorTests.cs
@@ -0,0 +1,49 @@
+using Bunit;
+
+using DockerUpdateGuard.Components.Common;
+using DockerUpdateGuard.Tests.Helper;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for
+///
+[TestClass]
+public class ScanStatusIndicatorTests
+{
+ #region Methods
+
+ ///
+ /// Verify the indicator renders a hidden dot, the status text and the class of the status tone
+ ///
+ /// Scan status text
+ /// Expected class attribute of the indicator
+ /// Task
+ [TestMethod]
+ [TestCategory("AC4")]
+ [DataRow("Succeeded", "dug-status dug-status--success")]
+ [DataRow("Partial", "dug-status dug-status--warning")]
+ [DataRow("Failed", "dug-status dug-status--danger")]
+ [DataRow("Running", "dug-status dug-status--info")]
+ [DataRow("Pending", "dug-status dug-status--neutral")]
+ [DataRow("NotScanned", "dug-status dug-status--neutral")]
+ [DataRow("Something else", "dug-status dug-status--neutral")]
+ public async Task ScanStatusIndicatorStatusRendersDotAndText(string status, string expectedClass)
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(indicator => indicator.Status, status));
+ var root = component.Find(".dug-status");
+ var dot = component.Find(".dug-status__dot");
+ var text = component.Find(".dug-status__text");
+
+ Assert.AreEqual(expectedClass, root.GetAttribute("class"), $"Status '{status}' must carry its tone class");
+ Assert.AreEqual("true", dot.GetAttribute("aria-hidden"), "The dot must be hidden from assistive technology");
+ Assert.AreEqual(status, text.TextContent, "The indicator must show the status text");
+ }
+ }
+
+ #endregion // Methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/SectionPanelTests.cs b/src/Tests/DockerUpdateGuard.Tests/SectionPanelTests.cs
new file mode 100644
index 00000000..26d484c1
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/SectionPanelTests.cs
@@ -0,0 +1,116 @@
+using Bunit;
+
+using DockerUpdateGuard.Components.Common;
+using DockerUpdateGuard.Tests.Helper;
+
+using Microsoft.AspNetCore.Components;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for
+///
+[TestClass]
+public class SectionPanelTests
+{
+ #region Methods
+
+ ///
+ /// Verify a panel with a title only renders one section heading and its content
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC7")]
+ public async Task SectionPanelTitleOnlyRendersOneSectionHeadingAndContent()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(panel => panel.Title, "Findings")
+ .Add(panel => panel.ChildContent, CreateFragment("Content
")));
+
+ Assert.AreEqual("dug-panel", component.Find("section").GetAttribute("class"), "The panel must be a section with the panel class only");
+ Assert.HasCount(1, component.FindAll("h2"), "The panel must render exactly one h2");
+ Assert.AreEqual("Findings", component.Find(".dug-panel__header h2.dug-panel__title").TextContent, "The h2 must hold the title in the header");
+ Assert.AreEqual("Content", component.Find(".dug-panel__body #body").TextContent, "The content must render in the body");
+ Assert.IsEmpty(component.FindAll(".dug-panel__meta"), "No meta text must render without one");
+ Assert.IsEmpty(component.FindAll(".dug-panel__header-content"), "No header content must render without any");
+ }
+ }
+
+ ///
+ /// Verify the meta text renders beside the title
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC7")]
+ public async Task SectionPanelMetaRendersMuted()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(panel => panel.Title, "Findings")
+ .Add(panel => panel.Meta, "12 findings"));
+
+ Assert.AreEqual("12 findings", component.Find(".dug-panel__header span.dug-panel__meta").TextContent, "The meta text must render in the header");
+ }
+ }
+
+ ///
+ /// Verify the header content replaces the meta text when both are given
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC7")]
+ public async Task SectionPanelHeaderContentReplacesMeta()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(panel => panel.Title, "Findings")
+ .Add(panel => panel.Meta, "12 findings")
+ .Add(panel => panel.HeaderContent, CreateFragment("Filter ")));
+
+ Assert.AreEqual("Filter", component.Find(".dug-panel__header .dug-panel__header-content #hdr").TextContent, "The header content must render in the header");
+ Assert.IsEmpty(component.FindAll(".dug-panel__meta"), "The meta text must not render beside header content");
+ }
+ }
+
+ ///
+ /// Verify the flush variant adds the flush class
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC7")]
+ public async Task SectionPanelFlushAddsFlushClass()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(panel => panel.Title, "Findings")
+ .Add(panel => panel.Flush, true));
+
+ Assert.AreEqual("dug-panel dug-panel--flush", component.Find("section").GetAttribute("class"), "The flush panel must carry the flush class");
+ }
+ }
+
+ #endregion // Methods
+
+ #region Static methods
+
+ ///
+ /// Create a render fragment from markup
+ ///
+ /// Markup
+ /// Fragment
+ private static RenderFragment CreateFragment(string markup)
+ {
+ return builder => builder.AddMarkupContent(0, markup);
+ }
+
+ #endregion // Static methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/SeverityBarTests.cs b/src/Tests/DockerUpdateGuard.Tests/SeverityBarTests.cs
new file mode 100644
index 00000000..3cca53cd
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/SeverityBarTests.cs
@@ -0,0 +1,176 @@
+using AngleSharp.Dom;
+
+using Bunit;
+
+using DockerUpdateGuard.Components.Common;
+using DockerUpdateGuard.Tests.Helper;
+using DockerUpdateGuard.UI;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for
+///
+[TestClass]
+public class SeverityBarTests
+{
+ #region Methods
+
+ ///
+ /// Verify a summary with every severity renders weighted segments, the legend and the spoken label
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC5")]
+ public async Task SeverityBarAllSeveritiesRendersWeightedSegmentsLegendAndLabel()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var summary = CreateSummary(2, 9, 14, 6, 0);
+
+ var component = testContext.Render(parameters => parameters.Add(bar => bar.Summary, summary));
+ var segments = component.FindAll(".dug-severity__segment");
+ var legend = component.FindAll(".dug-severity__legend span");
+ var bar = component.Find(".dug-severity__bar");
+
+ Assert.AreEqual("dug-severity__segment dug-severity__segment--critical|dug-severity__segment dug-severity__segment--high|dug-severity__segment dug-severity__segment--medium|dug-severity__segment dug-severity__segment--low", string.Join('|', segments.Select(segment => segment.GetAttribute("class"))), "The segments must follow the order critical, high, medium, low");
+ Assert.AreEqual("2|9|14|6", string.Join('|', GetWeights(segments)), "Every segment's flex weight must equal its count");
+ Assert.AreEqual("2 critical|9 high|14 medium|6 low", string.Join('|', legend.Select(item => item.TextContent)), "The legend must list the counts in severity order");
+ Assert.AreEqual("img", bar.GetAttribute("role"), "The bar must be an image for assistive technology");
+ Assert.AreEqual("Severity distribution: 2 critical, 9 high, 14 medium, 6 low", bar.GetAttribute("aria-label"), "The bar must speak the distribution");
+ }
+ }
+
+ ///
+ /// Verify only severities with findings render a segment and a legend entry
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC5")]
+ public async Task SeverityBarSomeSeveritiesRendersOnlyNonZero()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var summary = CreateSummary(0, 3, 0, 1, 0);
+
+ var component = testContext.Render(parameters => parameters.Add(bar => bar.Summary, summary));
+ var segments = component.FindAll(".dug-severity__segment");
+
+ Assert.HasCount(2, segments, "Only the non-zero severities must render a segment");
+ Assert.AreEqual("3|1", string.Join('|', GetWeights(segments)), "The segments must carry their counts as weights");
+ Assert.AreEqual("Severity distribution: 3 high, 1 low", component.Find(".dug-severity__bar").GetAttribute("aria-label"), "The label must list only the non-zero severities");
+ Assert.HasCount(2, component.FindAll(".dug-severity__legend span"), "The legend must list only the non-zero severities");
+ }
+ }
+
+ ///
+ /// Verify other severities are counted as low
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC5")]
+ public async Task SeverityBarOtherSeverityCountsAsLow()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var otherOnly = testContext.Render(parameters => parameters.Add(bar => bar.Summary, CreateSummary(0, 0, 0, 0, 4)));
+ var lowAndOther = testContext.Render(parameters => parameters.Add(bar => bar.Summary, CreateSummary(0, 0, 0, 2, 3)));
+
+ var otherSegments = otherOnly.FindAll(".dug-severity__segment");
+ var mixedSegments = lowAndOther.FindAll(".dug-severity__segment");
+
+ Assert.HasCount(1, otherSegments, "Other severities alone must render one low segment");
+ Assert.IsTrue(otherSegments[0].ClassList.Contains("dug-severity__segment--low"), "The segment of other severities must be a low segment");
+ Assert.AreEqual("4", string.Join('|', GetWeights(otherSegments)), "The low weight must be the other count");
+ Assert.AreEqual("4 low", otherOnly.Find(".dug-severity__legend span").TextContent, "The legend must read '4 low'");
+ Assert.HasCount(1, mixedSegments, "Low and other findings must share one segment");
+ Assert.AreEqual("5", string.Join('|', GetWeights(mixedSegments)), "The low weight must be the low count plus the other count");
+ Assert.AreEqual("Severity distribution: 5 low", lowAndOther.Find(".dug-severity__bar").GetAttribute("aria-label"), "The label must count other severities as low");
+ }
+ }
+
+ ///
+ /// Verify a very unequal summary keeps every segment with its own weight
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC5")]
+ public async Task SeverityBarUnequalCountsKeepsEverySegment()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var summary = CreateSummary(1, 0, 0, 500, 0);
+
+ var component = testContext.Render(parameters => parameters.Add(bar => bar.Summary, summary));
+
+ Assert.AreEqual("1|500", string.Join('|', GetWeights(component.FindAll(".dug-severity__segment"))), "Both segments must be rendered with their counts as weights");
+ }
+ }
+
+ ///
+ /// Verify an empty or missing summary renders nothing
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC5")]
+ public async Task SeverityBarEmptyOrMissingSummaryRendersNothing()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var empty = testContext.Render(parameters => parameters.Add(bar => bar.Summary, CreateSummary(0, 0, 0, 0, 0)));
+ var missing = testContext.Render();
+
+ Assert.AreEqual(string.Empty, empty.Markup.Trim(), "A summary without findings must render nothing");
+ Assert.AreEqual(string.Empty, missing.Markup.Trim(), "A missing summary must render nothing");
+ }
+ }
+
+ #endregion // Methods
+
+ #region Static methods
+
+ ///
+ /// Create a severity summary
+ ///
+ /// Critical count
+ /// High count
+ /// Medium count
+ /// Low count
+ /// Other count
+ /// Summary
+ private static VulnerabilitySeveritySummaryViewData CreateSummary(int critical, int high, int medium, int low, int other)
+ {
+ return new VulnerabilitySeveritySummaryViewData
+ {
+ CriticalCount = critical,
+ HighCount = high,
+ MediumCount = medium,
+ LowCount = low,
+ OtherCount = other,
+ };
+ }
+
+ ///
+ /// Read the flex weights of segments
+ ///
+ /// Segment elements
+ /// Weights
+ private static IEnumerable GetWeights(IEnumerable segments)
+ {
+ return segments.Select(segment => segment.GetAttribute("style") ?? string.Empty)
+ .Select(style => style.Replace("flex-grow:", string.Empty, StringComparison.Ordinal).Replace(";", string.Empty, StringComparison.Ordinal).Trim())
+ .Select(int.Parse);
+ }
+
+ #endregion // Static methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/StatusChipTests.cs b/src/Tests/DockerUpdateGuard.Tests/StatusChipTests.cs
new file mode 100644
index 00000000..430fc562
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/StatusChipTests.cs
@@ -0,0 +1,72 @@
+using Bunit;
+
+using DockerUpdateGuard.Components.Common;
+using DockerUpdateGuard.Tests.Helper;
+using DockerUpdateGuard.UI;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for
+///
+[TestClass]
+public class StatusChipTests
+{
+ #region Methods
+
+ ///
+ /// Verify the chip renders its text with exactly the class of its tone
+ ///
+ /// Tone
+ /// Expected class attribute
+ /// Task
+ [TestMethod]
+ [TestCategory("AC3")]
+ [DataRow(StatusTone.Neutral, "dug-chip dug-chip--neutral")]
+ [DataRow(StatusTone.Info, "dug-chip dug-chip--info")]
+ [DataRow(StatusTone.Success, "dug-chip dug-chip--success")]
+ [DataRow(StatusTone.Warning, "dug-chip dug-chip--warning")]
+ [DataRow(StatusTone.Danger, "dug-chip dug-chip--danger")]
+ [DataRow(StatusTone.Critical, "dug-chip dug-chip--critical")]
+ [DataRow(StatusTone.High, "dug-chip dug-chip--high")]
+ [DataRow(StatusTone.Medium, "dug-chip dug-chip--medium")]
+ [DataRow(StatusTone.Low, "dug-chip dug-chip--low")]
+ public async Task StatusChipToneRendersToneClassAndText(StatusTone tone, string expectedClass)
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(chip => chip.Text, "Some text")
+ .Add(chip => chip.Tone, tone));
+ var chip = component.Find("span");
+
+ Assert.AreEqual(expectedClass, chip.GetAttribute("class"), $"The chip of tone {tone} must carry exactly its tone class");
+ Assert.AreEqual("Some text", chip.TextContent, "The chip must show its text");
+ }
+ }
+
+ ///
+ /// Verify markup characters in the text are shown as text
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC3")]
+ public async Task StatusChipMarkupTextIsEncoded()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ const string text = "bold & more";
+
+ var component = testContext.Render(parameters => parameters.Add(chip => chip.Text, text)
+ .Add(chip => chip.Tone, StatusTone.Info));
+
+ Assert.IsEmpty(component.FindAll("b"), "Markup in the text must not become an element");
+ Assert.AreEqual(text, component.Find("span").TextContent, "The text must be shown literally");
+ }
+ }
+
+ #endregion // Methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/StatusToneFormatterTests.cs b/src/Tests/DockerUpdateGuard.Tests/StatusToneFormatterTests.cs
new file mode 100644
index 00000000..465c03e0
--- /dev/null
+++ b/src/Tests/DockerUpdateGuard.Tests/StatusToneFormatterTests.cs
@@ -0,0 +1,246 @@
+using DockerUpdateGuard.UI;
+
+namespace DockerUpdateGuard.Tests;
+
+///
+/// Tests for
+///
+[TestClass]
+public class StatusToneFormatterTests
+{
+ #region Methods
+
+ ///
+ /// Verify every status value of the mapping table maps to its tone, in any letter case
+ ///
+ /// Status text
+ /// Expected tone
+ [TestMethod]
+ [TestCategory("AC1")]
+ [DataRow("Succeeded", StatusTone.Success)]
+ [DataRow("Partial", StatusTone.Warning)]
+ [DataRow("Failed", StatusTone.Danger)]
+ [DataRow("Running", StatusTone.Info)]
+ [DataRow("Pending", StatusTone.Neutral)]
+ [DataRow("NotSet", StatusTone.Neutral)]
+ [DataRow("NotScanned", StatusTone.Neutral)]
+ [DataRow("Update available", StatusTone.Warning)]
+ [DataRow("Up to date", StatusTone.Success)]
+ [DataRow("Manual review required", StatusTone.Info)]
+ [DataRow("No tag data", StatusTone.Neutral)]
+ [DataRow("Not evaluated", StatusTone.Neutral)]
+ [DataRow("Unsupported", StatusTone.Neutral)]
+ [DataRow("No findings", StatusTone.Success)]
+ [DataRow("Not scanned", StatusTone.Neutral)]
+ [DataRow("Not configured", StatusTone.Neutral)]
+ [DataRow("Unavailable", StatusTone.Neutral)]
+ [DataRow("Paused", StatusTone.Warning)]
+ [DataRow("Restarting", StatusTone.Warning)]
+ [DataRow("Exited", StatusTone.Neutral)]
+ [DataRow("Dead", StatusTone.Neutral)]
+ public void StatusToneFormatterGetStatusToneKnownValueReturnsTone(string status, StatusTone expectedTone)
+ {
+ var exact = StatusToneFormatter.GetStatusTone(status);
+ var upper = StatusToneFormatter.GetStatusTone(status.ToUpperInvariant());
+ var lower = StatusToneFormatter.GetStatusTone(status.ToLowerInvariant());
+
+ Assert.AreEqual(expectedTone, exact, $"Status '{status}' must map to {expectedTone}");
+ Assert.AreEqual(expectedTone, upper, $"Upper-case status '{status}' must map to {expectedTone}");
+ Assert.AreEqual(expectedTone, lower, $"Lower-case status '{status}' must map to {expectedTone}");
+ }
+
+ ///
+ /// Verify status values in mixed letter case map to their tone
+ ///
+ [TestMethod]
+ [TestCategory("AC1")]
+ public void StatusToneFormatterGetStatusToneMixedCaseValueReturnsTone()
+ {
+ Assert.AreEqual(StatusTone.Danger, StatusToneFormatter.GetStatusTone("fAiLeD"), "Mixed-case 'Failed' must be Danger");
+ Assert.AreEqual(StatusTone.Warning, StatusToneFormatter.GetStatusTone("uPdAtE aVaIlAbLe"), "Mixed-case 'Update available' must be Warning");
+ Assert.AreEqual(StatusTone.Info, StatusToneFormatter.GetStatusTone("rUnNiNg"), "Mixed-case 'Running' must be Info");
+ }
+
+ ///
+ /// Verify unknown, empty and missing values map to the neutral tone
+ ///
+ /// Status text
+ [TestMethod]
+ [TestCategory("AC1")]
+ [DataRow(null)]
+ [DataRow("")]
+ [DataRow(" ")]
+ [DataRow("NotSet")]
+ [DataRow("Completed")]
+ public void StatusToneFormatterGetStatusToneUnknownOrEmptyValueReturnsNeutral(string? status)
+ {
+ var tone = StatusToneFormatter.GetStatusTone(status);
+
+ Assert.AreEqual(StatusTone.Neutral, tone, $"Status '{status}' must map to Neutral");
+ }
+
+ ///
+ /// Verify the four known severities map to the same severity tone, in any letter case
+ ///
+ /// Severity text
+ /// Expected tone
+ [TestMethod]
+ [TestCategory("AC1")]
+ [DataRow("Critical", StatusTone.Critical)]
+ [DataRow("High", StatusTone.High)]
+ [DataRow("Medium", StatusTone.Medium)]
+ [DataRow("Low", StatusTone.Low)]
+ public void StatusToneFormatterGetSeverityToneKnownSeverityReturnsSameSeverity(string severity, StatusTone expectedTone)
+ {
+ var exact = StatusToneFormatter.GetSeverityTone(severity);
+ var upper = StatusToneFormatter.GetSeverityTone(severity.ToUpperInvariant());
+ var lower = StatusToneFormatter.GetSeverityTone(severity.ToLowerInvariant());
+
+ Assert.AreEqual(expectedTone, exact, $"Severity '{severity}' must map to {expectedTone}");
+ Assert.AreEqual(expectedTone, upper, $"Upper-case severity '{severity}' must map to {expectedTone}");
+ Assert.AreEqual(expectedTone, lower, $"Lower-case severity '{severity}' must map to {expectedTone}");
+ }
+
+ ///
+ /// Verify every other severity value maps to the low tone
+ ///
+ /// Severity text
+ [TestMethod]
+ [TestCategory("AC1")]
+ [DataRow(null)]
+ [DataRow("")]
+ [DataRow("Unknown")]
+ [DataRow("Negligible")]
+ public void StatusToneFormatterGetSeverityToneOtherValueReturnsLow(string? severity)
+ {
+ var tone = StatusToneFormatter.GetSeverityTone(severity);
+
+ Assert.AreEqual(StatusTone.Low, tone, $"Severity '{severity}' must map to Low");
+ }
+
+ ///
+ /// Verify detected findings take the tone of the highest severity with a count above zero
+ ///
+ /// Critical count
+ /// High count
+ /// Medium count
+ /// Low count
+ /// Other count
+ /// Expected tone
+ [TestMethod]
+ [TestCategory("AC2")]
+ [DataRow(1, 0, 0, 0, 0, StatusTone.Critical)]
+ [DataRow(2, 9, 14, 6, 3, StatusTone.Critical)]
+ [DataRow(0, 1, 0, 0, 0, StatusTone.High)]
+ [DataRow(0, 3, 5, 7, 0, StatusTone.High)]
+ [DataRow(0, 0, 1, 0, 0, StatusTone.Medium)]
+ [DataRow(0, 0, 4, 2, 1, StatusTone.Medium)]
+ [DataRow(0, 0, 0, 1, 0, StatusTone.Low)]
+ [DataRow(0, 0, 0, 5, 2, StatusTone.Low)]
+ public void StatusToneFormatterGetStatusToneFindingsDetectedReturnsHighestSeverity(int critical, int high, int medium, int low, int other, StatusTone expectedTone)
+ {
+ var summary = CreateSummary(critical, high, medium, low, other);
+
+ var exact = StatusToneFormatter.GetStatusTone("Findings detected", summary);
+ var mixed = StatusToneFormatter.GetStatusTone("fINDINGS dETECTED", summary);
+
+ Assert.AreEqual(expectedTone, exact, $"Findings detected with {critical}/{high}/{medium}/{low}/{other} must map to {expectedTone}");
+ Assert.AreEqual(expectedTone, mixed, $"Mixed-case findings detected with {critical}/{high}/{medium}/{low}/{other} must map to {expectedTone}");
+ }
+
+ ///
+ /// Verify detected findings without a counted known severity map to the low tone
+ ///
+ [TestMethod]
+ [TestCategory("AC2")]
+ public void StatusToneFormatterGetStatusToneFindingsDetectedWithoutKnownSeverityReturnsLow()
+ {
+ var otherOnly = StatusToneFormatter.GetStatusTone("Findings detected", CreateSummary(0, 0, 0, 0, 4));
+ var empty = StatusToneFormatter.GetStatusTone("Findings detected", CreateSummary(0, 0, 0, 0, 0));
+ var missing = StatusToneFormatter.GetStatusTone("Findings detected", null);
+ var oneArgument = StatusToneFormatter.GetStatusTone("Findings detected");
+
+ Assert.AreEqual(StatusTone.Low, otherOnly, "A summary with only other severities must map to Low");
+ Assert.AreEqual(StatusTone.Low, empty, "An empty summary must map to Low");
+ Assert.AreEqual(StatusTone.Low, missing, "A missing summary must map to Low");
+ Assert.AreEqual(StatusTone.Low, oneArgument, "The one-argument overload must map to Low");
+ }
+
+ ///
+ /// Verify any other status ignores the severity summary
+ ///
+ [TestMethod]
+ [TestCategory("AC2")]
+ public void StatusToneFormatterGetStatusToneOtherStatusIgnoresSummary()
+ {
+ var summary = CreateSummary(3, 2, 1, 0, 0);
+
+ var failed = StatusToneFormatter.GetStatusTone("Failed", summary);
+ var noFindings = StatusToneFormatter.GetStatusTone("No findings", summary);
+
+ Assert.AreEqual(StatusTone.Danger, failed, "Failed must stay Danger whatever the summary holds");
+ Assert.AreEqual(StatusTone.Success, noFindings, "No findings must stay Success whatever the summary holds");
+ }
+
+ ///
+ /// Verify every tone maps to its lowercase CSS name
+ ///
+ /// Tone
+ /// Expected CSS name
+ [TestMethod]
+ [TestCategory("AC3")]
+ [DataRow(StatusTone.Neutral, "neutral")]
+ [DataRow(StatusTone.Info, "info")]
+ [DataRow(StatusTone.Success, "success")]
+ [DataRow(StatusTone.Warning, "warning")]
+ [DataRow(StatusTone.Danger, "danger")]
+ [DataRow(StatusTone.Critical, "critical")]
+ [DataRow(StatusTone.High, "high")]
+ [DataRow(StatusTone.Medium, "medium")]
+ [DataRow(StatusTone.Low, "low")]
+ public void StatusToneFormatterGetCssNameKnownToneReturnsLowercaseName(StatusTone tone, string expectedName)
+ {
+ var name = StatusToneFormatter.GetCssName(tone);
+
+ Assert.AreEqual(expectedName, name, $"Tone {tone} must map to '{expectedName}'");
+ }
+
+ ///
+ /// Verify an undefined tone value maps to the neutral CSS name
+ ///
+ [TestMethod]
+ [TestCategory("AC3")]
+ public void StatusToneFormatterGetCssNameUndefinedToneReturnsNeutral()
+ {
+ var name = StatusToneFormatter.GetCssName((StatusTone)999);
+
+ Assert.AreEqual("neutral", name, "An undefined tone must map to 'neutral'");
+ }
+
+ #endregion // Methods
+
+ #region Static methods
+
+ ///
+ /// Create a severity summary
+ ///
+ /// Critical count
+ /// High count
+ /// Medium count
+ /// Low count
+ /// Other count
+ /// Summary
+ private static VulnerabilitySeveritySummaryViewData CreateSummary(int critical, int high, int medium, int low, int other)
+ {
+ return new VulnerabilitySeveritySummaryViewData
+ {
+ CriticalCount = critical,
+ HighCount = high,
+ MediumCount = medium,
+ LowCount = low,
+ OtherCount = other,
+ };
+ }
+
+ #endregion // Static methods
+}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/TableSkeletonTests.cs b/src/Tests/DockerUpdateGuard.Tests/TableSkeletonTests.cs
index 784b4f1a..f797f310 100644
--- a/src/Tests/DockerUpdateGuard.Tests/TableSkeletonTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/TableSkeletonTests.cs
@@ -14,10 +14,11 @@ public class TableSkeletonTests
#region Methods
///
- /// Verify the table skeleton renders the requested number of row placeholders inside a section paper
+ /// Verify the table skeleton renders the requested number of row placeholders inside a panel
///
/// Task
[TestMethod]
+ [TestCategory("AC7")]
public async Task TableSkeletonRendersRequestedRowCount()
{
var testContext = BlazorTestContextFactory.Create();
@@ -27,11 +28,34 @@ public async Task TableSkeletonRendersRequestedRowCount()
var component = testContext.Render(parameters => parameters.Add(skeleton => skeleton.Rows, 4));
var markup = component.Markup;
- Assert.Contains("section-paper", markup, "The table skeleton must render inside a section paper");
+ Assert.HasCount(1, component.FindAll("section.dug-panel"), "The table skeleton must render inside a panel");
+ Assert.DoesNotContain("section-paper", markup, "The table skeleton must no longer render a section paper");
Assert.AreEqual(4, MarkupTestHelper.CountSkeletons(markup), "The table skeleton must render one placeholder per requested row");
}
}
+ ///
+ /// Verify the table skeleton has the shape of the section panel
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC7")]
+ public async Task TableSkeletonRendersPanelShape()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var component = testContext.Render(parameters => parameters.Add(skeleton => skeleton.Rows, 3)
+ .Add(skeleton => skeleton.Title, "Overview"));
+
+ Assert.HasCount(1, component.FindAll("section.dug-panel"), "The skeleton must render the panel element");
+ Assert.HasCount(1, component.FindAll(".dug-panel__header .mud-skeleton"), "The panel header must hold the title placeholder");
+ Assert.HasCount(3, component.FindAll(".dug-panel__body .mud-skeleton"), "The panel body must hold one placeholder per row");
+ Assert.DoesNotContain("section-paper", component.Markup, "The skeleton must no longer render a section paper");
+ }
+ }
+
///
/// Verify the table skeleton defaults to five row placeholders
///
@@ -70,11 +94,12 @@ public async Task TableSkeletonWithTitleRendersOneExtraBar()
}
///
- /// Verify the embedded variant renders the row placeholders without the surrounding section paper
+ /// Verify the embedded variant renders the row placeholders without the surrounding panel
///
/// Task
[TestMethod]
- public async Task TableSkeletonEmbeddedOmitsSectionPaper()
+ [TestCategory("AC7")]
+ public async Task TableSkeletonEmbeddedOmitsPanel()
{
var testContext = BlazorTestContextFactory.Create();
@@ -83,7 +108,8 @@ public async Task TableSkeletonEmbeddedOmitsSectionPaper()
var component = testContext.Render(parameters => parameters.Add(skeleton => skeleton.Embedded, true));
var markup = component.Markup;
- Assert.DoesNotContain("section-paper", markup, "The embedded table skeleton must not render the surrounding section paper");
+ Assert.DoesNotContain("section-paper", markup, "The embedded table skeleton must not render a section paper");
+ Assert.DoesNotContain("dug-panel", markup, "The embedded table skeleton must not render the surrounding panel");
Assert.AreEqual(5, MarkupTestHelper.CountSkeletons(markup), "The embedded table skeleton must still render its row placeholders");
}
}
diff --git a/src/Tests/DockerUpdateGuard.Tests/VulnerabilityAssessmentCardTests.cs b/src/Tests/DockerUpdateGuard.Tests/VulnerabilityAssessmentCardTests.cs
index a10ae43a..ff4ea3b8 100644
--- a/src/Tests/DockerUpdateGuard.Tests/VulnerabilityAssessmentCardTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/VulnerabilityAssessmentCardTests.cs
@@ -320,5 +320,54 @@ public async Task VulnerabilityAssessmentCardNullAssessmentRendersNothing()
}
}
+ ///
+ /// Verify the status chip follows the mapping and the scan delta chips use their tones
+ ///
+ /// Assessment status text
+ /// Expected class attribute of the status chip
+ /// Task
+ [TestMethod]
+ [TestCategory("AC11")]
+ [DataRow("Findings detected", "dug-chip dug-chip--high")]
+ [DataRow("Failed", "dug-chip dug-chip--danger")]
+ [DataRow("No findings", "dug-chip dug-chip--success")]
+ [DataRow("Not scanned", "dug-chip dug-chip--neutral")]
+ public async Task VulnerabilityAssessmentCardChipsUseTones(string status, string expectedClass)
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var assessment = CreateAssessment();
+
+ assessment.Status = status;
+ assessment.SeveritySummary.CriticalCount = 0;
+ assessment.SeveritySummary.MediumCount = 12;
+
+ var component = testContext.Render(parameters => parameters.Add(card => card.Assessment, assessment));
+
+ await component.Find("button.summary-card__detail-toggle")
+ .ClickAsync()
+ .ConfigureAwait(false);
+
+ Assert.AreEqual(expectedClass, GetChipClass(component, status), $"The status '{status}' chip must follow the tone mapping");
+ Assert.AreEqual("dug-chip dug-chip--danger", GetChipClass(component, "+2 since last scan"), "The new findings chip must use the danger tone");
+ Assert.AreEqual("dug-chip dug-chip--success", GetChipClass(component, "−3 fixed since last scan"), "The fixed findings chip must use the success tone");
+ }
+ }
+
+ ///
+ /// Read the class attribute of the status chip that shows a text
+ ///
+ /// Rendered component
+ /// Chip text
+ /// Class attribute
+ private static string GetChipClass(IRenderedComponent component, string text)
+ {
+ return component.FindAll(".dug-chip")
+ .Single(chip => chip.TextContent.Trim() == text)
+ .GetAttribute("class") ?? string.Empty;
+ }
+
#endregion // Methods
}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/VulnerabilityFindingsTableTests.cs b/src/Tests/DockerUpdateGuard.Tests/VulnerabilityFindingsTableTests.cs
index 96c2febb..de91c414 100644
--- a/src/Tests/DockerUpdateGuard.Tests/VulnerabilityFindingsTableTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/VulnerabilityFindingsTableTests.cs
@@ -259,6 +259,64 @@ public async Task VulnerabilityFindingsTableShowResolvedRendersOptionalDetailsAn
}
}
+ ///
+ /// Verify severity, new, active and resolved chips are status chips in their tones
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC11")]
+ public async Task VulnerabilityFindingsTableChipsUseTones()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var critical = CreateFinding("CVE-2026-0001", isActive: true);
+ var medium = CreateFinding("CVE-2026-0002", isActive: false);
+
+ critical.Severity = "Critical";
+ critical.IsNewSinceLastScan = true;
+ medium.Severity = "Medium";
+
+ List findings = [critical, medium];
+
+ var component = testContext.Render(parameters => parameters.Add(table => table.Findings, findings));
+
+ SetPrivateField(component.Instance, "_showResolved", true);
+ component.Render();
+
+ var severityClasses = component.FindAll("td[data-label='Severity'] .dug-chip").Select(chip => chip.GetAttribute("class"));
+ var statusClasses = component.FindAll("td[data-label='Status'] .dug-chip").Select(chip => chip.GetAttribute("class"));
+
+ Assert.AreEqual("dug-chip dug-chip--critical|dug-chip dug-chip--medium", string.Join('|', severityClasses), "Severity chips must use their severity tones");
+ Assert.AreEqual("dug-chip dug-chip--warning|dug-chip dug-chip--neutral", string.Join('|', statusClasses), "Active must be warning and resolved neutral");
+ Assert.AreEqual("dug-chip dug-chip--danger", component.Find("td[data-label='Advisory'] .dug-chip").GetAttribute("class"), "The New chip must use the danger tone");
+ }
+ }
+
+ ///
+ /// Verify the search field is an outlined field
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC9")]
+ public async Task VulnerabilityFindingsTableSearchFieldIsOutlined()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var findings = new List
+ {
+ CreateFinding("CVE-2026-0001", isActive: true)
+ };
+
+ var component = testContext.Render(parameters => parameters.Add(table => table.Findings, findings));
+
+ Assert.HasCount(1, component.FindAll(".mud-input.mud-input-outlined"), "The search field must be outlined");
+ }
+ }
+
///
/// Set a private field via reflection
///
diff --git a/src/Tests/DockerUpdateGuard.Tests/VulnerabilityRescanControlTests.cs b/src/Tests/DockerUpdateGuard.Tests/VulnerabilityRescanControlTests.cs
index 3673cb05..4b2ff4ff 100644
--- a/src/Tests/DockerUpdateGuard.Tests/VulnerabilityRescanControlTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/VulnerabilityRescanControlTests.cs
@@ -10,6 +10,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
+using MudBlazor;
+
using NSubstitute;
namespace DockerUpdateGuard.Tests;
@@ -149,5 +151,59 @@ public async Task VulnerabilityRescanControlWithoutCheckedAtShowsNeverScannedAsy
}
}
+ ///
+ /// Verify the rescan button is labelled for assistive technology and sits in its tooltip
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC10")]
+ public async Task VulnerabilityRescanControlButtonHasAriaLabelAndTooltip()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ testContext.Services.AddSingleton(Substitute.For());
+
+ var component = testContext.Render(parameters => parameters.Add(control => control.ImageVersionId, Guid.NewGuid()));
+ var tooltip = component.FindComponent();
+
+ Assert.AreEqual("Rescan vulnerabilities", component.Find("button").GetAttribute("aria-label"), "The icon button must be announced as 'Rescan vulnerabilities'");
+ Assert.AreEqual("Rescan for vulnerabilities now", tooltip.Instance.Text, "The button must keep its tooltip text");
+ }
+ }
+
+ ///
+ /// Verify the rescan button stays disabled while a rescan runs and is enabled again afterwards
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC10")]
+ public async Task VulnerabilityRescanControlRunningRescanDisablesButton()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var enrichmentService = Substitute.For();
+ var gate = new TaskCompletionSource();
+
+ enrichmentService.RefreshImageVersionAsync(Arg.Any(), Arg.Any(), Arg.Any())
+ .Returns(gate.Task);
+
+ testContext.Services.AddSingleton(enrichmentService);
+
+ var component = testContext.Render(parameters => parameters.Add(control => control.ImageVersionId, Guid.NewGuid()));
+ var click = component.Find("button").ClickAsync();
+
+ await component.WaitForAssertionAsync(() => Assert.IsTrue(component.Find("button").HasAttribute("disabled"), "The button must be disabled while the rescan runs")).ConfigureAwait(false);
+
+ gate.SetResult();
+ await click.ConfigureAwait(false);
+
+ await component.WaitForAssertionAsync(() => Assert.IsFalse(component.Find("button").HasAttribute("disabled"), "The button must be enabled again after the rescan completes")).ConfigureAwait(false);
+ }
+ }
+
#endregion // Methods
}
\ No newline at end of file
diff --git a/src/Tests/DockerUpdateGuard.Tests/VulnerabilitySeverityChipsTests.cs b/src/Tests/DockerUpdateGuard.Tests/VulnerabilitySeverityChipsTests.cs
index d5f5d117..bfaa0f6b 100644
--- a/src/Tests/DockerUpdateGuard.Tests/VulnerabilitySeverityChipsTests.cs
+++ b/src/Tests/DockerUpdateGuard.Tests/VulnerabilitySeverityChipsTests.cs
@@ -192,5 +192,53 @@ public async Task VulnerabilitySeverityChipsNullSummaryRendersNothing()
}
}
+ ///
+ /// Verify every chip is a status chip in the tone of its severity, and the folded counter is neutral
+ ///
+ /// Task
+ [TestMethod]
+ [TestCategory("AC11")]
+ public async Task VulnerabilitySeverityChipsRendersStatusChipsInSeverityTones()
+ {
+ var testContext = BlazorTestContextFactory.Create();
+
+ await using (testContext)
+ {
+ var summary = new VulnerabilitySeveritySummaryViewData
+ {
+ CriticalCount = 3,
+ HighCount = 7,
+ MediumCount = 12,
+ LowCount = 5,
+ OtherCount = 1,
+ };
+
+ var full = testContext.Render(parameters => parameters.Add(chips => chips.Summary, summary));
+ var compact = testContext.Render(parameters => parameters.Add(chips => chips.Summary, summary)
+ .Add(chips => chips.Compact, true));
+
+ Assert.AreEqual("dug-chip dug-chip--critical", GetChipClass(full, "3 Critical"), "The critical chip must use the critical tone");
+ Assert.AreEqual("dug-chip dug-chip--high", GetChipClass(full, "7 High"), "The high chip must use the high tone");
+ Assert.AreEqual("dug-chip dug-chip--medium", GetChipClass(full, "12 Medium"), "The medium chip must use the medium tone");
+ Assert.AreEqual("dug-chip dug-chip--low", GetChipClass(full, "5 Low"), "The low chip must use the low tone");
+ Assert.AreEqual("dug-chip dug-chip--low", GetChipClass(full, "1 Unknown"), "The unknown chip must use the low tone");
+ Assert.AreEqual("dug-chip dug-chip--critical", GetChipClass(compact, "3 Critical"), "The compact critical chip must use the critical tone");
+ Assert.AreEqual("dug-chip dug-chip--neutral", GetChipClass(compact, "+18 more"), "The folded counter must use the neutral tone");
+ }
+ }
+
+ ///
+ /// Read the class attribute of the status chip that shows a text
+ ///
+ /// Rendered component
+ /// Chip text
+ /// Class attribute
+ private static string GetChipClass(IRenderedComponent component, string text)
+ {
+ return component.FindAll(".dug-chip")
+ .Single(chip => chip.TextContent.Trim() == text)
+ .GetAttribute("class") ?? string.Empty;
+ }
+
#endregion // Methods
}
\ No newline at end of file