This repository was archived by the owner on Feb 14, 2026. It is now read-only.
generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 13
Create record and create form validation tests #333
Merged
Merged
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 dad12f2
Add test for creating a record in CanCreateRecordTest
CodeWithDennis 3c45527
Refactor test for creating a record in Laravel Livewire
CodeWithDennis b97c299
Add support for RichEditor in create record test
CodeWithDennis 586e610
Refactor indentation for record creation method
CodeWithDennis f86a301
Add CanValidateFormData test renderer for validation
CodeWithDennis bb89687
Delete form validation rules test file
CodeWithDennis 90b654d
Rename CanValidateFormData to CanValidateFormDataTest
CodeWithDennis 3bdfdfa
Rename form validation tests to match new naming convention
CodeWithDennis f1fb07f
Remove example file
CodeWithDennis 293bff7
Add Form Record Tests description to README.md
CodeWithDennis f68602b
Add method to get form fields with max length filter
CodeWithDennis ad4a0a4
Add form data max length validation test case
CodeWithDennis b2d3e10
Refactor form field rule prefix retrieval method
CodeWithDennis 875376b
Add validation for form data minimum character length
CodeWithDennis 24144df
Update README to clarify RichEditor field validation
CodeWithDennis e516178
Add validation notes for RichEditor fields in test suite
CodeWithDennis 79bf781
Remove unnecessary note about RichEditor field validation
CodeWithDennis eaeba4d
Update README file with Credits section
CodeWithDennis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
resources/views/resources/pages/create/can-create-record.blade.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ]); | ||
| }); |
21 changes: 21 additions & 0 deletions
21
resources/views/resources/pages/create/can-validate-create-form-data.blade.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/TestRenderers/Resources/Pages/Create/CanCreateRecordTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/TestRenderers/Resources/Pages/Create/CanValidateCreateFormData.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
CodeWithDennis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.