Add WCAG 2.2 AA accessibility baseline and browser tests

- Layout: skip link to the main content and a <main> landmark
- Home page: stable button label, counter announced via a live status region
- Pest browser plugin + Playwright: axe checks (level 2) in light/dark and
  desktop/mobile, plus a keyboard-only interaction test
- Register the Browser test suite in phpunit.xml and Pest.php
- CLAUDE.md: accessibility development rules and browser test notes
- Boost-refreshed testing-best-practices skill files

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-22 09:45:13 +02:00
co-authored by Claude Opus 5.5
parent 919e24c252
commit d403a86443
16 changed files with 1762 additions and 7 deletions
@@ -29,7 +29,7 @@ Read this section before you write a test.
- Leave framework behavior to framework tests. Testing project configuration is not testing the framework. A constrained relationship, cast, scope, or validation rule belongs to this project.
- Keep every test that can detect a distinct defect. When two tests detect the same defect, trim the higher-layer test to one case and report the duplication. Do not delete an existing test.
- Write a feature test first. Write a unit test only for logic that does not use the framework.
- Write a feature test for every behavior reachable through a request. Real-browser tests require `pestphp/pest-plugin-browser` and a browser download, neither of which this project installs. Mention the package only if the user asks for a real-browser test.
- Write a browser test only for behavior in JavaScript that a feature test cannot reach. Put a browser test in `tests/Browser`, and call `assertNoJavaScriptErrors()` in it.
- Judge an architecture test by the convention it protects, not by the rules above. An `arch()` test declares a rule for an entire directory, such as the parent class of every model, the classes that may use an enum, or the methods every factory declares. It intentionally checks declarations and fails when a new file breaks the convention.
- Use the test tools that the project installs. Add a new test dependency, plugin, or browser only after the user asks for it.
@@ -31,6 +31,32 @@ An HTTP test shows that the endpoint performs authorization. It cannot identify
- Write one HTTP test for one refused role, which shows that the endpoint calls the authorization.
- If the project has a helper that asserts the ability and the arguments of the gate, use that helper.
## Browser tests
Write a browser test only for JavaScript behavior that an HTTP test cannot reach, such as modal interaction, drag-and-drop, live search, or client-side validation. Browser tests are slower than HTTP tests and can fail for reasons unrelated to the code under test.
- Assert the state that the user can see, and assert the state in the database that the interaction saves.
- Wait until the test reaches the required state. Do not wait for a fixed number of seconds. A fixed wait can fail on a slower machine.
- Call `assertNoJavaScriptErrors()` in each browser test. An error in the console is a defect.
### Where a browser test lives and how to run it
The plugin runs browser tests as normal Pest tests, so they need no separate suite. Put them in `tests/Browser` to separate them from faster tests and run the directory with one command.
- Run a browser test with `vendor/bin/pest tests/Browser`, and add `--parallel` for the complete suite.
- Run `vendor/bin/pest --debug` to open the window of the browser and to pause at a failure. Use `--headed` to watch a run that passes.
- Add `--browser firefox` or `--browser safari` to run the test in a different browser. The default browser is Chrome.
- The run needs Playwright and a browser on the machine. Follow the plugin documentation for local and CI installation commands.
- Fetch `https://pestphp.com/docs/browser-testing` for the interactions, the assertions, and the devices that the plugin gives.
### Browser test pitfalls
- The plugin waits five seconds for an element. For a slower page, raise the value with `pest()->browser()->timeout(10000)` in `Pest.php`. Do not add a wait for a number of seconds to the test.
- Apply `RefreshDatabase` to the browser tests in `Pest.php`. A browser test hits the application through a real request, and the records that it leaves break the next test.
- Add `tests/Browser/Screenshots` to `.gitignore`. A failure writes a screenshot, and the file is not part of the repository.
- Give `withKeyDown()` a key code, such as `KeyA`. A letter such as `'a'` gives the lowercase character, whatever modifier the test holds.
- Interact inside the callback of `withinFrame()`. An interaction outside the callback does not reach the frame.
## Testing validation
- Write one test for each validation rule when each failure represents a separate contract.
@@ -29,7 +29,7 @@ Read this section before you write a test.
- Leave framework behavior to framework tests. Testing project configuration is not testing the framework. A constrained relationship, cast, scope, or validation rule belongs to this project.
- Keep every test that can detect a distinct defect. When two tests detect the same defect, trim the higher-layer test to one case and report the duplication. Do not delete an existing test.
- Write a feature test first. Write a unit test only for logic that does not use the framework.
- Write a feature test for every behavior reachable through a request. Real-browser tests require `pestphp/pest-plugin-browser` and a browser download, neither of which this project installs. Mention the package only if the user asks for a real-browser test.
- Write a browser test only for behavior in JavaScript that a feature test cannot reach. Put a browser test in `tests/Browser`, and call `assertNoJavaScriptErrors()` in it.
- Judge an architecture test by the convention it protects, not by the rules above. An `arch()` test declares a rule for an entire directory, such as the parent class of every model, the classes that may use an enum, or the methods every factory declares. It intentionally checks declarations and fails when a new file breaks the convention.
- Use the test tools that the project installs. Add a new test dependency, plugin, or browser only after the user asks for it.
@@ -31,6 +31,32 @@ An HTTP test shows that the endpoint performs authorization. It cannot identify
- Write one HTTP test for one refused role, which shows that the endpoint calls the authorization.
- If the project has a helper that asserts the ability and the arguments of the gate, use that helper.
## Browser tests
Write a browser test only for JavaScript behavior that an HTTP test cannot reach, such as modal interaction, drag-and-drop, live search, or client-side validation. Browser tests are slower than HTTP tests and can fail for reasons unrelated to the code under test.
- Assert the state that the user can see, and assert the state in the database that the interaction saves.
- Wait until the test reaches the required state. Do not wait for a fixed number of seconds. A fixed wait can fail on a slower machine.
- Call `assertNoJavaScriptErrors()` in each browser test. An error in the console is a defect.
### Where a browser test lives and how to run it
The plugin runs browser tests as normal Pest tests, so they need no separate suite. Put them in `tests/Browser` to separate them from faster tests and run the directory with one command.
- Run a browser test with `vendor/bin/pest tests/Browser`, and add `--parallel` for the complete suite.
- Run `vendor/bin/pest --debug` to open the window of the browser and to pause at a failure. Use `--headed` to watch a run that passes.
- Add `--browser firefox` or `--browser safari` to run the test in a different browser. The default browser is Chrome.
- The run needs Playwright and a browser on the machine. Follow the plugin documentation for local and CI installation commands.
- Fetch `https://pestphp.com/docs/browser-testing` for the interactions, the assertions, and the devices that the plugin gives.
### Browser test pitfalls
- The plugin waits five seconds for an element. For a slower page, raise the value with `pest()->browser()->timeout(10000)` in `Pest.php`. Do not add a wait for a number of seconds to the test.
- Apply `RefreshDatabase` to the browser tests in `Pest.php`. A browser test hits the application through a real request, and the records that it leaves break the next test.
- Add `tests/Browser/Screenshots` to `.gitignore`. A failure writes a screenshot, and the file is not part of the repository.
- Give `withKeyDown()` a key code, such as `KeyA`. A letter such as `'a'` gives the lowercase character, whatever modifier the test holds.
- Interact inside the callback of `withinFrame()`. An interaction outside the callback does not reach the frame.
## Testing validation
- Write one test for each validation rule when each failure represents a separate contract.
+2
View File
@@ -26,3 +26,5 @@ Homestead.json
Homestead.yaml
Thumbs.db
/New Text Document.txt
/tests/Browser/Screenshots
/tests/Browser/Traces
+16
View File
@@ -12,6 +12,21 @@ An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5
- **Access control is central.** Roles: admin (*pääkäyttäjä*), management (*johto*), employee (*työntekijä*), intern (*harjoittelija*), subcontractor (*alihankkija*). Employees and interns see only the jobs assigned to them and never see money amounts. Interns have an end date after which they can't log in, plus a supervisor. Subcontractors see only their assigned jobs.
- **UI targets:** logged-in users only (no public pages besides login). It must work on phones (new-job intake, time entry) and on FullHD desktops.
## Accessibility (WCAG 2.2 AA, EN 301 549)
Accessibility is a contractual acceptance criterion. It covers the whole UI: navigation, forms, tables, reports, notifications, dialogs, login, and every business process. Every new or changed view must meet these rules:
- Use Flux components first; they ship with correct roles, focus handling and keyboard support. Every form control goes in `flux:field` with a `flux:label` and a `flux:error` (or uses the shorthand `label` prop). Placeholder text is not a label.
- Never convey meaning by colour alone. Statuses, priorities (e.g. *kiire* = red), errors and warnings always also have visible text or an icon with text.
- Announce dynamic changes: put status text in `role="status"` / `aria-live="polite"` (errors: `role="alert"`), or use Flux toast. Keep button names stable instead of putting changing state in them.
- Make everything work with the keyboard alone, with a visible focus indicator and no focus traps. Use `flux:modal` for dialogs, so focus moves in and returns.
- The layout (`resources/views/layouts/app.blade.php`) provides a skip link and a `<main id="main-content">` landmark. Keep them, and add `<nav aria-label="…">` for navigation.
- One `h1` per page, logical heading order, and a descriptive page `#[Title]` on every page component.
- Data tables use `flux:table` with column headers. Icon-only buttons need an accessible name (`aria-label` or Flux `tooltip`). Decorative images get `alt=""`.
- Contrast is at least 4.5:1 for text and 3:1 for UI components and focus indicators, in both light and dark mode.
- Layouts must reflow at 320 px width and 400 % zoom without horizontal scrolling. Touch targets are at least 24×24 px.
- Every new page gets a browser test in `tests/Browser` that uses `assertNoAccessibilityIssues(level: 2)` in light and dark mode and on desktop and mobile. See `tests/Browser/AccessibilityTest.php`. Automated axe checks catch only part of WCAG: also check new flows manually with the keyboard and a screen reader (NVDA).
## Commands
```powershell
@@ -25,6 +40,7 @@ vendor/bin/pint --dirty --format agent
- Runs under XAMPP: Apache on port 8080 serves the app at `http://localhost:8080/toiminnanohjaus/public` (this is `APP_URL`). The database is XAMPP MariaDB 10.11 `toiminnanohjaus` (root, no password).
- Tests use in-memory SQLite with array cache/session/mail and the sync queue. `phpunit.xml` sets `APP_URL=http://localhost`, because the subfolder `APP_URL` makes test requests 404.
- Browser tests (`tests/Browser`, Pest browser plugin with Playwright Chromium) run against built assets, so run `npm run build` first. Run only them with `php artisan test --compact tests/Browser`. They need PHP's `sockets` extension (enabled in `C:\xampp\php\php.ini`). In the plugin's `click`/`keys` methods, a selector is treated as CSS only if it starts with `#`, `.` or `[`, or contains a CSS combinator (`html > body`). Otherwise it is matched as visible text, so `button` or `main button` time out.
- Apache serves built assets from `public/build`, so run `npm run build` after CSS/Blade class changes. A leftover `public/hot` file from a stopped `npm run dev` breaks all styling: delete it.
- Session, cache and queue use the `database` driver locally, so their tables come from the default migrations.
- Laravel Boost MCP is configured in `.mcp.json` (`php artisan boost:mcp`). `AGENTS.md` is a copy of the Boost guidelines below for other agents (opencode).
+1
View File
@@ -24,6 +24,7 @@
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"pestphp/pest": "^5.3",
"pestphp/pest-plugin-browser": "^5.2",
"pestphp/pest-plugin-laravel": "^5.0"
},
"autoload": {
Generated
+1595 -1
View File
File diff suppressed because it is too large Load Diff
+43
View File
@@ -8,6 +8,7 @@
"@tailwindcss/vite": "^4.0.0",
"concurrently": "^10.0.3",
"laravel-vite-plugin": "^3.1",
"playwright": "^1.65.1",
"tailwindcss": "^4.0.0",
"vite": "^8.0.0"
},
@@ -1590,6 +1591,33 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/playwright": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.65.1.tgz",
"integrity": "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw==",
"dev": true,
"dependencies": {
"playwright-core": "1.65.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/playwright-core": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz",
"integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==",
"dev": true,
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/postcss": {
"version": "8.5.33",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz",
@@ -3023,6 +3051,21 @@
"integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
"dev": true
},
"playwright": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.65.1.tgz",
"integrity": "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw==",
"dev": true,
"requires": {
"playwright-core": "1.65.1"
}
},
"playwright-core": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz",
"integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==",
"dev": true
},
"postcss": {
"version": "8.5.33",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz",
+1
View File
@@ -10,6 +10,7 @@
"@tailwindcss/vite": "^4.0.0",
"concurrently": "^10.0.3",
"laravel-vite-plugin": "^3.1",
"playwright": "^1.65.1",
"tailwindcss": "^4.0.0",
"vite": "^8.0.0"
},
+3
View File
@@ -11,6 +11,9 @@
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
<testsuite name="Browser">
<directory>tests/Browser</directory>
</testsuite>
</testsuites>
<source>
<include>
+10 -1
View File
@@ -15,7 +15,16 @@
@fluxAppearance
</head>
<body class="min-h-screen bg-white antialiased dark:bg-zinc-800">
{{ $slot }}
<a
href="#main-content"
class="sr-only focus:not-sr-only focus:fixed focus:start-4 focus:top-4 focus:z-50 focus:rounded-md focus:bg-white focus:px-4 focus:py-2 focus:text-zinc-900 focus:shadow-lg focus:outline-2 focus:outline-offset-2 focus:outline-blue-700"
>
Siirry pääsisältöön
</a>
<main id="main-content" tabindex="-1" class="focus:outline-none">
{{ $slot }}
</main>
@livewireScripts
@fluxScripts
+5 -1
View File
@@ -20,6 +20,10 @@ new #[Title('Toiminnanohjaus')] class extends Component
<flux:text>Livewire ja Flux UI toimivat. Tämä on väliaikainen kokeilusivu.</flux:text>
<flux:button variant="primary" icon="plus" wire:click="incrementClickCount">
Klikattu {{ $clickCount }} kertaa
Lisää klikkaus
</flux:button>
<flux:text role="status" aria-live="polite" aria-atomic="true">
Klikattu {{ $clickCount }} kertaa
</flux:text>
</div>
+28
View File
@@ -0,0 +1,28 @@
<?php
it('has no accessibility issues on the home page', function (string $device, string $colorScheme) {
$page = visit(route('home'));
$page = $device === 'mobile' ? $page->on()->mobile() : $page->on()->desktop();
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
$page->assertSee('Toiminnanohjaus')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('can be operated with the keyboard alone', function () {
$page = visit(route('home'));
$page->keys('html > body', 'Tab')
->assertScript('document.activeElement.textContent.trim()', 'Siirry pääsisältöön')
->keys('a[href="#main-content"]', 'Tab')
->assertScript('document.activeElement.textContent.trim()', 'Lisää klikkaus')
->keys('#main-content button', 'Enter')
->assertSeeIn('[role="status"]', 'Klikattu 1 kertaa');
});
+3 -1
View File
@@ -5,7 +5,9 @@ use Livewire\Livewire;
it('renders the home page', function () {
$this->get(route('home'))
->assertOk()
->assertSee('Toiminnanohjaus');
->assertSee('Toiminnanohjaus')
->assertSee('Siirry pääsisältöön')
->assertSee('id="main-content"', false);
});
it('increments the click count', function () {
+1 -1
View File
@@ -16,7 +16,7 @@ use Tests\TestCase;
pest()->extend(TestCase::class)
// ->use(RefreshDatabase::class)
->in('Feature');
->in('Feature', 'Browser');
/*
|--------------------------------------------------------------------------