Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5322591
Add CanCreateRecordTest to list of test classes
CodeWithDennis Sep 10, 2025
dad12f2
Add test for creating a record in CanCreateRecordTest
CodeWithDennis Sep 10, 2025
3c45527
Refactor test for creating a record in Laravel Livewire
CodeWithDennis Sep 10, 2025
b97c299
Add support for RichEditor in create record test
CodeWithDennis Sep 10, 2025
586e610
Refactor indentation for record creation method
CodeWithDennis Sep 10, 2025
f86a301
Add CanValidateFormData test renderer for validation
CodeWithDennis Sep 10, 2025
bb89687
Delete form validation rules test file
CodeWithDennis Sep 10, 2025
90b654d
Rename CanValidateFormData to CanValidateFormDataTest
CodeWithDennis Sep 10, 2025
3bdfdfa
Rename form validation tests to match new naming convention
CodeWithDennis Sep 10, 2025
f1fb07f
Remove example file
CodeWithDennis Sep 18, 2025
293bff7
Add Form Record Tests description to README.md
CodeWithDennis Sep 18, 2025
f68602b
Add method to get form fields with max length filter
CodeWithDennis Sep 18, 2025
ad4a0a4
Add form data max length validation test case
CodeWithDennis Sep 18, 2025
b2d3e10
Refactor form field rule prefix retrieval method
CodeWithDennis Sep 18, 2025
875376b
Add validation for form data minimum character length
CodeWithDennis Sep 18, 2025
24144df
Update README to clarify RichEditor field validation
CodeWithDennis Sep 18, 2025
e516178
Add validation notes for RichEditor fields in test suite
CodeWithDennis Sep 18, 2025
79bf781
Remove unnecessary note about RichEditor field validation
CodeWithDennis Sep 18, 2025
eaeba4d
Update README file with Credits section
CodeWithDennis Sep 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ The `make:filament-test` command supports the following options:

This package generates comprehensive PEST tests for your Filament resources. Here's a complete list of currently working tests:

### Form Record Tests
- **CanCreateRecordTest** - Tests that a record can be created
- **CanValidateCreateFormTest** - Tests that the create form validates input correctly
- [x] Max
- [x] Min
- [x] Required

### Page Rendering Tests
- **CanRenderCreatePageTest** - Tests that the create page renders correctly
- **CanRenderEditPageTest** - Tests that the edit page renders correctly
Expand Down Expand Up @@ -73,6 +80,9 @@ This package generates comprehensive PEST tests for your Filament resources. Her

All tests are automatically generated based on your Filament resource configuration and will only run when the relevant features are present in your resource (e.g., search tests only run if you have searchable columns).

## Known Issues
- Validation of RichEditor fields is not supported, this is due to the complexity of handling rich text content in tests.

## Credits

- [CodeWithDennis](https://github.com/CodeWithDennis)
Expand Down
19 changes: 0 additions & 19 deletions resources/views/can-create-record.blade.php

This file was deleted.

19 changes: 0 additions & 19 deletions resources/views/form-validation-rules.blade.php

This file was deleted.

20 changes: 20 additions & 0 deletions resources/views/resources/pages/create/can-create-record.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@php use Filament\Forms\Components\RichEditor; @endphp
it('can create a record', function (): void {
$record = {{ $getResourceModel() }}::factory()->make();

livewire({{ $getPageClass('create') }}::class)
->fillForm([
@foreach($getResourceFormFields() as $key => $field)
'{{ $key }}' => $record->{{ $key }},
@endforeach
])
->call('create')
->assertHasNoFormErrors()
->assertNotified();

$this->assertDatabaseHas({{ $getResourceModel() }}::class, [
@foreach($getResourceFormFields() as $key => $field)
'{{ $key }}' => $record->{{ $key }},
@endforeach
]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
it('validates form data field :dataset', function (array $data, array $errors): void {
$record = {{ $getResourceModel() }}::factory()->make();

livewire({{ $getPageClass('create') }}::class)
->fillForm([
...$data
])
->call('create')
->assertHasFormErrors($errors)
->assertNotified();
})->with([
@foreach($getResourceFormFieldsByRulePrefix('required') as $key => $field)
'`{{ $key }}` is required' => [['{{ $key }}' => null], ['{{ $key }}' => 'required']],
@endforeach
@foreach($getResourceFormFieldsByRulePrefix('max') as $key => $field)
'`{{ $key }}` is max {{ $getRuleValue($field, 'max') }} characters' => [['{{ $key }}' => Illuminate\Support\Str::random({{ $getRuleValue($field, 'max') + 1 }})], ['{{ $key }}' => 'max']],
@endforeach
@foreach($getResourceFormFieldsByRulePrefix('min') as $key => $field)
'`{{ $key }}` is min {{ $getRuleValue($field, 'min') }} characters' => [['{{ $key }}' => Illuminate\Support\Str::random({{ $getRuleValue($field, 'min') - 1 }})], ['{{ $key }}' => 'min']],
@endforeach
]);
4 changes: 4 additions & 0 deletions src/Commands/FilamentTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use CodeWithDennis\FilamentTests\Concerns\Commands\InteractsWithUserInput;
use CodeWithDennis\FilamentTests\TestRenderers\BaseTest;
use CodeWithDennis\FilamentTests\TestRenderers\BeforeEach;
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Create\CanCreateRecordTest;
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Create\CanRenderCreatePageTest;
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Create\CanValidateCreateFormData;
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Edit\CanDeleteRecordTest;
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Edit\CanRenderEditPageTest;
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Edit\HasHeaderActionTest;
Expand Down Expand Up @@ -89,6 +91,8 @@ protected function getRenderers(): array
ShowsHeaderActionTest::class,
HidesHeaderActionTest::class,
HasFilterTest::class,
CanCreateRecordTest::class,
CanValidateCreateFormData::class,
];
}
}
26 changes: 26 additions & 0 deletions src/Concerns/Resources/InteractsWithSchemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CodeWithDennis\FilamentTests\Concerns\Resources;

use Closure;
use Filament\Forms\Components\Field;
use Filament\Infolists\Components\Entry;
use Filament\Resources\Pages\EditRecord;
Expand All @@ -22,6 +23,31 @@ public function getResourceFormFields(): array
return $this->getResourceForm()->getFlatFields(true);
}

public function getResourceFormFieldsByRulePrefix(string $prefix): array
{
return collect($this->getResourceFormFields())
->filter(
fn (Field $field): bool => array_any(
$field->getValidationRules(),
fn (Closure|string $rule): bool => is_string($rule) && str_starts_with($rule, $prefix)
)
)
->all();
}

public function getRuleValue(Field $field, string $ruleName): ?string
{
foreach ($field->getValidationRules() as $rule) {
if (is_string($rule) && str_starts_with($rule, $ruleName.':')) {
[, $value] = explode(':', $rule, 2);

return $value;
}
}

return null;
}

public function getResourceFormFieldKeys(): array
{
return collect($this->getResourceFormFields())
Expand Down
15 changes: 15 additions & 0 deletions src/TestRenderers/Resources/Pages/Create/CanCreateRecordTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Create;

use CodeWithDennis\FilamentTests\TestRenderers\BaseTest;

class CanCreateRecordTest extends BaseTest
{
public ?string $view = 'filament-tests::resources.pages.create.can-create-record';

public function getShouldRender(): bool
{
return $this->hasPage('create');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Create;

use CodeWithDennis\FilamentTests\TestRenderers\BaseTest;

class CanValidateCreateFormData extends BaseTest
{
public ?string $view = 'filament-tests::resources.pages.create.can-validate-create-form-data';

public function getShouldRender(): bool
{
return $this->hasPage('create');
}
}