How can I test a form from a modal? (simple resource)

I have some resources made with --simple flag, so they don't have Create, Edit or View pages, only the Manage class. I would like to know 2 things, how to assert the modal rendering and how to test the form (because the fillForm seems to not work in this case). 1 - is this a good assertion for the "render modal test"?
livewire($manageModelClass)
->callAction('create')
->assertSeeHtml('fi-modal-window')
->assertSee('Create');
livewire($manageModelClass)
->callAction('create')
->assertSeeHtml('fi-modal-window')
->assertSee('Create');
2 - how to use the fillForm for modals?
livewire($manageModelClass)
->callAction('create') // it does render the modal
->assertFormExists() // error
->fillForm($formData) // error
livewire($manageModelClass)
->callAction('create') // it does render the modal
->assertFormExists() // error
->fillForm($formData) // error
Solution:
```php $data = [ 'title' => 'Title', 'description' => 'Description', ......
Jump to solution
5 Replies
Bruno Silva
Bruno SilvaOP10mo ago
anyone?
Solution
LeandroFerreira
LeandroFerreira10mo ago
$data = [
'title' => 'Title',
'description' => 'Description',
...
];

livewire(ManageXXX::class)
->callAction('create', data: $data)
->assertHasNoActionErrors();
$data = [
'title' => 'Title',
'description' => 'Description',
...
];

livewire(ManageXXX::class)
->callAction('create', data: $data)
->assertHasNoActionErrors();
https://filamentphp.com/docs/3.x/actions/testing
Bruno Silva
Bruno SilvaOP10mo ago
that don't work as well, I think that is because the assertion is for Create or Edit resources classes, but I'm not sure, I got this error:
Filament\Resources\Pages\ListRecords::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/bruno/Developer/www/grandparking/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 56
Filament\Resources\Pages\ListRecords::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/bruno/Developer/www/grandparking/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 56
Using this test:
it('can create record from modal', function () {
$data = [
'name' => 'Test Vehicle Type',
'daily_fee' => 100,
];

livewire(ManageVehicleTypes::class)
->callAction('create', $data)
->assertHasNoFormErrors();
});
it('can create record from modal', function () {
$data = [
'name' => 'Test Vehicle Type',
'daily_fee' => 100,
];

livewire(ManageVehicleTypes::class)
->callAction('create', $data)
->assertHasNoFormErrors();
});
I have similar tests for resources that have the crud pages, and they work just fine
LeandroFerreira
LeandroFerreira10mo ago
yes, because you are using assertHasNoFormErrors instead of assertHasNoActionErrors
Bruno Silva
Bruno SilvaOP10mo ago
Oh, sorry, I misread. That works. Thank you very much
Want results from more Discord servers?
Add your server