Testing Table Action with modal
My action code is with my test being , while it runs the action method, it never seems to get to the removeAction method, it never gets to the ->action() within it. Only my tests are failing. Its working great in the actual browser. Im assuming i need to call something else?
28 Replies
Anyone have any ideas?
The really odd thing here is that it never errors until it does the expect(), so the assert that it exists passes, the call passes, the no error passes, it just never seems to run the action(). Ive even taken off all the modal/confirmation off the action so that it runs direct and i still get the same result of the action() never executing
Hmm, I'm not sure if I can really help but I'm curious to dig in a bit... so it fails to assert that
property_management_company_id
is null
?@pboivin correct. Ive verified with just a dump of
$propertyManager->fresh()->property_management_company_id
that it is indeed still there as well.
Just really odd that in real world everything works perfectly. ive tried a bunch of refactors and cant get the test to work. Its not like this is the first table row ive tested before. Though the others were either a delete or an editAnd just for context, how is
removeAction()
setup in the rest of the table? What calls that method?@pboivin ->actions([$this->removeAction()])
Ok I see, so when you run the test, what output are you seeing in Ray? (I'm assuming nothing...?)
only
running remove action
twice. but that obviously runs simply when the table is rendered. Ive even added a ray() to modalHeading() and that doesnt runOh right, yeah
So the Action class is instantiated but none of the callbacks are executed at runtime through the test
yep. i must be missing something simple
Can you try
->callTableAction('asdf', record: $propertyManager)
, just to make sure that fails?@pboivin it does fail
I refactored a bit since yesterday
If I do switchout the call action that should fail, i do get:
Ok nice, I know it's a bit dumb but you never know 😄
oh absolutely and i appreciate the help and ideas
Have you been digging a bit into
vendor/filament/tables/src/Testing/TestsActions.php
? I'm wondering if (for some unknown reason) you could be getting an early return of $this
before your action gets called.I have, but not super in depth
you nailed it, its getting stopped by
as i temporarily edited it to have and the before runs, but not the after
Hmm, getting closer! So now is the issue in
mountTableAction()
or getMountedTableAction()
? 🤔yep, looks like it
Another sanity check... is your action extending oops
Filament\Tables\Actions\Action
?
yes, 100%
Is
PropertyManagersTable
a custom Livewire component? At this point this is the only difference I'm seeing. I just tried with a regular List page and my test is correctly calling the action.@pboivin yes. my entire app is standalone
So you did a custom action that was not related to edit or delete or any standard action?
Yeah, just tested on a List page and a custom Livewire component. Both worked.
Are you on the latest v3.0.4?
I am not as i cant upgrade to livewire 3 yet. im on the latest alpha. I didnt see anything different in regards to these affected classes though. Maybe i should spin up the the latest demo and give it a try
Yeah, in the off chance it could have been an issue in the alpha... but I'm a bit out of my depth, I've only been exploring v3 since the beta release.
we have been using it in production since March 😛
Just ran into the same problem. Reading through this post helped me fix it: mount the action before you call it:
this worked for me, so thanks!