7 class UserPreferencesTest extends TestCase
9 public function test_update_sort_preference()
11 $editor = $this->getEditor();
12 $this->actingAs($editor);
14 $updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/books', [
15 'sort' => 'created_at',
18 $updateRequest->assertStatus(302);
20 $this->assertDatabaseHas('settings', [
21 'setting_key' => 'user:' . $editor->id . ':books_sort',
22 'value' => 'created_at',
24 $this->assertDatabaseHas('settings', [
25 'setting_key' => 'user:' . $editor->id . ':books_sort_order',
28 $this->assertEquals('created_at', setting()->getForCurrentUser('books_sort'));
29 $this->assertEquals('desc', setting()->getForCurrentUser('books_sort_order'));
32 public function test_update_sort_preference_defaults()
34 $editor = $this->getEditor();
35 $this->actingAs($editor);
37 $updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/bookshelves', [
41 $updateRequest->assertStatus(302);
43 $this->assertEquals('name', setting()->getForCurrentUser('bookshelves_sort'));
44 $this->assertEquals('asc', setting()->getForCurrentUser('bookshelves_sort_order'));
47 public function test_update_sort_bad_entity_type_handled()
49 $editor = $this->getEditor();
50 $this->actingAs($editor);
52 $updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/dogs', [
56 $updateRequest->assertStatus(500);
58 $this->assertNotEmpty('name', setting()->getForCurrentUser('bookshelves_sort'));
59 $this->assertNotEmpty('asc', setting()->getForCurrentUser('bookshelves_sort_order'));
62 public function test_update_expansion_preference()
64 $editor = $this->getEditor();
65 $this->actingAs($editor);
67 $updateRequest = $this->patch('/settings/users/' . $editor->id . '/update-expansion-preference/home-details', ['expand' => 'true']);
68 $updateRequest->assertStatus(204);
70 $this->assertDatabaseHas('settings', [
71 'setting_key' => 'user:' . $editor->id . ':section_expansion#home-details',
74 $this->assertEquals(true, setting()->getForCurrentUser('section_expansion#home-details'));
76 $invalidKeyRequest = $this->patch('/settings/users/' . $editor->id . '/update-expansion-preference/my-home-details', ['expand' => 'true']);
77 $invalidKeyRequest->assertStatus(500);
80 public function test_toggle_dark_mode()
82 $home = $this->actingAs($this->getEditor())->get('/');
83 $home->assertSee('Dark Mode');
84 $this->withHtml($home)->assertElementNotExists('.dark-mode');
86 $this->assertEquals(false, setting()->getForCurrentUser('dark-mode-enabled', false));
87 $prefChange = $this->patch('/settings/users/toggle-dark-mode');
88 $prefChange->assertRedirect();
89 $this->assertEquals(true, setting()->getForCurrentUser('dark-mode-enabled'));
91 $home = $this->actingAs($this->getEditor())->get('/');
92 $this->withHtml($home)->assertElementExists('.dark-mode');
93 $home->assertDontSee('Dark Mode');
94 $home->assertSee('Light Mode');
97 public function test_dark_mode_defaults_to_config_option()
99 config()->set('setting-defaults.user.dark-mode-enabled', false);
100 $this->assertEquals(false, setting()->getForCurrentUser('dark-mode-enabled'));
101 $home = $this->get('/login');
102 $this->withHtml($home)->assertElementNotExists('.dark-mode');
104 config()->set('setting-defaults.user.dark-mode-enabled', true);
105 $this->assertEquals(true, setting()->getForCurrentUser('dark-mode-enabled'));
106 $home = $this->get('/login');
107 $this->withHtml($home)->assertElementExists('.dark-mode');
110 public function test_books_view_type_preferences_when_list()
112 $editor = $this->getEditor();
113 setting()->putUser($editor, 'books_view_type', 'list');
115 $resp = $this->actingAs($editor)->get('/books');
116 $this->withHtml($resp)
117 ->assertElementNotExists('.featured-image-container')
118 ->assertElementExists('.content-wrap .entity-list-item');
121 public function test_books_view_type_preferences_when_grid()
123 $editor = $this->getEditor();
124 setting()->putUser($editor, 'books_view_type', 'grid');
126 $resp = $this->actingAs($editor)->get('/books');
127 $this->withHtml($resp)->assertElementExists('.featured-image-container');
130 public function test_shelf_view_type_change()
132 $editor = $this->getEditor();
133 $shelf = $this->entities->shelf();
134 setting()->putUser($editor, 'bookshelf_view_type', 'list');
136 $resp = $this->actingAs($editor)->get($shelf->getUrl())->assertSee('Grid View');
137 $this->withHtml($resp)
138 ->assertElementNotExists('.featured-image-container')
139 ->assertElementExists('.content-wrap .entity-list-item');
141 $req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
142 $req->assertRedirect($shelf->getUrl());
144 $resp = $this->actingAs($editor)->get($shelf->getUrl())
145 ->assertSee('List View');
147 $this->withHtml($resp)
148 ->assertElementExists('.featured-image-container')
149 ->assertElementNotExists('.content-wrap .entity-list-item');
152 public function test_update_code_language_favourite()
154 $editor = $this->getEditor();
155 $page = $this->entities->page();
156 $this->actingAs($editor);
158 $this->patch('/settings/users/update-code-language-favourite', ['language' => 'php', 'active' => true]);
159 $this->patch('/settings/users/update-code-language-favourite', ['language' => 'javascript', 'active' => true]);
161 $resp = $this->get($page->getUrl('/edit'));
162 $resp->assertSee('option:code-editor:favourites="php,javascript"', false);
164 $this->patch('/settings/users/update-code-language-favourite', ['language' => 'ruby', 'active' => true]);
165 $this->patch('/settings/users/update-code-language-favourite', ['language' => 'php', 'active' => false]);
167 $resp = $this->get($page->getUrl('/edit'));
168 $resp->assertSee('option:code-editor:favourites="javascript,ruby"', false);