Dark Mode: Fixed not toggle action when dark by default

Added test to cover.
For #4543.
This commit is contained in:
Dan Brown 2023-09-14 13:53:24 +01:00
parent 4ec600adfa
commit 417705651c
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 17 additions and 1 deletions

View File

@ -145,7 +145,7 @@ class UserPreferencesController extends Controller
*/
public function toggleDarkMode()
{
$enabled = setting()->getForCurrentUser('dark-mode-enabled', false);
$enabled = setting()->getForCurrentUser('dark-mode-enabled');
setting()->putForCurrentUser('dark-mode-enabled', $enabled ? 'false' : 'true');
return redirect()->back();

View File

@ -242,6 +242,22 @@ class UserPreferencesTest extends TestCase
$this->withHtml($home)->assertElementExists('.dark-mode');
}
public function test_dark_mode_toggle_endpoint_changes_to_light_when_dark_by_default()
{
config()->set('setting-defaults.user.dark-mode-enabled', true);
$editor = $this->users->editor();
$this->assertEquals(true, setting()->getUser($editor, 'dark-mode-enabled'));
$prefChange = $this->actingAs($editor)->patch('/preferences/toggle-dark-mode');
$prefChange->assertRedirect();
$this->assertEquals(false, setting()->getUser($editor, 'dark-mode-enabled'));
$home = $this->get('/');
$this->withHtml($home)->assertElementNotExists('.dark-mode');
$home->assertDontSee('Light Mode');
$home->assertSee('Dark Mode');
}
public function test_books_view_type_preferences_when_list()
{
$editor = $this->users->editor();