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' => 'test@example.com',
'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
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' => 'test@example.com',
'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
https://github.com/filamentphp/filament/discussions/9208#discussioncomment-7337715
GitHub
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...