How to write tests for create, edit and delete actions of Relation managers

This is what I am trying it('can add contacts', function () { $admin = Admin::factory()->create(); $contact = Contact::factory()->make(); livewire(AdminResource\RelationManagers\ContactsRelationManager::class, [ 'ownerRecord' => $admin, 'pageClass' => EditAdmin::class, ]) ->set('form', [ 'first_name' => $contact->first_name, 'last_name' => $contact->last_name, 'email' => '[email protected]', 'mobile' => $contact->mobile, 'phone' => $contact->phone, ]) ->call('create') ->assertSee('Contact created successfully'); }); and getting following error Error: App\Filament\Resources\AdminResource\RelationManagers\ContactsRelationManager::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/xxxx/myfila/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 54
Solution:
I have an example using attach action. Maybe it can help you https://github.com/filamentphp/filament/discussions/9208#discussioncomment-7337715...
GitHub
I'm using AttachAction in a relationship, but I'm not sure how to w...
I couldn't find any information in the documentation at https://filamentphp.com/docs/3.x/panels/testing#relation-managers Is it possible to write tests to confirm that a record has been attache...
Jump to solution
3 Replies
Solution
LeandroFerreira
LeandroFerreira14mo ago
I have an example using attach action. Maybe it can help you https://github.com/filamentphp/filament/discussions/9208#discussioncomment-7337715
GitHub
I'm using AttachAction in a relationship, but I'm not sure how to w...
I couldn't find any information in the documentation at https://filamentphp.com/docs/3.x/panels/testing#relation-managers Is it possible to write tests to confirm that a record has been attache...
Akshay Bokade
Akshay BokadeOP14mo ago
@Leandro Ferreira Perfect. Thank you so much.
tanner
tanner13mo ago
I am trying to very similar where I have a Form, which has a RelationManger of many Fields. I am trying to test the Field record can be updated. I don't have any Attach action, as I am just using the default Edit action. My tests look similar as:
it('can show field relation manager form', function () {
$form = Form::factory()->has(Field::factory(1))->create();

livewire(FieldsRelationManager::class, [
'ownerRecord' => $form,
'pageClass' => EditForm::class,
])
->assertTableActionExists('edit')
->mountTableAction('edit', $form->fields->first()->id)
->assertFormSet([
'name' => $form->fields->first()->name,
'description' => $form->fields->first()->description,
'type' => $form->fields->first()->type,
]);
});
it('can show field relation manager form', function () {
$form = Form::factory()->has(Field::factory(1))->create();

livewire(FieldsRelationManager::class, [
'ownerRecord' => $form,
'pageClass' => EditForm::class,
])
->assertTableActionExists('edit')
->mountTableAction('edit', $form->fields->first()->id)
->assertFormSet([
'name' => $form->fields->first()->name,
'description' => $form->fields->first()->description,
'type' => $form->fields->first()->type,
]);
});
I do get that similar error:
Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given
Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given
I dont see how to test an InfoList as I dont see that section in the docs. So I am a bit confused here if this is supposed to be a Form or an InfoList.
Want results from more Discord servers?
Add your server