Testing custom table filters

I have a table with the following custom filter:
Tables\Filters\Filter::make('year')
    ->form([
        Forms\Components\TextInput::make('yearFrom')
            ->label('From Year'),
        Forms\Components\TextInput::make('yearTo')
            ->label('To Year')
    ])
    ->query(function (Builder $query, array $data) {
        return $query
            ->when($data['yearFrom'], function (Builder $query, $yearFrom) {
                $query->where('year', '>=', $yearFrom);
            })
            ->when($data['yearTo'], function (Builder $query, $yearTo) {
                $query->where('year', '<=', $yearTo);
            });
    })

I'm trying to write a test case for this filter that looks like this:
it('can filter posts by a year from', function () {

    $cars = Car::factory()->count(3)
        ->state(new Sequence(
            ['year' => 2016],
            ['year' => 2017],
            ['year' => 2018],
        ))
        ->for(Brand::factory())
        ->create();

    $yearFrom = 2017;

    Livewire::test(CarList::class)
        ->assertCanSeeTableRecords($cars)
        ->filterTable('year', $yearFrom )
        ->assertCanSeeTableRecords(
            $cars->where('year', '>=', $yearFrom)
        )
        ->assertCanNotSeeTableRecords(
            $cars->where('year', '<', $yearFrom)
        );
});


My problem is that, when I run this test, the data coming into the
->query()
method is empty
[
    'yearFrom' => null
    'yearTo' => null
]


How can I set the values of a custom filter using ->filterTable()?
Was this page helpful?