diff --git a/lang/fi/layout.php b/lang/fi/layout.php
index d7af331..5d4eb78 100644
--- a/lang/fi/layout.php
+++ b/lang/fi/layout.php
@@ -8,4 +8,5 @@ return [
'users' => 'Käyttäjät',
'signed_in_as' => 'Kirjautuneena: :name',
'logout' => 'Kirjaudu ulos',
+ 'theme_toggle' => 'Tumma teema',
];
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index 47d5c65..6cbf9be 100644
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -44,6 +44,8 @@
{{ __('layout.signed_in_as', ['name' => auth()->user()->name]) }}
+ @include('partials.theme-toggle')
+
+ @else
+
+ @include('partials.theme-toggle')
+
@endauth
diff --git a/resources/views/partials/theme-toggle.blade.php b/resources/views/partials/theme-toggle.blade.php
new file mode 100644
index 0000000..a833c66
--- /dev/null
+++ b/resources/views/partials/theme-toggle.blade.php
@@ -0,0 +1,19 @@
+{{--
+ Light/dark theme toggle. Flux stores the choice in localStorage
+ ("flux.appearance") and @fluxAppearance applies it before the page paints.
+ The name stays "Tumma teema"; aria-pressed tells whether it is on.
+--}}
+
+
+
+
diff --git a/tests/Browser/ThemeToggleTest.php b/tests/Browser/ThemeToggleTest.php
new file mode 100644
index 0000000..969a406
--- /dev/null
+++ b/tests/Browser/ThemeToggleTest.php
@@ -0,0 +1,48 @@
+on()->desktop()->inLightMode();
+
+ $page->assertScript('document.documentElement.classList.contains("dark")', false)
+ ->assertAttribute(THEME_TOGGLE, 'aria-pressed', 'false')
+ ->assertAttribute(THEME_TOGGLE, 'aria-label', 'Tumma teema')
+ ->click(THEME_TOGGLE)
+ ->assertScript('document.documentElement.classList.contains("dark")', true)
+ ->assertAttribute(THEME_TOGGLE, 'aria-pressed', 'true')
+ ->assertAttribute(THEME_TOGGLE, 'aria-label', 'Tumma teema')
+ ->assertScript('localStorage.getItem("flux.appearance")', 'dark')
+ ->assertNoAccessibilityIssues(level: 2);
+
+ $page->navigate(route('password.request'))
+ ->assertScript('document.documentElement.classList.contains("dark")', true)
+ ->click(THEME_TOGGLE)
+ ->assertScript('document.documentElement.classList.contains("dark")', false)
+ ->assertScript('localStorage.getItem("flux.appearance")', 'light')
+ ->assertNoAccessibilityIssues(level: 2);
+});
+
+it('overrides a dark system theme', function () {
+ visit(route('login'))->inDarkMode()
+ ->assertScript('document.documentElement.classList.contains("dark")', true)
+ ->assertAttribute(THEME_TOGGLE, 'aria-pressed', 'true')
+ ->click(THEME_TOGGLE)
+ ->assertScript('document.documentElement.classList.contains("dark")', false)
+ ->assertScript('localStorage.getItem("flux.appearance")', 'light');
+});
+
+it('is in the header for signed-in users and works with the keyboard', function () {
+ $this->actingAs(User::factory()->create());
+
+ visit(route('customers.index'))->inLightMode()
+ ->assertPresent('header '.THEME_TOGGLE)
+ ->keys(THEME_TOGGLE, 'Enter')
+ ->assertScript('document.documentElement.classList.contains("dark")', true)
+ ->assertScript('localStorage.getItem("flux.appearance")', 'dark');
+});
diff --git a/tests/Feature/HomePageTest.php b/tests/Feature/HomePageTest.php
index 0d3b706..3559e99 100644
--- a/tests/Feature/HomePageTest.php
+++ b/tests/Feature/HomePageTest.php
@@ -17,7 +17,8 @@ it('renders the home page with the main menu', function () {
->assertSee('Siirry pääsisältöön')
->assertSee('id="main-content"', false)
->assertSee('aria-label="Päävalikko"', false)
- ->assertSee('Kirjautuneena: Eero Esimerkki');
+ ->assertSee('Kirjautuneena: Eero Esimerkki')
+ ->assertSee('aria-label="Tumma teema"', false);
});
it('increments the click count', function () {