Updated tests to align with recent list changes

This commit is contained in:
Dan Brown 2022-11-01 14:53:36 +00:00
parent d4e71e431b
commit f809bd3a62
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
6 changed files with 19 additions and 38 deletions

View File

@ -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);

View File

@ -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()

View File

@ -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()

View File

@ -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');
}

View File

@ -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()

View File

@ -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();