F
Filamentβ€’2w ago
CGM

Is it possible to test forms in actions?

https://filamentphp.com/docs/3.x/actions/testing Looking at the documentation I'm not sure I can do this, but is there an easy way to test forms inside of actions that I add to my livewire components? For example, how could I mount an action in my livewire component and test a field is both visible and has a value? If it would help I could post pseudo code as an example, but really just any pointers would be wildly useful. πŸ™‚
4 Replies
CGM
CGMOPβ€’2w ago
Ooo ChatGPT might have saved me on this one. It looks like I need to dig into the mountedActionData to test.
it('shows the location_id field when the quickSend action is mounted', function () {
Livewire::test(ReviewRequestSetupAction::class)
->mountAction('quickSend')
->assertSet('mountedActionData.location_id.isHidden', false)
->assertSet('mountedActionData.location_id', null);
});
it('shows the location_id field when the quickSend action is mounted', function () {
Livewire::test(ReviewRequestSetupAction::class)
->mountAction('quickSend')
->assertSet('mountedActionData.location_id.isHidden', false)
->assertSet('mountedActionData.location_id', null);
});
Does this look sane? Should I beable to just reply on assertSet and use those class variables to test instead of all the fancy helper functions available for forms, etc.?
CGM
CGMOPβ€’2w ago
I'm having trouble finding how to set and test field values, visibility etc. for forms inside of actions. I can mountAction() successfully for example, but when I go to assert a field exists I get errors:
it('shows the location_id field when the quickSend action is mounted', function () {
Livewire::test(ReviewRequestSetupAction::class)
->mountAction('quickSend')
->assertFormFieldExists('location_id');
});
it('shows the location_id field when the quickSend action is mounted', function () {
Livewire::test(ReviewRequestSetupAction::class)
->mountAction('quickSend')
->assertFormFieldExists('location_id');
});
Failed asserting that null is an instance of class Filament\Forms\Components\Field.
Failed asserting that null is an instance of class Filament\Forms\Components\Field.
Is there a way to mount a form in an action and then do standard 'filament form' testing to that form? i.e. things like assertFormFieldExists, etc.
awcodes
awcodesβ€’2w ago
Try ->assertActionFormFieldExists() Not πŸ’― to be honest
Want results from more Discord servers?
Add your server