Skip to content

Commit

Permalink
Merge pull request #172 from dissto/add-password-reset-test
Browse files Browse the repository at this point in the history
Add render reset password page test
  • Loading branch information
CodeWithDennis authored Apr 21, 2024
2 parents 2d739c1 + 2c711bf commit 98c9adc
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
- PasswordReset
- [x] it can render the password reset page
- Login
- [x] it can render the login page
- Resource
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\PasswordReset\Render::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Pages\Auth\Login\Render::make($resource)->get(),

\CodeWithDennis\FilamentTests\Stubs\Resource\Page\Index\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 getRequestPasswordResetRouteAction(): ?string
{
return Filament::getDefaultPanel()?->getRequestPasswordResetRouteAction();
}

public function hasPasswordReset(): bool
{
return Filament::hasPasswordReset();
}

public function getLoginRouteAction(): ?string
{
return Filament::getDefaultPanel()?->getLoginRouteAction();
Expand Down
26 changes: 26 additions & 0 deletions src/Stubs/Pages/Auth/PasswordReset/Render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

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

use CodeWithDennis\FilamentTests\Stubs\Base;

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

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

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

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

0 comments on commit 98c9adc

Please sign in to comment.