Testing modal form fields.
Given an action with a modal, with a form schema, I'd like to test that the form has specific fields. How is that done?
Example action
Example test
Fails with
Failed asserting that a field with the name [export_format] exists on the form with the name [form] on the [App\Filament\App\Resources\DomainResource\Widgets\DomainActions] component.
Failed asserting that null is an instance of class Filament\Forms\Components\Field.
5 Replies
/** @test */
public function export_action_modal_has_select_field_for_format()
{
Livewire::test(DomainActions::class, ['record' => $this->domain])
->mountAction('export')
->assertActionHasFormField('export', 'export_format');
}
/** @test */
public function export_action_modal_has_select_field_for_format()
{
Livewire::test(DomainActions::class, ['record' => $this->domain])
->mountAction('export')
->assertSet('mountedAction', 'export')
->assertSet('mountedActionFormComponent', 'export')
->assertSet('mountedActionFormData.export_format', null);
}
or
/** @test */
public function export_action_modal_has_select_field_for_format()
{
$component = Livewire::test(DomainActions::class, ['record' => $this->domain])
->mountAction('export');
$formData = $component->get('mountedActionFormData');
$this->assertArrayHasKey('export_format', $formData);
}
So I take it there is no simple and straight forward way of testing forms in modals?
I think this should work for you: