diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 13b57bdc..8f6320b2 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -27,7 +27,7 @@ parameters: - # From the way the methods are inherited by the Browser object message: '#Call to an undefined method Laravel\\Dusk\\Browser::#' path: tests/Browser - count: 19 + count: 22 - # From the way the methods are inherited by Pest message: '#Function testNotifiedUpdate#' path: tests/Feature/Http/Controllers/Auth/PasswordForgottenControllerTest.php diff --git a/tests/Browser/Pages/Admin/Page/AdminEditPage.php b/tests/Browser/Pages/Admin/Page/AdminEditPage.php new file mode 100644 index 00000000..e47774ae --- /dev/null +++ b/tests/Browser/Pages/Admin/Page/AdminEditPage.php @@ -0,0 +1,33 @@ +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')); + } +} diff --git a/tests/Browser/Pages/AdminPage.php b/tests/Browser/Pages/AdminPage.php new file mode 100644 index 00000000..7ed7d720 --- /dev/null +++ b/tests/Browser/Pages/AdminPage.php @@ -0,0 +1,30 @@ +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'); + } +} diff --git a/tests/Browser/TestContent/Admin/PageAdminTest.php b/tests/Browser/TestContent/Admin/PageAdminTest.php new file mode 100644 index 00000000..3c498e73 --- /dev/null +++ b/tests/Browser/TestContent/Admin/PageAdminTest.php @@ -0,0 +1,55 @@ + 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') + ); + } +}