Feb 24, 2025
0
Level 24
The behavior ->removeTableFilter('...') of testing Select filter is not same as Ternary filter
ALL my Select filter Test with use ->removeTableFilter('...') and ->removeTableFilters() is Passed.
but when i write a Test for the Ternary filter, it always Fail.
i removed all the code, make the question more simple, so only focus on this
UserResource.php
->filters([
Tables\Filters\TernaryFilter::make('avatar')
->queries(
true: fn (Builder $query) => $query->whereNotNull('avatar_name'),
false: fn (Builder $query) => $query->whereNull('avatar_name'),
blank: fn (Builder $query) => $query,
),
])
Why the Test fail? the problem is same as use ->removeTableFilters()
test('table can remove avatar filter', function () {
$users = User::factory()->count(3)->create();
$component = Livewire::test(ListUsers::class);
$component
->filterTable('avatar', true) // Apply filter
// ... other code
->removeTableFilter('avatar') // Remove filter
->assertCanSeeTableRecords($users, inOrder: true);
})->only();
https://filamentphp.com/docs/3.x/tables/testing#removing-filters
Please or to participate in this conversation.