Files
Toiminnanohjaus/tests/Browser/UsersAccessibilityTest.php
T
petriandClaude Opus 5.5 90d6f5bd66 Replace Flux UI with TallStackUI 4
Rewrite the layout and all Customers and Users pages with TallStackUI
components and remove livewire/flux and its Boost skill.

Fix the TallStackUI accessibility gaps found by the axe tests:
- password reveal and theme switch have no accessible name: add
  <x-password-field> and keep the own theme toggle button
- select.native label is not tied to the control: add aria-label
- contrast: darker primary palette, soft-customized error colours and
  published alert/link colour classes; neutral buttons use subtle black
- follow the system theme by default (localStorage key dark-theme)

Load TallStackUI assets from the app URL so they work in the XAMPP
subfolder, add Finnish TallStackUI strings, and drop inputmode=numeric
from the business ID field so iOS keyboards show the hyphen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 12:22:03 +02:00

109 lines
4.0 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Pest\Browser\Api\AwaitableWebpage;
use Pest\Browser\Api\PendingAwaitablePage;
uses(RefreshDatabase::class);
$devicesAndSchemes = [
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
];
/**
* @param PendingAwaitablePage|AwaitableWebpage $page
*/
function onDeviceAndScheme(mixed $page, string $device, string $colorScheme): mixed
{
$page = $device === 'mobile' ? $page->on()->mobile() : $page->on()->desktop();
return $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
}
it('has no accessibility issues on the guest pages', function (string $routeName, string $device, string $colorScheme) {
$url = $routeName === 'password.reset'
? route($routeName, ['token' => 'token', 'email' => '[email protected]'])
: route($routeName);
onDeviceAndScheme(visit($url), $device, $colorScheme)
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'login' => 'login',
'forgot password' => 'password.request',
'reset password' => 'password.reset',
])->with($devicesAndSchemes);
it('has no accessibility issues on the user admin pages', function (string $page, string $device, string $colorScheme) {
$admin = User::factory()->admin()->create();
$intern = User::factory()->intern('2027-05-31')->create();
$this->actingAs($admin);
$url = match ($page) {
'list' => route('users.index'),
'create' => route('users.create'),
'edit intern' => route('users.edit', $intern->id),
};
onDeviceAndScheme(visit($url), $device, $colorScheme)
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['list', 'create', 'edit intern'])->with($devicesAndSchemes);
it('shows a login error without accessibility issues', function (string $colorScheme) {
$page = onDeviceAndScheme(visit(route('login')), 'desktop', $colorScheme);
$page->fill('[wire\\:model="email"]', '[email protected]')
->fill('[wire\\:model="password"]', 'väärä-salasana')
->press('Kirjaudu')
->assertSee('Kirjautuminen ei onnistunut.')
->assertNoAccessibilityIssues(level: 2);
})->with(['light', 'dark']);
it('sends a user who is deactivated mid-session to the login page with the reason', function () {
$user = User::factory()->create();
$this->actingAs($user);
// visit() is lazy: load the form before the account is deactivated.
$page = visit(route('customers.create'))->assertSee('Uusi asiakas');
$user->update(['is_active' => false]);
$page->fill('[wire\\:model="form.name"]', 'Mainos Oy')
->press('Tallenna')
->assertPathIs('/login')
->assertSee('Käyttöoikeutesi on päättynyt. Ota yhteyttä pääkäyttäjään.')
->assertNoAccessibilityIssues(level: 2);
});
it('shows and hides the password with a named toggle button', function () {
$toggle = '[aria-label="Näytä salasana"]';
visit(route('login'))
->assertAttribute('[wire\\:model="password"]', 'type', 'password')
->assertAttribute($toggle, 'aria-pressed', 'false')
->click($toggle)
->assertAttribute('[wire\\:model="password"]', 'type', 'text')
->assertAttribute($toggle, 'aria-pressed', 'true')
->assertAttribute($toggle, 'aria-label', 'Näytä salasana');
});
it('logs in with the keyboard alone', function () {
User::factory()->create(['email' => '[email protected]']);
visit(route('login'))
->keys('html > body', 'Tab')
->keys('a[href="#main-content"]', 'Enter')
->keys('#main-content', 'Tab')
->assertScript('document.activeElement.getAttribute("wire:model")', 'email')
->type('[wire\\:model="email"]', '[email protected]')
->type('[wire\\:model="password"]', 'password')
->keys('[wire\\:model="password"]', 'Enter')
->assertPathIs('/')
->assertSee('Kirjaudu ulos');
});