]> BookStack Code Mirror - bookstack/commitdiff
Added tests and translations for dark-mode components 2022/head
authorDan Brown <redacted>
Sat, 11 Apr 2020 19:44:23 +0000 (20:44 +0100)
committerDan Brown <redacted>
Sat, 11 Apr 2020 19:44:23 +0000 (20:44 +0100)
resources/lang/en/common.php
resources/views/common/header.blade.php
tests/User/UserPreferencesTest.php

index c8b4a2b223e3afb602017a5ad43d9b5193a1dc02..68c58b92ba4e9243fd1afae7eca30ed89feab4df 100644 (file)
@@ -66,6 +66,8 @@ return [
     'profile_menu' => 'Profile Menu',
     'view_profile' => 'View Profile',
     'edit_profile' => 'Edit Profile',
+    'dark_mode' => 'Dark Mode',
+    'light_mode' => 'Light Mode',
 
     // Layout tabs
     'tab_info' => 'Info',
index af7aaeeb0ee8ec3cb498867c3084ac91b2d6621b..98bd01788cd3b3960951c0c6e7ea9fefd18b4cda 100644 (file)
@@ -76,9 +76,9 @@
                                     {{ csrf_field() }}
                                     {{ method_field('patch') }}
                                     @if(setting()->getForCurrentUser('dark-mode-enabled'))
-                                        <button>@icon('light-mode')Light Mode</button>
+                                        <button>@icon('light-mode'){{ trans('common.light_mode') }}</button>
                                     @else
-                                        <button>@icon('dark-mode')Dark Mode</button>
+                                        <button>@icon('dark-mode'){{ trans('common.dark_mode') }}</button>
                                     @endif
                                 </form>
                             </li>
index b70d52dfa85f3d3dea3a5d1d378d2c9cd17f5951..0db4f803aff0bf268f4004b2339280dba10cc3fd 100644 (file)
@@ -75,4 +75,21 @@ class UserPreferencesTest extends TestCase
         $invalidKeyRequest = $this->patch('/settings/users/' . $editor->id.'/update-expansion-preference/my-home-details', ['expand' => 'true']);
         $invalidKeyRequest->assertStatus(500);
     }
+
+    public function test_toggle_dark_mode()
+    {
+        $home = $this->actingAs($this->getEditor())->get('/');
+        $home->assertElementNotExists('.dark-mode');
+        $home->assertSee('Dark Mode');
+
+        $this->assertEquals(false, setting()->getForCurrentUser('dark-mode-enabled', false));
+        $prefChange = $this->patch('/settings/users/toggle-dark-mode');
+        $prefChange->assertRedirect();
+        $this->assertEquals(true, setting()->getForCurrentUser('dark-mode-enabled'));
+
+        $home = $this->actingAs($this->getEditor())->get('/');
+        $home->assertElementExists('.dark-mode');
+        $home->assertDontSee('Dark Mode');
+        $home->assertSee('Light Mode');
+    }
 }
\ No newline at end of file