How to test SelectColumn in a table?

I am trying to test my SelectColum that when I change a role, that user's role is updated in the database. From the testing docs https://filamentphp.com/docs/3.x/tables/testing#select-columns , it doesn't seem like this type of functionality is testable through a method much like a filter can be applied with
->filterTable(
->filterTable(
... I'm wondering if there is a method such as
selectColumn
selectColumn
that I just can't find in the docs/through the ide. Here is a barebones test:
/** @test */
public function it_will_correctly_reassign_a_users_role(): void
{
// Given I have a user with an 'Admin' role
$superadmin_role_id = Role::where('name', 'Superadmin')->first()->id;
$admin_role_id = Role::where('name', 'Admin')->first()->id;
$user = User::factory()->create(['role_id' => $admin_role_id]);

// When I change the role to 'Superadmin'
Livewire::test(AdminClinicPageComponent::class, ['clinic' => $this->clinicA])
->selectColumn('role_id', $superadmin_role_id, record: $user);

// Then my user's role should be 'Superadmin'
$this->assertEquals($superadmin_role_id, $user->fresh()->role_id);
}
/** @test */
public function it_will_correctly_reassign_a_users_role(): void
{
// Given I have a user with an 'Admin' role
$superadmin_role_id = Role::where('name', 'Superadmin')->first()->id;
$admin_role_id = Role::where('name', 'Admin')->first()->id;
$user = User::factory()->create(['role_id' => $admin_role_id]);

// When I change the role to 'Superadmin'
Livewire::test(AdminClinicPageComponent::class, ['clinic' => $this->clinicA])
->selectColumn('role_id', $superadmin_role_id, record: $user);

// Then my user's role should be 'Superadmin'
$this->assertEquals($superadmin_role_id, $user->fresh()->role_id);
}
Here is my code snippet
public function table(Table $table): Table
{
return $table
->query(
User::query()
)
->columns([
// other text columns in my tables
SelectColumn::make('role_id')
->options($this->allowed_roles)
->afterStateUpdated(function ($record, $state): void
{
$record->assignRole($state);
$record->refresh();
}),
]);
}
public function table(Table $table): Table
{
return $table
->query(
User::query()
)
->columns([
// other text columns in my tables
SelectColumn::make('role_id')
->options($this->allowed_roles)
->afterStateUpdated(function ($record, $state): void
{
$record->assignRole($state);
$record->refresh();
}),
]);
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server