From 2a5250b2510187a58fa6569341f50aaf00ae34af Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sun, 12 May 2024 22:08:37 +0100 Subject: [PATCH 1/4] Create browser test abstract AdminPage --- tests/Browser/Pages/AdminPage.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Browser/Pages/AdminPage.php 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'); + } +} From cb72b1f094a7bf2c53f5e866f9bdf4db5847eca0 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sun, 12 May 2024 22:13:49 +0100 Subject: [PATCH 2/4] Create browser test AdminEditPage page class --- .../Pages/Admin/Page/AdminEditPage.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/Browser/Pages/Admin/Page/AdminEditPage.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')); + } +} From 0e88f04f573041014e0ab87e1b74339ef0be084a Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sun, 12 May 2024 22:44:06 +0100 Subject: [PATCH 3/4] Create Page admin browser tests --- .../TestContent/Admin/PageAdminTest.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Browser/TestContent/Admin/PageAdminTest.php 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') + ); + } +} From dcaf52c3cf923addd66cea7998c30adcb53bc91e Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Sun, 12 May 2024 22:47:11 +0100 Subject: [PATCH 4/4] Update PHPStan exceptions --- phpstan.dist.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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