hint action tests
hey i got a hint action setup on a simple Select that opens a Form inside a modal.
Select::make('chooseProfile') ->hintAction( Action::make('createNewProfile')->label('newProfileAction')->form([ Grid::make()->schema([ TextInput::make('newProfile') ->required() ]) ]) )how do i call that nested action when testing the livewire component in order to write tests for the form displayed in the modal? when i try using call action i get:
Failed asserting that an action with name [createNewProfile] exists on the [App\Livewire\ProfileForm] page.
15 Replies
@AncientFriend Were you ever able to figure this out?
@awcodes thank you I tried following those docs but I kept getting a weird error about infolists (https://discord.com/channels/883083792112300104/1260726161785356438)
I'm guessing the issue is becuse I'm trying to test a hint action within a relation manager
Shouldn’t matter. Can sure more code than just the action?
You might need to mount the form action too.
Before calling it.
Seems weird to be testing these together though. In my mind it would be a test to call the table action. But a separate test for actions in the create / edit for the related form.
If that makes sense.
Ie, if the create / edit form for the related record works then you can expect it to work when loaded by the table action too.
I'm not sure I understand what you mean. How could I test this hint action on it's own? The hint action is only available through the EditAction form. Don't I have to call the table action before running this test?
I just tried using
but got the same error about an Infolist
I appreciate your responses and any further insight you can provide. Thank you!
I’m sure there’s a proper way to do it, I’ll get back to you. I’m away from the computer right now though.
Do you have a resource for category or is it a simple resource?
I actually don't have a resource for it at all. The code examples I've showed are simplified. What I'm actually trying to modify are
EventCategory
s. The organization has Category
s that are used to create all the EventCategory
models for an event. This way the EventCategory
can be renamed or modified for a specific event without changing it for all events. The EventCategory
models are created initially in protected function afterCreate()
of the CreateEvent
class after the event has been saved.
Do you think I need to create a resource for EventCategory
in order for this testing to work?Did you add a form to a custom page? Would you like to test the
createNewProfile
action? Is it?This is within the
EditAction
of a table record within a relation manager
It is not a custom page
What is createNewProfile
?could you share some code you are using?
sorry, this was the main question from
AncientFriend
line 48 is just
public function form(Form $form): Form
from the relation manager so I feel like I don't have a whole lot to go on
When I use the form as a user it works as expected. So I can't figure out why I'm getting an error about an Infolist when I try to run a testtry this
Yup this worked!
Thank you!
How do I fill the form with data?
Sorry to keep asking so many questions - when I search for
mountFormComponentAction
in the Filament docs I get no results. Am I missing this somewhere?try
->set('mountedFormComponentActionsData.0.your_field', 'value')
you sometimes need to dive into the source code to achieve what you want..
@AncientFriend share the whole codeHere is the full solution: