F
Filamentβ€’2y ago
techenby

How to test a Table header action on a Relationship Manager?

I have the following test:
/** @test */
public function can_assign_users_to_job_on_view_page()
{
$admin = User::factory()->create();
$job = Job::factory()->create();
$employee = User::factory()->create();

Livewire::actingAs($admin)
->test(UsersRelationManager::class, ['ownerRecord' => $job])
->assertSuccessful()
->callPageAction(AttachAction::class, [
'recordId' => $employee->id,
'task' => Job::EXCAVATE,
]);

$this->assertDatabaseHas('job_user', [
'job_id' => $job->id,
'user_id' => $employee->id,
'task' => Job::EXCAVATE,
]);
}
/** @test */
public function can_assign_users_to_job_on_view_page()
{
$admin = User::factory()->create();
$job = Job::factory()->create();
$employee = User::factory()->create();

Livewire::actingAs($admin)
->test(UsersRelationManager::class, ['ownerRecord' => $job])
->assertSuccessful()
->callPageAction(AttachAction::class, [
'recordId' => $employee->id,
'task' => Job::EXCAVATE,
]);

$this->assertDatabaseHas('job_user', [
'job_id' => $job->id,
'user_id' => $employee->id,
'task' => Job::EXCAVATE,
]);
}
I don't think callPageAction is correct since if I use it, I get the following error: UsersRelationManager::getCachedAction does not exist. If I use callTableAction I get the following error: RelationManager::getTableRecord(): Argument #1 ($key) must be of type ?string, array given, Which makes sense, but what should I use?
2 Replies
Dan Harrin
Dan Harrinβ€’2y ago
should be callTableAction the second argument should be null (there is no table row), or use data: on the array of data
techenby
techenbyOPβ€’2y ago
Gotcha! Thank you πŸ™‚
Want results from more Discord servers?
Add your server