Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,24 @@ jobs:
browser: ${{ matrix.engine.browser }}
modes: ${{ matrix.part.mode }}
filter: ${{ matrix.part.filter }}

# The fixture must start the gallery that was built, in Development, whatever the parent's environment holds
# (CONTRIBUTING.md, Browser tests). Each case runs one browser test under a parent that would break it.
startup:
name: Gallery startup
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ./.github/actions/setup-dotnet
- name: Build browser tests and gallery
shell: bash
run: dotnet build tests/FluentCMS.Components.Browser
- name: Install Chromium
shell: bash
run: pwsh tests/FluentCMS.Components.Browser/bin/Debug/net10.0/playwright.ps1 install chromium
- name: Start the gallery under each parent environment
shell: bash
run: node tests/FluentCMS.Components.Browser/test-startup.mjs
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ $env:FLUENTCMS_BROWSER = "firefox"
dotnet test --project tests/FluentCMS.Components.Browser --filter-class "*AccessibilitySamples"
```

A test is written once for the three modes. The mode comes from `[ModeData]`. `OpenAsync` requires a successful document response and waits for the requested mode; in an interactive mode it also waits for `data-interactive="true"`. Before an axe scan starts, the fixture checks that the document's computed colour scheme and direction match the request. A 404 page or a second LTR scan in place of RTL fails the test.
A test is written once for the three modes. The mode comes from `[ModeData]`. `OpenAsync` requires a successful document response at the address it asked for (a redirect fails), extends a query that the path brings, and waits for the requested mode; in an interactive mode it also waits for `data-interactive="true"`. Before an axe scan starts, the fixture checks that the document's computed colour scheme and direction, and its density, match the request. A 404 page or a second LTR scan in place of RTL fails the test.

For example:

Expand All @@ -220,18 +220,18 @@ The helpers are in `tests/FluentCMS.Components.Browser/Harness`:
| Helper | Checks |
| --- | --- |
| `Accessibility.AssertNoViolationsAsync` | axe-core finds nothing, in light, dark and right to left (light only in an interactive mode on a page in `StaticPages`). A failure names the rule, the target and the help address |
| `page.Keys()` | Drives the page with the keyboard. `AssertFocusNameAsync` checks the focused element's accessible name with Playwright; `TabToAndAssertPaintChangeAsync` checks a known point on its focus indicator |
| `Wcag.AssertTargetSizesAsync` | Every operable target is at least 24 by 24 CSS pixels in both densities. This is the [project rule](design/system/RECIPE.md), not a check that permits smaller targets if they are spaced apart. A box under the minimum passes only if a pointer hits the element across the whole square, as when a pseudo-element widens it |
| `page.Keys()` | Drives the page with the keyboard. `AssertFocusNameAsync` checks the focused element's accessible name with Playwright; `TabToAndAssertPaintChangeAsync` checks that a known point on its focus indicator changes by at least 3:1 |
| `Wcag.AssertTargetSizesAsync` | Every operable target is at least 24 by 24 CSS pixels in both densities. This is the [project rule](design/system/RECIPE.md), not a check that permits smaller targets if they are spaced apart. A box is measured as a pointer can reach it: an ancestor that clips its overflow cuts it, and an open tree item is its row. A checkbox or a radio counts with its label. A box under the minimum passes only if a pointer hits the element across the whole square, as when a pseudo-element widens it |
| `Wcag.AssertNoHorizontalScrollAsync` | The page does not scroll sideways at 320 pixels (1.4.10) |
| `Wcag.AssertNoMotionAsync` | Watches for movement under reduced motion before and during the supplied interaction. A colour change alone is not movement |
| `Wcag.AssertNoMotionAsync` | Watches for movement under reduced motion before and during the supplied interaction: boxes that move, and animations or transitions of a property that moves or resizes, also on a pseudo-element, a travelling background, or one that waits for its delay. A colour or opacity change alone is not movement |
| `Overlay.IsOpenAsync`, `IsModalAsync`, `IsInertAsync`, `AssertTabStaysInsideAsync` | A dialog or a popover is open, is modal, leaves the page behind it inert, and keeps Tab inside. `Overlay.SettledAsync` waits past the event of a close before a test says that focus stayed where it was |
| `Scrolling.AtRestAsync`, `IntoViewAsync`, `AssertInWindow` | Waits until the page has stopped scrolling, which Firefox and WebKit may do over several frames after a key or a call; brings an element into view; checks that a point a pointer is sent to lies in the window |

For a focus ring drawn on a wrapper, pass the wrapper as `indicator` and choose a point on the ring: the offset is measured from the left edge, halfway down. This checks a visible change at that point, not focus contrast across the whole control. For motion, pass the action itself, for example `Wcag.AssertNoMotionAsync(page, () => button.HoverAsync())`. Checking only after the action can miss a transition that has already finished.
For a focus ring drawn on a wrapper, pass the wrapper as `indicator` and choose a point on the ring: the offset is measured from the left edge, halfway down. The change at that point must be at least 3:1, which the recipe asks of a mark that is needed; it is not focus contrast across the whole control. Choose a point where the ring lies on the background, not on a border it covers. For motion, pass the action itself, for example `Wcag.AssertNoMotionAsync(page, () => button.HoverAsync())`. Checking only after the action can miss a transition that has already finished.

In an interactive mode, let .NET remove what .NET rendered. A test that takes such an element out with script leaves Blazor with a page it no longer knows, and what follows fails for that reason alone. The overlay tests remove an element with script in static mode only.

`tests/FluentCMS.Components.Browser/Samples` holds working examples and regressions that put each helper in front of the fault it should catch. The gallery itself holds no deliberate fault. To check gallery startup with a non-default build path, a production parent environment, and quiet logging, run the separate regression from the repository root:
`tests/FluentCMS.Components.Browser/Samples` holds working examples and regressions that put each helper in front of the fault it should catch. The gallery itself holds no deliberate fault. The fixture passes the gallery none of the host settings of its own environment (`ASPNETCORE_*`, `Kestrel__*`, `Logging__*`, and the `DOTNET_*` names that are host settings or configuration), and sets what the gallery needs. To check gallery startup with a non-default build path and under a parent that sets a production environment, quiet logging, console logging settings or addresses of its own, run the separate regression from the repository root; the nightly workflow runs it too:

```powershell
node tests/FluentCMS.Components.Browser/test-startup.mjs
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/0002-styling-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The alternatives were weighed in the plan. A CSS framework such as Bootstrap or
8. **State comes from the real attribute**, never from a class: `disabled`, `aria-invalid`, `aria-pressed`, `aria-selected`, `aria-current`, `aria-expanded`, `[open]`, `:checked`, `:popover-open`. Where no attribute exists, a `data-fl-` attribute is used, such as `data-fl-active`.
9. **Names.** Classes are `fl-<block>`, `fl-<block>__<part>` and `fl-<block>--<modifier>`, custom properties are `--fl-…` and data attributes are `data-fl-…`. A modifier names what a thing is, not how it looks.
10. **No inline script and no injected `<style>` element**, so the library runs under a content security policy that allows scripts from the site alone. Avoiding inline `style` attributes as well, so that a host can refuse those too, is a goal tracked per component.
11. **One file per component** under `Styles/components/`, and one per CSS-only pattern under `Styles/patterns/`. The token file and the component files of the design system become the library's as they are. The design system pages and the gallery load the same stylesheet the package ships.
11. **One file per component** under `Styles/components/`, and one per CSS-only pattern under `Styles/patterns/`. The token file and the component files of the design system become the library's as they are. ~~The design system pages and the gallery load the same stylesheet the package ships.~~ They load the same sources, not the same file: the [update below](#update-where-the-files-live-and-how-they-are-joined) supersedes this sentence.

## Consequences

Expand Down
2 changes: 1 addition & 1 deletion tests/FluentCMS.Components.Browser/Forms/SelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task KeyboardChangesTheBoundValueAndHostRerendersRetainTheAccessibl
IPage page = sample.Page;
KeyboardDriver keys = page.Keys();
await keys.StartAtTopAsync();
await keys.TabToAndAssertPaintChangeAsync(Binding, 0, page.Locator(".fl-select:has(> #select-binding)"));
await keys.TabToAndAssertPaintChangeAsync(Binding, -1, page.Locator(".fl-select:has(> #select-binding)"));
await keys.AssertFocusNameAsync("Project role");
ILocator binding = page.Locator(Binding);
await Expect(binding.Locator("option[value=owner]")).ToBeDisabledAsync();
Expand Down
2 changes: 1 addition & 1 deletion tests/FluentCMS.Components.Browser/Forms/TemporalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public async Task NativeKeyboardEditKeepsFocusWithReducedMotion(RenderMode mode)
await keys.StartAtTopAsync();
// The native controls before this example contribute several real segment stops each.
await keys.TabToAsync(LiveLocal, maxPresses: 120);
await keys.TabToAndAssertPaintChangeAsync(LiveTime, 0, page.Locator(".fl-time-input:has(> #temporal-live-time)"));
await keys.TabToAndAssertPaintChangeAsync(LiveTime, -1, page.Locator(".fl-time-input:has(> #temporal-live-time)"));
await keys.AssertFocusAsync(LiveTime);
ILocator time = page.Locator(LiveTime);
await Expect(time).ToHaveAccessibleNameAsync("Reminder time");
Expand Down
2 changes: 1 addition & 1 deletion tests/FluentCMS.Components.Browser/Forms/TextInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task TabReachesEachInputThenItsNamedActions(RenderMode mode)
await FormsPage.FocusSettledAsync(page, mode);
KeyboardDriver keys = page.Keys();
await keys.StartAtTopAsync();
await keys.TabToAndAssertPaintChangeAsync("#input-clear", xFromLeft: 0, indicator: page.Locator("#parts .fl-input:has(> #input-clear)"));
await keys.TabToAndAssertPaintChangeAsync("#input-clear", xFromLeft: -1, indicator: page.Locator("#parts .fl-input:has(> #input-clear)"));
await keys.AssertFocusNameAsync("With a clear action");
await keys.TabAsync();
await keys.AssertFocusAsync("#parts .fl-input:has(> #input-clear) > button.fl-input__action");
Expand Down
41 changes: 39 additions & 2 deletions tests/FluentCMS.Components.Browser/Harness/GalleryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,22 @@ public async Task<GalleryPage> OpenAsync(RenderMode mode, string path, GalleryOp
{
context = await NewContextAsync(options, own ?? Browser);
IPage page = await context.NewPageAsync();
var address = new Uri(BaseAddress, $"{mode.Segment()}/{path}{options.Query}");
// A path may bring a query of its own, which the options extend.
string query = path.Contains('?') && options.Query.Length > 0 ? "&" + options.Query[1..] : options.Query;
var address = new Uri(BaseAddress, $"{mode.Segment()}/{path}{query}");
IResponse? response = await page.GotoAsync(address.AbsoluteUri);
if (response is null || !response.Ok)
{
string status = response is null ? "no document response" : $"HTTP {response.Status}";
throw new InvalidOperationException($"Opening {address} returned {status}.");
}

// A redirect that answers with another page is not the page asked for. The fragment is not compared.
if (!new Uri(response.Url).Equals(address))
{
throw new InvalidOperationException($"Opening {address} ended at {response.Url}.");
}

await WaitUntilReadyAsync(page, mode);
if (options.Theme is "light" or "dark")
{
Expand All @@ -91,6 +99,15 @@ public async Task<GalleryPage> OpenAsync(RenderMode mode, string path, GalleryOp
await CheckAppearanceAsync(page, "direction", options.Direction, "direction");
}

if (options.Density is not null)
{
string? density = await page.Locator("html").GetAttributeAsync("data-fl-density");
if (density != options.Density)
{
throw new InvalidOperationException($"{page.Url} density: expected '{options.Density}', got '{density}'.");
}
}

return new GalleryPage(context, page, mode, path, own);
}
catch
Expand Down Expand Up @@ -163,12 +180,19 @@ private async Task<Uri> StartGalleryAsync()
start.ArgumentList.Add(targetPath);
start.ArgumentList.Add("--urls");
start.ArgumentList.Add("http://127.0.0.1:0");
// The host reads its settings from the environment too. What the parent has set for its own hosts (an
// environment, addresses, logging, startup hooks) would change this one, so none of it is passed on.
foreach (string name in start.Environment.Keys.Where(InheritedHostSetting).ToList())
{
start.Environment.Remove(name);
}

// Development, as under dotnet run: the host then finds the static files of the
// build output through the manifest the build wrote.
start.Environment["ASPNETCORE_ENVIRONMENT"] = "Development";
start.Environment["DOTNET_ENVIRONMENT"] = "Development";
// Information logging costs every request a line on the pipe; the suite reads none of it.
start.Environment.TryAdd("Logging__LogLevel__Default", "Warning");
start.Environment["Logging__LogLevel__Default"] = "Warning";
// The lifetime logger announces the port Kestrel picked, even if the parent logs only warnings.
start.Environment["Logging__LogLevel__Microsoft.Hosting.Lifetime"] = "Information";
start.Environment["DOTNET_NOLOGO"] = "1";
Expand All @@ -195,6 +219,19 @@ private async Task<Uri> StartGalleryAsync()
}
}

private static bool InheritedHostSetting(string name) =>
name.StartsWith("ASPNETCORE_", StringComparison.OrdinalIgnoreCase)
|| name.StartsWith("Kestrel__", StringComparison.OrdinalIgnoreCase)
|| name.StartsWith("Logging__", StringComparison.OrdinalIgnoreCase)
|| name.StartsWith("DOTNET_HOSTINGSTARTUP", StringComparison.OrdinalIgnoreCase)
|| name.Equals("DOTNET_ENVIRONMENT", StringComparison.OrdinalIgnoreCase)
|| name.Equals("DOTNET_URLS", StringComparison.OrdinalIgnoreCase)
|| name.Equals("DOTNET_CONTENTROOT", StringComparison.OrdinalIgnoreCase)
|| name.Equals("DOTNET_STARTUP_HOOKS", StringComparison.OrdinalIgnoreCase)
|| name.Equals("URLS", StringComparison.OrdinalIgnoreCase)
// The host also reads DOTNET_ names as configuration, such as DOTNET_Kestrel__Endpoints__Http__Url.
|| (name.StartsWith("DOTNET_", StringComparison.OrdinalIgnoreCase) && name.Contains("__", StringComparison.Ordinal));

private void OnLine(string? line, TaskCompletionSource<Uri> listening)
{
if (line is null)
Expand Down
20 changes: 20 additions & 0 deletions tests/FluentCMS.Components.Browser/Harness/KeyboardDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ public async Task TabToAndAssertPaintChangeAsync(string selector, int xFromLeft,
await TabToAsync(selector);
string after = await ReadPixelAsync(indicator, xFromLeft);
Assert.True(before != after, $"Tab reached '{selector}', but the indicator pixel on {indicator} at x={xFromLeft} stayed {after}.");
// A change has to be seen: RECIPE asks 3:1 of a mark that is needed, and focus is one.
double contrast = Contrast(before, after);
Assert.True(contrast >= 3, $"Tab reached '{selector}', but the indicator pixel on {indicator} at x={xFromLeft} went from {before} to {after}, {contrast:0.00}:1 where 3:1 is needed.");
}

private static double Contrast(string first, string second)
{
static double Luminance(string pixel)
{
double Channel(int start)
{
double value = Convert.ToInt32(pixel.Substring(start, 2), 16) / 255.0;
return value <= 0.03928 ? value / 12.92 : Math.Pow((value + 0.055) / 1.055, 2.4);
}

return 0.2126 * Channel(1) + 0.7152 * Channel(3) + 0.0722 * Channel(5);
}

double a = Luminance(first), b = Luminance(second);
return (Math.Max(a, b) + 0.05) / (Math.Min(a, b) + 0.05);
}

// Waits a moment for focus to settle, since a pattern may move it after the key press.
Expand Down
Loading
Loading