1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Updated tests to use ssddanbrown/asserthtml package

Closes #3519
This commit is contained in:
Dan Brown
2022-07-23 15:10:18 +01:00
parent cf73e5f2c6
commit 72c8b138e1
48 changed files with 869 additions and 1014 deletions

View File

@ -93,10 +93,10 @@ class UserApiTokenTest extends TestCase
$token = ApiToken::query()->latest()->first();
$resp = $this->get($editor->getEditUrl());
$resp->assertElementExists('#api_tokens');
$resp->assertElementContains('#api_tokens', $token->name);
$resp->assertElementContains('#api_tokens', $token->token_id);
$resp->assertElementContains('#api_tokens', $token->expires_at->format('Y-m-d'));
$this->withHtml($resp)->assertElementExists('#api_tokens');
$this->withHtml($resp)->assertElementContains('#api_tokens', $token->name);
$this->withHtml($resp)->assertElementContains('#api_tokens', $token->token_id);
$this->withHtml($resp)->assertElementContains('#api_tokens', $token->expires_at->format('Y-m-d'));
}
public function test_secret_shown_once_after_creation()
@ -161,7 +161,7 @@ class UserApiTokenTest extends TestCase
$resp = $this->get($tokenUrl . '/delete');
$resp->assertSeeText('Delete Token');
$resp->assertSeeText($token->name);
$resp->assertElementExists('form[action="' . $tokenUrl . '"]');
$this->withHtml($resp)->assertElementExists('form[action="' . $tokenUrl . '"]');
$resp = $this->delete($tokenUrl);
$resp->assertRedirect($editor->getEditUrl('#api_tokens'));

View File

@ -22,10 +22,10 @@ class UserManagementTest extends TestCase
$adminRole = Role::getRole('admin');
$resp = $this->asAdmin()->get('/settings/users');
$resp->assertElementContains('a[href="' . url('/settings/users/create') . '"]', 'Add New User');
$this->withHtml($resp)->assertElementContains('a[href="' . url('/settings/users/create') . '"]', 'Add New User');
$this->get('/settings/users/create')
->assertElementContains('form[action="' . url('/settings/users/create') . '"]', 'Save');
$resp =$this->get('/settings/users/create');
$this->withHtml($resp)->assertElementContains('form[action="' . url('/settings/users/create') . '"]', 'Save');
$resp = $this->post('/settings/users/create', [
'name' => $user->name,
@ -166,7 +166,7 @@ class UserManagementTest extends TestCase
$guest = User::getDefault();
$resp = $this->asAdmin()->get('/settings/users/' . $guest->id);
$resp->assertSee('Guest');
$resp->assertElementNotExists('#password');
$this->withHtml($resp)->assertElementNotExists('#password');
}
public function test_guest_profile_cannot_be_deleted()
@ -175,7 +175,7 @@ class UserManagementTest extends TestCase
$resp = $this->asAdmin()->get('/settings/users/' . $guestUser->id . '/delete');
$resp->assertSee('Delete User');
$resp->assertSee('Guest');
$resp->assertElementContains('form[action$="/settings/users/' . $guestUser->id . '"] button', 'Confirm');
$this->withHtml($resp)->assertElementContains('form[action$="/settings/users/' . $guestUser->id . '"] button', 'Confirm');
$resp = $this->delete('/settings/users/' . $guestUser->id);
$resp->assertRedirect('/settings/users/' . $guestUser->id);
@ -189,7 +189,7 @@ class UserManagementTest extends TestCase
foreach ($langs as $lang) {
config()->set('app.locale', $lang);
$resp = $this->asAdmin()->get('/settings/users/create');
$resp->assertElementExists('select[name="language"] option[value="' . $lang . '"][selected]');
$this->withHtml($resp)->assertElementExists('select[name="language"] option[value="' . $lang . '"][selected]');
}
}

View File

@ -81,8 +81,8 @@ class UserPreferencesTest extends TestCase
public function test_toggle_dark_mode()
{
$home = $this->actingAs($this->getEditor())->get('/');
$home->assertElementNotExists('.dark-mode');
$home->assertSee('Dark Mode');
$this->withHtml($home)->assertElementNotExists('.dark-mode');
$this->assertEquals(false, setting()->getForCurrentUser('dark-mode-enabled', false));
$prefChange = $this->patch('/settings/users/toggle-dark-mode');
@ -90,7 +90,7 @@ class UserPreferencesTest extends TestCase
$this->assertEquals(true, setting()->getForCurrentUser('dark-mode-enabled'));
$home = $this->actingAs($this->getEditor())->get('/');
$home->assertElementExists('.dark-mode');
$this->withHtml($home)->assertElementExists('.dark-mode');
$home->assertDontSee('Dark Mode');
$home->assertSee('Light Mode');
}
@ -100,12 +100,12 @@ class UserPreferencesTest extends TestCase
config()->set('setting-defaults.user.dark-mode-enabled', false);
$this->assertEquals(false, setting()->getForCurrentUser('dark-mode-enabled'));
$home = $this->get('/login');
$home->assertElementNotExists('.dark-mode');
$this->withHtml($home)->assertElementNotExists('.dark-mode');
config()->set('setting-defaults.user.dark-mode-enabled', true);
$this->assertEquals(true, setting()->getForCurrentUser('dark-mode-enabled'));
$home = $this->get('/login');
$home->assertElementExists('.dark-mode');
$this->withHtml($home)->assertElementExists('.dark-mode');
}
public function test_books_view_type_preferences_when_list()
@ -113,7 +113,8 @@ class UserPreferencesTest extends TestCase
$editor = $this->getEditor();
setting()->putUser($editor, 'books_view_type', 'list');
$this->actingAs($editor)->get('/books')
$resp = $this->actingAs($editor)->get('/books');
$this->withHtml($resp)
->assertElementNotExists('.featured-image-container')
->assertElementExists('.content-wrap .entity-list-item');
}
@ -123,8 +124,8 @@ class UserPreferencesTest extends TestCase
$editor = $this->getEditor();
setting()->putUser($editor, 'books_view_type', 'grid');
$this->actingAs($editor)->get('/books')
->assertElementExists('.featured-image-container');
$resp = $this->actingAs($editor)->get('/books');
$this->withHtml($resp)->assertElementExists('.featured-image-container');
}
public function test_shelf_view_type_change()
@ -134,17 +135,20 @@ class UserPreferencesTest extends TestCase
$shelf = Bookshelf::query()->first();
setting()->putUser($editor, 'bookshelf_view_type', 'list');
$this->actingAs($editor)->get($shelf->getUrl())
$resp = $this->actingAs($editor)->get($shelf->getUrl())->assertSee('Grid View');
$this->withHtml($resp)
->assertElementNotExists('.featured-image-container')
->assertElementExists('.content-wrap .entity-list-item')
->assertSee('Grid View');
->assertElementExists('.content-wrap .entity-list-item');
$req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
$req->assertRedirect($shelf->getUrl());
$this->actingAs($editor)->get($shelf->getUrl())
->assertElementExists('.featured-image-container')
->assertElementNotExists('.content-wrap .entity-list-item')
$resp = $this->actingAs($editor)->get($shelf->getUrl())
->assertSee('List View');
$this->withHtml($resp)
->assertElementExists('.featured-image-container')
->assertElementNotExists('.content-wrap .entity-list-item');
}
}

View File

@ -44,17 +44,17 @@ class UserProfileTest extends TestCase
{
$newUser = User::factory()->create();
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name)
->assertElementContains('#content-counts', '0 Books')
$resp = $this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name);
$this->withHtml($resp)->assertElementContains('#content-counts', '0 Books')
->assertElementContains('#content-counts', '0 Chapters')
->assertElementContains('#content-counts', '0 Pages');
$this->createEntityChainBelongingToUser($newUser, $newUser);
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name)
->assertElementContains('#content-counts', '1 Book')
$resp = $this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name);
$this->withHtml($resp)->assertElementContains('#content-counts', '1 Book')
->assertElementContains('#content-counts', '1 Chapter')
->assertElementContains('#content-counts', '1 Page');
}
@ -67,8 +67,8 @@ class UserProfileTest extends TestCase
Activity::add(ActivityType::BOOK_UPDATE, $entities['book']);
Activity::add(ActivityType::PAGE_CREATE, $entities['page']);
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertElementContains('#recent-user-activity', 'updated book')
$resp = $this->asAdmin()->get('/user/' . $newUser->slug);
$this->withHtml($resp)->assertElementContains('#recent-user-activity', 'updated book')
->assertElementContains('#recent-user-activity', 'created page')
->assertElementContains('#recent-user-activity', $entities['page']->name);
}
@ -82,8 +82,8 @@ class UserProfileTest extends TestCase
Activity::add(ActivityType::PAGE_CREATE, $entities['page']);
$linkSelector = '#recent-activity a[href$="/user/' . $newUser->slug . '"]';
$this->asAdmin()->get('/')
->assertElementContains($linkSelector, $newUser->name);
$resp = $this->asAdmin()->get('/');
$this->withHtml($resp)->assertElementContains($linkSelector, $newUser->name);
}
public function test_profile_has_search_links_in_created_entity_lists()
@ -99,7 +99,7 @@ class UserProfileTest extends TestCase
];
foreach ($expectedLinks as $link) {
$resp->assertElementContains('[href$="' . $link . '"]', 'View All');
$this->withHtml($resp)->assertElementContains('[href$="' . $link . '"]', 'View All');
}
}
}