Files
petriandClaude Opus 5.5 4f926c238b Let the theme be chosen by clicking its label in the profile menu
Clicking a theme option's text moved focus nowhere, and the focusout rule
closed the panel before the radio was checked. The panel now closes only
when focus moves to an element outside it; clicks outside and Escape still
close it. Each theme option is a full-width row with a hover state, and
the chosen one is also shown in bold.

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

79 lines
3.1 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
const PROFILE_MENU = '[data-profile-menu]';
beforeEach(function () {
$this->user = User::factory()->create(['name' => 'Eero Esimerkki']);
$this->actingAs($this->user);
});
it('opens and closes the profile menu with the keyboard', function () {
visit(route('customers.index'))->inLightMode()
->assertAttribute(PROFILE_MENU, 'aria-label', 'Profiili: Eero Esimerkki')
->assertAttribute(PROFILE_MENU, 'aria-expanded', 'false')
->assertMissing('#profile-menu-panel')
->keys(PROFILE_MENU, 'Enter')
->assertAttribute(PROFILE_MENU, 'aria-expanded', 'true')
->assertVisible('#profile-menu-panel')
->assertChecked('[data-theme-option="system"]')
->assertAttribute('#profile-menu-panel button[value="fi"]', 'aria-pressed', 'true')
->keys('[data-theme-option="system"]', 'Escape')
->assertAttribute(PROFILE_MENU, 'aria-expanded', 'false')
->assertScript('document.activeElement.hasAttribute("data-profile-menu")', true);
});
it('chooses the theme by clicking the text of an option', function () {
visit(route('customers.index'))->inLightMode()
->click(PROFILE_MENU)
->click('#profile-menu-panel label:has([data-theme-option="dark"])')
->assertScript('document.documentElement.classList.contains("dark")', true)
->assertChecked('[data-theme-option="dark"]')
->assertAttribute(PROFILE_MENU, 'aria-expanded', 'true')
->assertVisible('#profile-menu-panel');
});
it('changes the language from the profile menu', function () {
$page = visit(route('customers.index'))->inLightMode()
->click(PROFILE_MENU)
->click('#profile-menu-panel button[value="en"]')
->assertScript('document.documentElement.lang', 'en')
->assertAttribute(PROFILE_MENU, 'aria-label', 'Profile: Eero Esimerkki');
expect($this->user->fresh()->locale->value)->toBe('en');
$page->click(PROFILE_MENU)
->assertAttribute('#profile-menu-panel button[value="en"]', 'aria-pressed', 'true')
->assertNoAccessibilityIssues(level: 2);
});
it('changes the language on the login page', function () {
auth()->logout();
visit(route('login'))
->click('button[value="en"]')
->assertScript('document.documentElement.lang', 'en')
->assertAttribute('button[value="en"]', 'aria-pressed', 'true')
->assertNoAccessibilityIssues(level: 2);
});
it('has no accessibility issues in the open profile menu', function (string $device, string $colorScheme) {
$page = visit(route('customers.index'));
$page = $device === 'mobile' ? $page->on()->mobile() : $page->on()->desktop();
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
$page->click(PROFILE_MENU)
->assertVisible('#profile-menu-panel')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);