Files
Toiminnanohjaus/tests/Browser/UsersAccessibilityTest.php
T
petriandClaude Opus 5.5 8aead06972 Add English to the UI and a profile menu for language and theme
Every UI string now exists in lang/fi and lang/en; a unit test checks that
both languages have the same keys and placeholders. A user's language is
stored on the account (users.locale) and applied by the SetLocale web
middleware, falling back to the session's choice on signed-out pages and
then APP_LOCALE. Emails use the user's language through
HasLocalePreference, and the login page keeps the language after logout.

The header's name, theme toggle and logout button become one profile menu
(a disclosure) with the language buttons, light/dark/system theme radios
kept on the device, and logging out. Signed-out pages get a Suomi/English
switch next to the theme toggle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 06:28:39 +02:00

121 lines
4.6 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 new set-password link to copy without accessibility issues', function (string $device, string $colorScheme) {
$this->actingAs(User::factory()->admin()->create());
$user = User::factory()->create();
onDeviceAndScheme(visit(route('users.edit', $user->id)), $device, $colorScheme)
->press('Luo salasanan asetuslinkki')
->assertSee('Uusi linkki luotu')
->assertSourceHas('/reset-password/')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->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('/')
->assertPresent('[data-profile-menu]');
});