F
Filamentβ€’2w ago
Laurens

Testing relation manager actions

I am trying to test the actions of relation managers to get 100% code coverage across an internal project we have. However, the furthest I can get are exception that the create actions is not being rendered/present on the livewire component. I am seeing the create action while logged into the panel. This is a trimmed down WIP of an example test I have with some specific business logic from the app trimmed out.
it('can create project assets', function () {
$this->actingAs($user = $this->createTeamUser()->fresh());

// Create dummy owner record
$ownerRecord = Project::factory()->create();

// Prepare dummy data
$data = Asset::factory()->make();

livewire(ProjectResource\RelationManagers\AssetsRelationManager::class, [
'pageClass' => ProjectResource\Pages\EditProject::class,
'ownerRecord' => $ownerRecord,
])
->callAction(CreateAction::class, $data->only(['name', 'url']))
->assertSuccessful();

// Verify the record exists
$this->assertDatabaseHas(Asset::class, $data->only(['name', 'url']));
})->skip('cannot assert on relation manager');
it('can create project assets', function () {
$this->actingAs($user = $this->createTeamUser()->fresh());

// Create dummy owner record
$ownerRecord = Project::factory()->create();

// Prepare dummy data
$data = Asset::factory()->make();

livewire(ProjectResource\RelationManagers\AssetsRelationManager::class, [
'pageClass' => ProjectResource\Pages\EditProject::class,
'ownerRecord' => $ownerRecord,
])
->callAction(CreateAction::class, $data->only(['name', 'url']))
->assertSuccessful();

// Verify the record exists
$this->assertDatabaseHas(Asset::class, $data->only(['name', 'url']));
})->skip('cannot assert on relation manager');
This is happening for me in an Laravel 11 project with Filament v3.3.x. Is there any way to test actions for relation managers? Thanks in advance!
4 Replies
LeandroFerreira
LeandroFerreiraβ€’2w ago
remove callAction and try
->mountTableAction(CreateAction::class)
->setTableActionData($data->only(['name', 'url']))
->callMountedTableAction()
->assertHasNoTableActionErrors()
->mountTableAction(CreateAction::class)
->setTableActionData($data->only(['name', 'url']))
->callMountedTableAction()
->assertHasNoTableActionErrors()
Laurens
LaurensOPβ€’2w ago
Thanks I've set a Slack reminder to try this tomorrow morning πŸ™‚
LeandroFerreira
LeandroFerreiraβ€’2w ago
I did another example using attachAction You can use the same approach
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...
Laurens
LaurensOPβ€’2w ago
It works, thanks a lot πŸ™‚

Did you find this page helpful?