How to test table with filter form
Hi Experts. I have a table component with a pretty complex filterform. Everything is running well. Now I want to write some tests for this tablecomponent to make sure all my filters are working correctly. The relevant parts of the tabledefinition in the resource looks like this:
return $table
->columns( ... )
->filters([
Filter::make('Filter')->columnSpan(12)->form([
Grid::make(['default' => 12])->schema([
Section::make('fixed_section')
->columnSpan(12)
->schema([
Grid::make(5)->schema([
TextInput::make('hawb'),
...
])
])
->query(function (Builder $query, array $data): Builder {
...
})
])
->filtersLayout(Layout::AboveContent)
->actions([])
->bulkActions([]);
In my test I am doing something like this:
Livewire::test(ListShipments::class)
->assertCanSeeTableRecords( $allShipments )
->filterTable('hawb', 'XYZ')
->assertCanSeeTableRecords( $specificShipments );
When I run the test I get the following Error message:
Failed asserting that a table filter with name [hawb] exists on the [App\Filament\Resources\ShipmentResource....
So I assume to set a value in the filter form I need to use something different then ->filterTable('hawb', 'XYZ')
?! How do I interact with the filterform of my tablecomponent in a test?
Any tipps very appreciated!4 Replies
the name of your filter goes in Filter::make('Filter')
Filter::make('hawb')
thats how we identify themThanks @Dan Harrin for your answer! But my filter is a pretty complex form, with about 20 TextInput and Select formfields. Not just a "simple" filtervalue. My example just contains one TextInput (
TextInput::make('hawb')
) for the sake of better overview. But there are much more fields included. Arranged in a grid with collabsable sections and so on. More like it is described here (https://filamentphp.com/docs/2.x/tables/filters#custom-filter-forms). So I only have this single Filter::make call that contains the whole filterform. Or is that already the wrong approach?->filterTable('combinedFilterName', ['hawb' => 'XYZ'])
you can use as many inputs in it as you wantAh! OK, thank you very mutch! That was exactly what I was missing! Now it works!