diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 207741df..6dd6c196 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b467cacc..d70a1a74 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: @@ -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 diff --git a/docs/decisions/0002-styling-architecture.md b/docs/decisions/0002-styling-architecture.md index f9b2cd78..e0dc84e1 100644 --- a/docs/decisions/0002-styling-architecture.md +++ b/docs/decisions/0002-styling-architecture.md @@ -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-`, `fl-__` and `fl---`, 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 ` + """); + + XunitException failure = await Assert.ThrowsAnyAsync(() => Wcag.AssertTargetSizesAsync(page.Page)); + + Assert.Contains("button#empty", failure.Message); + } + + [Fact] + public async Task TargetSizeChecksMenuItemsThatAreNotButtons() + { + await using GalleryPage page = await gallery.OpenBlankAsync(Head + """ +
Bold
+ """); + + XunitException failure = await Assert.ThrowsAnyAsync(() => Wcag.AssertTargetSizesAsync(page.Page)); + + Assert.Contains("div#check", failure.Message); + } + [Fact] public async Task TargetSizeExcludesControlsDisabledByAFieldset() { @@ -181,6 +276,35 @@ public async Task MotionFailsOnAnAnimationThatIgnoresReducedMotion() Assert.Contains("div#mover", failure.Message); } + // Movement that no box of an element shows: a pseudo-element, a background that travels, and a spinner that jumps + // in steps with still frames between them. + [Theory] + [InlineData("@keyframes slide { to { translate: 120px } } #mover::after { content: ''; display: block; width: 10px; height: 10px; animation: slide 2s infinite alternate }", "::after animates translate")] + [InlineData("@keyframes travel { to { background-position: 200px 0 } } #mover { height: 10px; background: linear-gradient(90deg, red, blue); animation: travel 2s linear infinite }", "div#mover")] + [InlineData("@keyframes spin { to { rotate: 1turn } } #mover { width: 20px; animation: spin 2s steps(4) infinite }", "div#mover")] + public async Task MotionFailsOnMovementThatNoBoxShows(string css, string expected) + { + await using GalleryPage page = await gallery.OpenBlankAsync($"{Head}
Moves
"); + + XunitException failure = await Assert.ThrowsAnyAsync(() => Wcag.AssertNoMotionAsync(page.Page)); + + Assert.Contains(expected, failure.Message); + } + + // A transition that starts after the window that watches the interaction still counts. + [Fact] + public async Task MotionFailsOnATransitionThatWaitsForItsDelay() + { + await using GalleryPage page = await gallery.OpenBlankAsync(Head + """ + +
→
+ """); + + XunitException failure = await Assert.ThrowsAnyAsync(() => Wcag.AssertNoMotionAsync(page.Page, () => page.Page.Locator("button").HoverAsync())); + + Assert.Contains("div#marker", failure.Message); + } + [Fact] public async Task MotionPassesAnAnimationThatReducedMotionTurnsOff() { diff --git a/tests/FluentCMS.Components.Browser/Samples/KeyboardIndicatorTests.cs b/tests/FluentCMS.Components.Browser/Samples/KeyboardIndicatorTests.cs index 1a8c1eb7..2004446c 100644 --- a/tests/FluentCMS.Components.Browser/Samples/KeyboardIndicatorTests.cs +++ b/tests/FluentCMS.Components.Browser/Samples/KeyboardIndicatorTests.cs @@ -32,13 +32,23 @@ public async Task KeyboardDoesNotShowAnIndicatorWhenThePaintIsUnchanged(string c Assert.Contains("stayed", failure.Message); } + // A ring of 2 per cent black changes the pixel, but nobody sees it. + [Fact] + public async Task KeyboardDoesNotShowAnIndicatorThatCannotBeSeen() + { + await using GalleryPage page = await gallery.OpenBlankAsync(""); + KeyboardDriver keys = page.Page.Keys(); + XunitException failure = await Assert.ThrowsAnyAsync(() => keys.TabToAndAssertPaintChangeAsync("button", xFromLeft: -1)); + Assert.Contains("where 3:1 is needed", failure.Message); + } + [Fact] public async Task KeyboardShowsABackgroundOnlyIndicator() { await using GalleryPage page = await gallery.OpenBlankAsync(""" """); diff --git a/tests/FluentCMS.Components.Browser/Screens/EntryEditorTests.cs b/tests/FluentCMS.Components.Browser/Screens/EntryEditorTests.cs index b5c4dc29..ec1e277d 100644 --- a/tests/FluentCMS.Components.Browser/Screens/EntryEditorTests.cs +++ b/tests/FluentCMS.Components.Browser/Screens/EntryEditorTests.cs @@ -19,6 +19,7 @@ public async Task EditorShowsTheSampleEntryAndItsLocaleTabsArePages(RenderMode m { await using GalleryPage sample = await gallery.OpenAsync(mode, Path, new() { Theme = "dark" }); IPage page = sample.Page; + await FormsPage.FocusSettledAsync(page, mode); // The editor is below Articles, so that link of the navigation is the current one. await ScreenChecks.AssertFrameAsync(page, mode, Title, "Articles"); await Expect(page.GetByRole(AriaRole.Navigation, new() { Name = "Breadcrumb" }).GetByRole(AriaRole.Link)).ToHaveTextAsync(["Home", "Articles"]); @@ -73,6 +74,7 @@ public async Task SaveAndThePublishSplitButtonGiveTheSampleOutcomesWithTheKeyboa { await using GalleryPage sample = await gallery.OpenAsync(mode, Path); IPage page = sample.Page; + await FormsPage.FocusSettledAsync(page, mode); KeyboardDriver keys = page.Keys(); await page.Locator("#entry-title").FillAsync("Spring release, edited"); @@ -222,6 +224,7 @@ public async Task MoveToTrashAsksFirstAndTheArticleComesBack(RenderMode mode) { await using GalleryPage sample = await gallery.OpenAsync(mode, Path); IPage page = sample.Page; + await FormsPage.FocusSettledAsync(page, mode); KeyboardDriver keys = page.Keys(); ILocator dialog = page.GetByRole(AriaRole.Alertdialog, new() { Name = "Move this article to the trash?" }); @@ -293,6 +296,7 @@ public async Task InvalidDraftNamesItsFieldKeepsTheEditsAndANewEntryStartsAtVers { await using GalleryPage sample = await gallery.OpenAsync(mode, "content-list/entry?new=page"); IPage page = sample.Page; + await FormsPage.FocusSettledAsync(page, mode); KeyboardDriver keys = page.Keys(); await ScreenChecks.AssertFrameAsync(page, mode, "New page", "Articles"); await Expect(page.Locator("#entry-state")).ToHaveTextAsync("Not saved yet"); @@ -338,6 +342,7 @@ public async Task LinksToTheGroupsOfFieldsMoveFocusToTheGroup(RenderMode mode) { await using GalleryPage sample = await gallery.OpenAsync(mode, Path, new() { Width = 1280, Height = 500, ReducedMotion = true }); IPage page = sample.Page; + await FormsPage.FocusSettledAsync(page, mode); KeyboardDriver keys = page.Keys(); ILocator groups = page.GetByRole(AriaRole.Navigation, new() { Name = "Groups of fields" }); await Expect(groups.GetByRole(AriaRole.Link)).ToHaveTextAsync(["Content", "Sections, 3 blocks", "SEO"]); @@ -365,6 +370,7 @@ public async Task InteractiveChoicesAndDiscardUseTheBoundModelAndEditsStayAcross { await using GalleryPage sample = await gallery.OpenAsync(mode, Path); IPage page = sample.Page; + await FormsPage.FocusSettledAsync(page, mode); KeyboardDriver keys = page.Keys(); // One choice and several, searched with the keyboard. @@ -526,6 +532,7 @@ public async Task WideWindowKeepsTheBandInViewAndNeitherWidthObscuresFocus(Rende await using (GalleryPage wide = await gallery.OpenAsync(mode, Path, new() { Width = 1280, Height = 400, ReducedMotion = true })) { IPage page = wide.Page; + await FormsPage.FocusSettledAsync(page, mode); await Expect(page.Locator("#entry-save-bar")).ToBeHiddenAsync(); await page.Locator("#entry-info").ScrollIntoViewIfNeededAsync(); await Expect(page.Locator("#entry-save")).ToBeInViewportAsync(); @@ -534,6 +541,7 @@ public async Task WideWindowKeepsTheBandInViewAndNeitherWidthObscuresFocus(Rende } await using GalleryPage narrow = await gallery.OpenAsync(mode, Path, new() { Width = 320, Height = 500, ReducedMotion = true }); + await FormsPage.FocusSettledAsync(narrow.Page, mode); await ScreenChecks.AssertFocusIsNeverObscuredAsync(narrow.Page, maxStops: 220); } @@ -563,6 +571,9 @@ public async Task OverlaysHaveTheirTransitionsAndNothingMovesWhenMotionIsReduced } await Expect(page.Locator("#entry-publish__toggle")).ToHaveAttributeAsync("aria-expanded", "false"); + // The router puts focus on the heading after the first interactive render; a key sent before that can lose its + // focus to it, as in #182. + await FormsPage.FocusSettledAsync(page, mode); await page.Locator("#entry-publish__toggle").FocusAsync(); await Wcag.AssertNoMotionAsync(page, async () => { diff --git a/tests/FluentCMS.Components.Browser/test-startup.mjs b/tests/FluentCMS.Components.Browser/test-startup.mjs index c97e0086..23358cf9 100644 --- a/tests/FluentCMS.Components.Browser/test-startup.mjs +++ b/tests/FluentCMS.Components.Browser/test-startup.mjs @@ -1,11 +1,22 @@ -// node tests/FluentCMS.Components.Browser/test-startup.mjs [artifacts|environment|logging] +// node tests/FluentCMS.Components.Browser/test-startup.mjs [artifacts|environment|logging|console|kestrel] import { spawnSync } from 'node:child_process'; import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { basename, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -const cases = ['artifacts', 'environment', 'logging']; +const cases = ['artifacts', 'environment', 'logging', 'console', 'kestrel']; +// Settings a parent may hold that would change the host the fixture starts, by case. +const inherited = { + console: { Logging__Console__LogLevel__Default: 'Warning', Logging__Console__FormatterName: 'json' }, + // An address of TEST-NET-3, which no machine has, so a host that takes it fails to start on any system. + kestrel: { + Kestrel__Endpoints__Http__Url: 'http://203.0.113.1:5000', + DOTNET_Kestrel__Endpoints__Http__Url: 'http://203.0.113.1:5000', + ASPNETCORE_URLS: 'http://203.0.113.1:5000', + DOTNET_Logging__Console__FormatterName: 'json', + }, +}; const selected = process.argv.slice(2); const root = fileURLToPath(new URL('../../', import.meta.url)); @@ -18,6 +29,7 @@ for (const name of selected.length ? selected : cases) { FLUENTCMS_MODES: mode.toLowerCase(), DOTNET_ENVIRONMENT: name === 'environment' ? 'Production' : 'Development', Logging__LogLevel__Default: name === 'logging' ? 'Warning' : 'Information', + ...inherited[name], }; const args = ['test', '--project', 'tests/FluentCMS.Components.Browser', '--filter-display-name', `*EveryModeBecomesWhatItsAddressNames(mode: ${mode})`, @@ -26,7 +38,7 @@ for (const name of selected.length ? selected : cases) { try { // A fresh configuration means a previous default-bin build cannot mask the bug. if (artifacts) args.push('--configuration', basename(artifacts), '--artifacts-path', artifacts); - console.log(`[${name}] FLUENTCMS_MODES=${env.FLUENTCMS_MODES} DOTNET_ENVIRONMENT=${env.DOTNET_ENVIRONMENT} Logging__LogLevel__Default=${env.Logging__LogLevel__Default}`); + console.log(`[${name}] FLUENTCMS_MODES=${env.FLUENTCMS_MODES} DOTNET_ENVIRONMENT=${env.DOTNET_ENVIRONMENT} Logging__LogLevel__Default=${env.Logging__LogLevel__Default}`, inherited[name] ?? ''); console.log('dotnet', args.map(arg => arg.includes(' ') ? `"${arg}"` : arg).join(' ')); const result = spawnSync('dotnet', args, { cwd: root, env, stdio: 'inherit' }); if (result.error) throw result.error;