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);
$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');

View File

@ -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

View File

@ -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');
}
}

View File

@ -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

View File

@ -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;

View File

@ -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