-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from musimana/feature/AdminEditPageTests
feat: Admin Edit Page Tests
- Loading branch information
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Tests\Browser\Pages\Admin\Page; | ||
|
||
use App\Models\Page; | ||
use Laravel\Dusk\Browser; | ||
use Tests\Browser\Pages\AdminPage; | ||
|
||
final class AdminEditPage extends AdminPage | ||
{ | ||
/** Instantiate the class. */ | ||
public function __construct( | ||
private Page $page | ||
) { | ||
} | ||
|
||
/** Get the URL for the page. */ | ||
public function url(): string | ||
{ | ||
return $this->page->getUrlEdit(); | ||
} | ||
|
||
/** Assert that the browser is on the page. */ | ||
public function assert(Browser $browser): void | ||
{ | ||
$browser | ||
->assertHasLoadedCorrectly($this->url()) | ||
->assertHasCorrectCookies() | ||
->assertHasRenderedCorrectly($this->page->getTitle()) | ||
|
||
->pause(config('dusk.pause_length')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Tests\Browser\Pages; | ||
|
||
use Laravel\Dusk\Browser; | ||
use Tests\Browser\Traits\HasForm; | ||
|
||
abstract class AdminPage extends Page | ||
{ | ||
use HasForm; | ||
|
||
/** Assert the page has loaded correctly. */ | ||
public function assertHasLoadedCorrectly(Browser $browser, string $url): void | ||
{ | ||
$browser | ||
->waitForLocation($url, config('tests.wait_length')) | ||
->assertUrlIs($url) | ||
->assertScript('window.__VUE__') | ||
->assertScript('document.readyState', 'complete'); | ||
} | ||
|
||
/** Assert the page has rendered correctly. */ | ||
public function assertHasRenderedCorrectly(Browser $browser, string $title): void | ||
{ | ||
$browser | ||
->assertTitle($title . ' - ' . config('app.name')) | ||
->assertVisible('#app') | ||
->assertVisible('main'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Tests\Browser\TestContent\Admin; | ||
|
||
use App\Models\Page; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\DatabaseTruncation; | ||
use Laravel\Dusk\Browser; | ||
use PHPUnit\Framework\Assert; | ||
use Tests\Browser\Pages\Admin\Page\AdminEditPage; | ||
use Tests\DuskTestCase; | ||
|
||
final class PageAdminTest extends DuskTestCase | ||
{ | ||
use DatabaseTruncation; | ||
|
||
/** Test the admin page edit view renders & behaves correctly. */ | ||
public function testAdminPageEdit(): void | ||
{ | ||
$initial_array = [ | ||
'in_sitemap' => 0, | ||
'meta_description' => 'Old meta-description.', | ||
'meta_title' => 'Old Title', | ||
'subtitle' => 'Old subtitle', | ||
'title' => 'Old Title', | ||
]; | ||
|
||
$expected_array = [ | ||
'title' => 'New Title', | ||
'subtitle' => 'New subtitle', | ||
'metaTitle' => 'New meta-title', | ||
'metaDescription' => 'New meta-description.', | ||
'inSitemap' => ['type' => 'checkbox'], | ||
]; | ||
|
||
$page = Page::factory()->create($initial_array); | ||
$user = User::factory()->isAdmin()->create(); | ||
|
||
Assert::assertTrue($page->title === $initial_array['title']); | ||
Assert::assertTrue($page->subtitle === $initial_array['subtitle']); | ||
Assert::assertTrue($page->meta_title === $initial_array['meta_title']); | ||
Assert::assertTrue($page->meta_description === $initial_array['meta_description']); | ||
Assert::assertFalse($page->in_sitemap); | ||
|
||
$this->browse(fn (Browser $browser) => $browser | ||
->loginAs($user) | ||
|
||
->visit(new AdminEditPage($page)) | ||
->screenshotWholePage('admin-pages-edit-blank') | ||
->completeForm('form', $expected_array) | ||
->screenshotWholePage('admin-pages-edit-filled') | ||
->submitForm('form') | ||
); | ||
} | ||
} |