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('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'], ]);