diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index f38bd71df..c3c8d1066 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -10,13 +10,15 @@ use BookStack\Entities\Queries\TopFavourites; use BookStack\Entities\Repos\BookRepo; use BookStack\Entities\Repos\BookshelfRepo; use BookStack\Entities\Tools\PageContent; +use BookStack\Util\SimpleListOptions; +use Illuminate\Http\Request; class HomeController extends Controller { /** * Display the homepage. */ - public function index(ActivityQueries $activities) + public function index(Request $request, ActivityQueries $activities) { $activity = $activities->latest(10); $draftPages = []; @@ -61,33 +63,27 @@ class HomeController extends Controller if ($homepageOption === 'bookshelves' || $homepageOption === 'books') { $key = $homepageOption; $view = setting()->getForCurrentUser($key . '_view_type'); - $sort = setting()->getForCurrentUser($key . '_sort', 'name'); - $order = setting()->getForCurrentUser($key . '_sort_order', 'asc'); - - $sortOptions = [ - 'name' => trans('common.sort_name'), + $listOptions = SimpleListOptions::fromRequest($request, $key)->withSortOptions([ + 'name' => trans('common.sort_name'), 'created_at' => trans('common.sort_created_at'), 'updated_at' => trans('common.sort_updated_at'), - ]; + ]); $commonData = array_merge($commonData, [ 'view' => $view, - 'sort' => $sort, - 'order' => $order, - 'sortOptions' => $sortOptions, + 'listOptions' => $listOptions, ]); } if ($homepageOption === 'bookshelves') { - $shelves = app(BookshelfRepo::class)->getAllPaginated(18, $commonData['sort'], $commonData['order']); + $shelves = app(BookshelfRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder()); $data = array_merge($commonData, ['shelves' => $shelves]); return view('home.shelves', $data); } if ($homepageOption === 'books') { - $bookRepo = app(BookRepo::class); - $books = $bookRepo->getAllPaginated(18, $commonData['sort'], $commonData['order']); + $books = app(BookRepo::class)->getAllPaginated(18, $commonData['listOptions']->getSort(), $commonData['listOptions']->getOrder()); $data = array_merge($commonData, ['books' => $books]); return view('home.books', $data); diff --git a/tests/Actions/AuditLogTest.php b/tests/Actions/AuditLogTest.php index 987e23a45..25fa2b796 100644 --- a/tests/Actions/AuditLogTest.php +++ b/tests/Actions/AuditLogTest.php @@ -51,7 +51,7 @@ class AuditLogTest extends TestCase $resp->assertSeeText($page->name); $resp->assertSeeText('page_create'); $resp->assertSeeText($activity->created_at->toDateTimeString()); - $this->withHtml($resp)->assertElementContains('.table-user-item', $admin->name); + $this->withHtml($resp)->assertElementContains('a[href*="users/' . $admin->id . '"]', $admin->name); } public function test_shows_name_for_deleted_items() diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index d00ec5ce5..0749888c8 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -195,12 +195,12 @@ class PageRevisionTest extends TestCase $this->createRevisions($page, 1, ['html' => 'new page html']); $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions')); - $this->withHtml($resp)->assertElementContains('td', '(WYSIWYG)'); - $this->withHtml($resp)->assertElementNotContains('td', '(Markdown)'); + $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'WYSIWYG)'); + $this->withHtml($resp)->assertElementNotContains('.item-list-row > div:nth-child(2)', 'Markdown)'); $this->createRevisions($page, 1, ['markdown' => '# Some markdown content']); $resp = $this->get($page->refresh()->getUrl('/revisions')); - $this->withHtml($resp)->assertElementContains('td', '(Markdown)'); + $this->withHtml($resp)->assertElementContains('.item-list-row > div:nth-child(2)', 'Markdown)'); } public function test_revision_restore_action_only_visible_with_permission() diff --git a/tests/Entity/TagTest.php b/tests/Entity/TagTest.php index ed5c798a5..ab06686e0 100644 --- a/tests/Entity/TagTest.php +++ b/tests/Entity/TagTest.php @@ -164,7 +164,7 @@ class TagTest extends TestCase $resp->assertSee('OtherTestContent'); $resp->assertDontSee('OtherTagName'); $resp->assertSee('Active Filter:'); - $this->withHtml($resp)->assertElementCount('table .tag-item', 2); + $this->withHtml($resp)->assertElementCount('.item-list .tag-item', 2); $this->withHtml($resp)->assertElementContains('form[action$="/tags"]', 'Clear Filter'); } diff --git a/tests/Settings/RecycleBinTest.php b/tests/Settings/RecycleBinTest.php index 3d27e9c8d..990df607e 100644 --- a/tests/Settings/RecycleBinTest.php +++ b/tests/Settings/RecycleBinTest.php @@ -62,11 +62,11 @@ class RecycleBinTest extends TestCase $viewReq = $this->asAdmin()->get('/settings/recycle-bin'); $html = $this->withHtml($viewReq); - $html->assertElementContains('table.table', $page->name); - $html->assertElementContains('table.table', $editor->name); - $html->assertElementContains('table.table', $book->name); - $html->assertElementContains('table.table', $book->pages_count . ' Pages'); - $html->assertElementContains('table.table', $book->chapters_count . ' Chapters'); + $html->assertElementContains('.item-list-row', $page->name); + $html->assertElementContains('.item-list-row', $editor->name); + $html->assertElementContains('.item-list-row', $book->name); + $html->assertElementContains('.item-list-row', $book->pages_count . ' Pages'); + $html->assertElementContains('.item-list-row', $book->chapters_count . ' Chapters'); } public function test_recycle_bin_empty() diff --git a/tests/User/UserPreferencesTest.php b/tests/User/UserPreferencesTest.php index c65b11d7d..92e4158cd 100644 --- a/tests/User/UserPreferencesTest.php +++ b/tests/User/UserPreferencesTest.php @@ -29,21 +29,6 @@ class UserPreferencesTest extends TestCase $this->assertEquals('desc', setting()->getForCurrentUser('books_sort_order')); } - public function test_update_sort_preference_defaults() - { - $editor = $this->getEditor(); - $this->actingAs($editor); - - $updateRequest = $this->patch('/settings/users/' . $editor->id . '/change-sort/bookshelves', [ - 'sort' => 'cat', - 'order' => 'dog', - ]); - $updateRequest->assertStatus(302); - - $this->assertEquals('name', setting()->getForCurrentUser('bookshelves_sort')); - $this->assertEquals('asc', setting()->getForCurrentUser('bookshelves_sort_order')); - } - public function test_update_sort_bad_entity_type_handled() { $editor = $this->getEditor();