From 213227eeff5ffbc61dddc6a684bec446ff151dbe Mon Sep 17 00:00:00 2001 From: "M. D." Date: Sun, 21 Apr 2024 14:15:58 +0200 Subject: [PATCH 1/4] Add render registration test --- src/Handlers/StubHandler.php | 2 ++ src/Stubs/Base.php | 11 +++++++++ src/Stubs/Pages/Auth/Registration/Render.php | 26 ++++++++++++++++++++ stubs/Pages/Auth/Registration/Render.stub | 6 +++++ 4 files changed, 45 insertions(+) create mode 100644 src/Stubs/Pages/Auth/Registration/Render.php create mode 100644 stubs/Pages/Auth/Registration/Render.stub diff --git a/src/Handlers/StubHandler.php b/src/Handlers/StubHandler.php index c965d684..565d6e5c 100644 --- a/src/Handlers/StubHandler.php +++ b/src/Handlers/StubHandler.php @@ -25,6 +25,8 @@ public function getStubs(): Collection $stubs = [ \CodeWithDennis\FilamentTests\Stubs\SetupStub::make($resource)->get(), + \CodeWithDennis\FilamentTests\Stubs\Pages\Auth\Registration\Render::make($resource)->get(), + \CodeWithDennis\FilamentTests\Stubs\Resource\Page\Index\Render::make($resource)->get(), \CodeWithDennis\FilamentTests\Stubs\Resource\Page\Index\ListRecords::make($resource)->get(), \CodeWithDennis\FilamentTests\Stubs\Resource\Page\Index\ListRecordsPaginated::make($resource)->get(), diff --git a/src/Stubs/Base.php b/src/Stubs/Base.php index 450e3654..1d64c894 100644 --- a/src/Stubs/Base.php +++ b/src/Stubs/Base.php @@ -3,6 +3,7 @@ namespace CodeWithDennis\FilamentTests\Stubs; use Closure; +use Filament\Facades\Filament; use Filament\Forms\Form; use Filament\Resources\Pages\CreateRecord; use Filament\Resources\Pages\EditRecord; @@ -610,6 +611,16 @@ public function hasTableFilter(string $filter, Table $table): bool return $this->getResourceTableFilters($table)->map(fn ($filter) => $filter->getName())->contains($filter); } + public function getRegistrationRouteAction(): ?string + { + return Filament::getDefaultPanel()?->getRegistrationRouteAction(); + } + + public function hasRegistration(): bool + { + return Filament::hasRegistration(); + } + public function getDeferredLoadingMethod(): string { return "\n\t\t->loadTable()"; diff --git a/src/Stubs/Pages/Auth/Registration/Render.php b/src/Stubs/Pages/Auth/Registration/Render.php new file mode 100644 index 00000000..a4aa01d5 --- /dev/null +++ b/src/Stubs/Pages/Auth/Registration/Render.php @@ -0,0 +1,26 @@ +hasRegistration() + && $this->getRegistrationRouteAction(); + } + + public function getVariables(): array + { + return [ + 'REGISTRATION_ROUTE_ACTION' => str($this->getRegistrationRouteAction())->prepend('\\'), + ]; + } +} diff --git a/stubs/Pages/Auth/Registration/Render.stub b/stubs/Pages/Auth/Registration/Render.stub new file mode 100644 index 00000000..6d88d7ee --- /dev/null +++ b/stubs/Pages/Auth/Registration/Render.stub @@ -0,0 +1,6 @@ +it({{ DESCRIPTION }}, function () { + Auth::logout(); + + livewire({{ REGISTRATION_ROUTE_ACTION }}::class) + ->assertSuccessful(); +}){{ RESOLVED_GROUP_METHOD }}; From 94103af75ee0876f92242a5a351dcd84fccf2158 Mon Sep 17 00:00:00 2001 From: "M. D." Date: Sun, 21 Apr 2024 14:16:54 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f42e95f3..00bfc34d 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,10 @@ php artisan vendor:publish --tag="filament-tests-stubs" ``` ### Available Tests +- Pages + - Auth + - Registration + - [x] it can render the registration page - Resource - Page - Create From 7a003ee3b62513f0daeeaf492987cee234976e11 Mon Sep 17 00:00:00 2001 From: dissto Date: Sun, 21 Apr 2024 13:48:06 +0000 Subject: [PATCH 3/4] Pint: Fix code style issues --- src/Stubs/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stubs/Base.php b/src/Stubs/Base.php index 96e56372..55b5e639 100644 --- a/src/Stubs/Base.php +++ b/src/Stubs/Base.php @@ -620,7 +620,7 @@ public function hasRegistration(): bool { return Filament::hasRegistration(); } - + public function getLoginRouteAction(): ?string { return Filament::getDefaultPanel()?->getLoginRouteAction(); From bab48a402cee20d9ad45ddae1bec86bd6691a163 Mon Sep 17 00:00:00 2001 From: dissto Date: Sun, 21 Apr 2024 14:08:49 +0000 Subject: [PATCH 4/4] Pint: Fix code style issues --- src/Stubs/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stubs/Base.php b/src/Stubs/Base.php index aa928d03..8cac934f 100644 --- a/src/Stubs/Base.php +++ b/src/Stubs/Base.php @@ -620,7 +620,7 @@ public function hasRegistration(): bool { return Filament::hasRegistration(); } - + public function getRequestPasswordResetRouteAction(): ?string { return Filament::getDefaultPanel()?->getRequestPasswordResetRouteAction();