Move component assertion

This commit is contained in:
philipp lang 2024-06-27 17:50:18 +02:00
parent 5482d47f0c
commit 73633d7628
6 changed files with 17 additions and 10 deletions

View File

@ -25,9 +25,8 @@ class IndexTest extends EndToEndTestCase
]); ]);
sleep(1); 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('::firstname::', $response, 'data.data.0.firstname');
$this->assertInertiaHas(false, $response, 'data.data.0.has_nami'); $this->assertInertiaHas(false, $response, 'data.data.0.has_nami');
$this->assertInertiaHas('Kölner Str 3, 33333 Hilden', $response, 'data.data.0.full_address'); $this->assertInertiaHas('Kölner Str 3, 33333 Hilden', $response, 'data.data.0.full_address');

View File

@ -15,9 +15,7 @@ class ForgotPasswordTest extends TestCase
public function testItShowsResetForm(): void public function testItShowsResetForm(): void
{ {
$this->withoutExceptionHandling(); $this->withoutExceptionHandling();
$response = $this->get('/password/reset'); $this->get('/password/reset')->assertComponent('authentication/PasswordReset');
$this->assertComponent('authentication/PasswordReset', $response);
} }
public function testItRequiresAnEmailAddress(): void public function testItRequiresAnEmailAddress(): void

View File

@ -33,4 +33,11 @@ class FileshareIndexActionTest extends FileshareTestCase
->assertInertiaPath('data.meta.types.0.defaults.base_url', '') ->assertInertiaPath('data.meta.types.0.defaults.base_url', '')
->assertInertiaPath('data.meta.types.0.fields.1', ['label' => 'Benutzer', 'key' => 'user', 'type' => 'text']); ->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');
}
} }

View File

@ -22,11 +22,6 @@ trait TestsInertia
$this->assertInertiaDeepNest($bindings, $viewData); $this->assertInertiaDeepNest($bindings, $viewData);
} }
public function assertComponent(string $component, TestResponse $response): void
{
PHPUnit::assertEquals($component, $response->viewData('page')['component']);
}
/** /**
* @param mixed $should * @param mixed $should
* @param mixed $is * @param mixed $is

View File

@ -133,6 +133,13 @@ abstract class TestCase extends BaseTestCase
return $this; 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) { TestResponse::macro('assertPdfPageCount', function (int $count) {
/** @var TestResponse */ /** @var TestResponse */
$response = $this; $response = $this;

View File

@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\File\File;
* @method self assertPdfPageCount(int $count) * @method self assertPdfPageCount(int $count)
* @method self assertPdfName(string $filename) * @method self assertPdfName(string $filename)
* @method self assertHasJsonPath(string $path) * @method self assertHasJsonPath(string $path)
* @method self assertComponnet(string $component)
* @method File getFile() * @method File getFile()
*/ */
class TestResponse class TestResponse