From 73633d76289baafdb8871ad798f581bd57e658dc Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 27 Jun 2024 17:50:18 +0200 Subject: [PATCH] Move component assertion --- tests/EndToEnd/Member/IndexTest.php | 3 +-- tests/Feature/Authentication/ForgotPasswordTest.php | 4 +--- tests/Fileshare/FileshareIndexActionTest.php | 7 +++++++ tests/Lib/TestsInertia.php | 5 ----- tests/TestCase.php | 7 +++++++ tests/stub/phpstan/TestResponse.stub | 1 + 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/EndToEnd/Member/IndexTest.php b/tests/EndToEnd/Member/IndexTest.php index a5c0a25e..02f4ccda 100644 --- a/tests/EndToEnd/Member/IndexTest.php +++ b/tests/EndToEnd/Member/IndexTest.php @@ -25,9 +25,8 @@ class IndexTest extends EndToEndTestCase ]); sleep(1); - $response = $this->get('/member'); + $response = $this->get('/member')->assertComponent('member/VIndex'); - $this->assertComponent('member/VIndex', $response); $this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname'); $this->assertInertiaHas(false, $response, 'data.data.0.has_nami'); $this->assertInertiaHas('Kölner Str 3, 33333 Hilden', $response, 'data.data.0.full_address'); diff --git a/tests/Feature/Authentication/ForgotPasswordTest.php b/tests/Feature/Authentication/ForgotPasswordTest.php index 81682a13..c0688cfa 100644 --- a/tests/Feature/Authentication/ForgotPasswordTest.php +++ b/tests/Feature/Authentication/ForgotPasswordTest.php @@ -15,9 +15,7 @@ class ForgotPasswordTest extends TestCase public function testItShowsResetForm(): void { $this->withoutExceptionHandling(); - $response = $this->get('/password/reset'); - - $this->assertComponent('authentication/PasswordReset', $response); + $this->get('/password/reset')->assertComponent('authentication/PasswordReset'); } public function testItRequiresAnEmailAddress(): void diff --git a/tests/Fileshare/FileshareIndexActionTest.php b/tests/Fileshare/FileshareIndexActionTest.php index 6add6779..b5e24e44 100644 --- a/tests/Fileshare/FileshareIndexActionTest.php +++ b/tests/Fileshare/FileshareIndexActionTest.php @@ -33,4 +33,11 @@ class FileshareIndexActionTest extends FileshareTestCase ->assertInertiaPath('data.meta.types.0.defaults.base_url', '') ->assertInertiaPath('data.meta.types.0.fields.1', ['label' => 'Benutzer', 'key' => 'user', 'type' => 'text']); } + + public function testItRendersComponent(): void + { + $this->withoutExceptionHandling()->login()->loginNami(); + + $this->get('/setting/fileshare')->assertComponent('fileshareconnection/Index'); + } } diff --git a/tests/Lib/TestsInertia.php b/tests/Lib/TestsInertia.php index bcca1256..bc71f867 100644 --- a/tests/Lib/TestsInertia.php +++ b/tests/Lib/TestsInertia.php @@ -22,11 +22,6 @@ trait TestsInertia $this->assertInertiaDeepNest($bindings, $viewData); } - public function assertComponent(string $component, TestResponse $response): void - { - PHPUnit::assertEquals($component, $response->viewData('page')['component']); - } - /** * @param mixed $should * @param mixed $is diff --git a/tests/TestCase.php b/tests/TestCase.php index f75fe0f1..14e5c4dc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -133,6 +133,13 @@ abstract class TestCase extends BaseTestCase return $this; }); + TestResponse::macro('assertComponent', function (string $component) { + /** @var TestResponse */ + $response = $this; + Assert::assertEquals($component, data_get($response->viewData('page'), 'component')); + return $this; + }); + TestResponse::macro('assertPdfPageCount', function (int $count) { /** @var TestResponse */ $response = $this; diff --git a/tests/stub/phpstan/TestResponse.stub b/tests/stub/phpstan/TestResponse.stub index ca140fb9..0b80ebda 100644 --- a/tests/stub/phpstan/TestResponse.stub +++ b/tests/stub/phpstan/TestResponse.stub @@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\File\File; * @method self assertPdfPageCount(int $count) * @method self assertPdfName(string $filename) * @method self assertHasJsonPath(string $path) + * @method self assertComponnet(string $component) * @method File getFile() */ class TestResponse