From 49997525bc0f1df46f1193dfd4d42684a5a7ecca Mon Sep 17 00:00:00 2001 From: Elliot Derhay Date: Sun, 7 Jul 2024 15:18:07 -0400 Subject: [PATCH] Minor progress Add a Livewire and Volt helpers for quickly checking that components can mount. Also discovering there's something wrong with finding the database. Sometimes it's there, sometimes the necessary tables are there...other times, not. --- tests/CreatesApplication.php | 3 ++- tests/Feature/Livewire/BlogIndexTest.php | 8 +------- tests/Feature/Livewire/BlogPostTest.php | 8 +------- tests/Pest.php | 22 +++++++++++++++++++--- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 4fd9d249..0cd55f3b 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -12,7 +12,8 @@ trait CreatesApplication */ public function createApplication(): Application { - $app = require __DIR__.'/../bootstrap/app.php'; + /** @var Application $app */ + $app = require __DIR__ . '/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); diff --git a/tests/Feature/Livewire/BlogIndexTest.php b/tests/Feature/Livewire/BlogIndexTest.php index 273a71f2..f58d9d6d 100644 --- a/tests/Feature/Livewire/BlogIndexTest.php +++ b/tests/Feature/Livewire/BlogIndexTest.php @@ -1,9 +1,3 @@ assertSee(''); -}); +voltMountable('blog-index'); diff --git a/tests/Feature/Livewire/BlogPostTest.php b/tests/Feature/Livewire/BlogPostTest.php index 72ab5565..fc326cff 100644 --- a/tests/Feature/Livewire/BlogPostTest.php +++ b/tests/Feature/Livewire/BlogPostTest.php @@ -1,9 +1,3 @@ assertSee(''); -}); +voltMountable('blog-post', ['post' => createPost()]); diff --git a/tests/Pest.php b/tests/Pest.php index eb5957a5..b433dbaf 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -11,14 +11,17 @@ | */ +use App\Actions\HashPassword; use App\Models\Image; use App\Models\Post; use App\Models\Project; use App\Models\User; use Illuminate\Foundation\Testing\DatabaseMigrations; +use Livewire\Livewire; +use Livewire\Volt\Volt; uses(Tests\TestCase::class, DatabaseMigrations::class) - ->in('Feature', 'Unit'); + ->in('Feature'); /* |-------------------------------------------------------------------------- @@ -56,6 +59,7 @@ function createPost(): Post return Post::factory()->createOne(); } + function createProject(): Project { return Project::factory()->createOne(); @@ -66,9 +70,9 @@ function createUser(): User return User::factory()->createOne(); } -function hashPassword(#[\SensitiveParameter] string $password): string +function hashPassword(#[SensitiveParameter] string $password): string { - $hashPassword = new \App\Actions\HashPassword(); + $hashPassword = new HashPassword(); return $hashPassword($password); } @@ -99,3 +103,15 @@ function makeUser(): User { return User::factory()->makeOne(); } + +// borrowed from Ryan Chandler: +// https://x.com/ryangjchandler/status/1808796458260341189 +function livewireMountable(string $class, array $params = []): void +{ + it('can be mounted', fn () => Livewire::test($class, $params)->assertOk()); +} + +function voltMountable(string $component, array $params = []): void +{ + it('can be mounted', fn () => Volt::test($component, $params)->assertOk()); +}