F
Filament3mo ago
CGM

How do I create a test for filtersForm() on dashboard?

I'm having a difficult time creating a test to ensure one of my filters is providing the correct select list in the filtersForm() method on my dashboard. How can I target this method?
class Dashboard extends \Filament\Pages\Dashboard
{
use HasFiltersForm;

public function filtersForm(Form $form): Form
{
return $form
->schema([
// These are the form fields I want to test...
// I just want to make sure a select list has the proper values.
]);
}
}
class Dashboard extends \Filament\Pages\Dashboard
{
use HasFiltersForm;

public function filtersForm(Form $form): Form
{
return $form
->schema([
// These are the form fields I want to test...
// I just want to make sure a select list has the proper values.
]);
}
}
1 Reply
CGM
CGMOP3mo ago
After some source diving, it looks like this is what you need to do. Hopefully this helps someone...
livewire(Dashboard::class)
->assertFormExists('filtersForm')
->assertFormFieldExists('location', 'filtersForm', function ($field) use ($expectedOptions) {
return expect($field->getOptions())->toBe($expectedOptions) &&
expect($field->getOptions())->toHaveCount(5);
})
->assertSuccessful();
livewire(Dashboard::class)
->assertFormExists('filtersForm')
->assertFormFieldExists('location', 'filtersForm', function ($field) use ($expectedOptions) {
return expect($field->getOptions())->toBe($expectedOptions) &&
expect($field->getOptions())->toHaveCount(5);
})
->assertSuccessful();
Want results from more Discord servers?
Add your server