Skip to content

Commit

Permalink
Merge pull request #171 from dissto/add-register-test
Browse files Browse the repository at this point in the history
Add render registration test
  • Loading branch information
CodeWithDennis authored Apr 21, 2024
2 parents 98c9adc + bab48a4 commit b3cffd8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ php artisan vendor:publish --tag="filament-tests-stubs"
- Pages
- Auth
- Registration
- [x] it can render the registration page
- PasswordReset
- [x] it can render the password reset page
- Login
Expand Down
1 change: 1 addition & 0 deletions src/Handlers/StubHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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\Pages\Auth\PasswordReset\Render::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Pages\Auth\Login\Render::make($resource)->get(),

Expand Down
10 changes: 10 additions & 0 deletions src/Stubs/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,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 getRequestPasswordResetRouteAction(): ?string
{
return Filament::getDefaultPanel()?->getRequestPasswordResetRouteAction();
Expand Down
26 changes: 26 additions & 0 deletions src/Stubs/Pages/Auth/Registration/Render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace CodeWithDennis\FilamentTests\Stubs\Pages\Auth\Registration;

use CodeWithDennis\FilamentTests\Stubs\Base;

class Render extends Base
{
public function getDescription(): string
{
return 'can render the registration page';
}

public function getShouldGenerate(): bool
{
return $this->hasRegistration()
&& $this->getRegistrationRouteAction();
}

public function getVariables(): array
{
return [
'REGISTRATION_ROUTE_ACTION' => str($this->getRegistrationRouteAction())->prepend('\\'),
];
}
}
6 changes: 6 additions & 0 deletions stubs/Pages/Auth/Registration/Render.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
it({{ DESCRIPTION }}, function () {
Auth::logout();

livewire({{ REGISTRATION_ROUTE_ACTION }}::class)
->assertSuccessful();
}){{ RESOLVED_GROUP_METHOD }};

0 comments on commit b3cffd8

Please sign in to comment.