Testing action error

Hello and thanks for anyone that helps me. So I have a list page were i have a custom action
Action::make('import-historical-orders')
->label('Import Historical Orders')
->before(function (Action $action) {
if (Gate::denies('import-historical-orders')) {
$action->failure();
$action->halt();
}
})
->action(fn () => ImportUserHistoricalOrders::dispatch(auth()->user()))
->successNotification($this->importHistoricalOrdersSuccessNotification())
->failureNotification($this->importHistoricalOrdersFailureNotification());
Action::make('import-historical-orders')
->label('Import Historical Orders')
->before(function (Action $action) {
if (Gate::denies('import-historical-orders')) {
$action->failure();
$action->halt();
}
})
->action(fn () => ImportUserHistoricalOrders::dispatch(auth()->user()))
->successNotification($this->importHistoricalOrdersSuccessNotification())
->failureNotification($this->importHistoricalOrdersFailureNotification());
When testing this action i'm getting the error
Failed asserting that an event [open-modal] was fired with parameters: {"id":"oUPpTeYPcvmKfIXk0WEo-action"}
Failed asserting that an event [open-modal] was fired with parameters: {"id":"oUPpTeYPcvmKfIXk0WEo-action"}
The test is the following one
livewire(ListHistoricalOrders::class)
->callAction('import-historical-orders')
->assertActionHalted('import-historical-orders')
livewire(ListHistoricalOrders::class)
->callAction('import-historical-orders')
->assertActionHalted('import-historical-orders')
If i remove the Action $action parameter from the closure on the before method from the action the error doesn't appear anymore. So how can i test an action that have a closure with the action itself?
3 Replies
🎮Days🕹
🎮Days🕹3mo ago
Anyone had this error before?
Dennis Koch
Dennis Koch3mo ago
I think this is coming from callAction() which asserts opening the modal which won't happen because of your before(). Try using mountAction()
🎮Days🕹
🎮Days🕹3mo ago
@Dennis Koch thanks for the answer but i have tryied it and i have the same behaviour even doing this
Action::make('import-historical-orders')
->label('Import Historical Orders')
->action(function (Action $action) {
if (Gate::denies('import-historical-orders')) {
$action->failure();
$action->halt();
}

ImportUserHistoricalOrders::dispatch(auth()->user());
$action->success();
})
->successNotification($this->importHistoricalOrdersSuccessNotification())
->failureNotification($this->importHistoricalOrdersFailureNotification());
Action::make('import-historical-orders')
->label('Import Historical Orders')
->action(function (Action $action) {
if (Gate::denies('import-historical-orders')) {
$action->failure();
$action->halt();
}

ImportUserHistoricalOrders::dispatch(auth()->user());
$action->success();
})
->successNotification($this->importHistoricalOrdersSuccessNotification())
->failureNotification($this->importHistoricalOrdersFailureNotification());
removing the before and adding the check on the action i have the same behaviour...it's something to do when i pass the Action parametter to the closure. Solved the situation removing the
$action->halt();
$action->halt();
and adding
$action->cancel();
$action->cancel();
and removing the expectation
->assertActionHalted('import-historical-orders')
->assertActionHalted('import-historical-orders')
for an unknown reason for me the halt method is giving this error
Want results from more Discord servers?
Add your server
More Posts
Call the "edit" modal for a record in a resource from a different pageHi everyone. I have a "Reservation" Resource (and Model) that I use in a custom Livewire component tChange default table query to get only the soft deleted recordsHello all, For a project im working on I need my table results to only show the soft deleted recordsTailwind Issues even with Custom ThemeHi, I'm having some issues with tailwind where certain classes are not being picked up. I've setup Hello, how do I make Relation Manager form use full width of the page please?Hello, I am using Relation Manager to add records. I need to display the form modal in full width, pThe default value is not set in the select field with any nameThe default value is not set in the select field with any name when editing a record. I need to addthere seems to be no difference when using disabled vs visible in actionIt seems that using the visible method on an Action just disables the action, it doesn't actually hiFilament v2 Wizard Step mandatoryI have a step where the inputs are not required. But the step itself must be viewed before submittinNext step with pressing enter instead of submitting.I have a Wizzard with several steps. When I press enter inside the wizzard it submits the whole thinHide Bulk Upload Action on Table filter value changeI am trying to hide bulk actions when status filter is changed. How to get filter select field data Modal Dialogue with scrollbars?Hi all, I have a modal dialgue with a form with a repeater element. If the user adds a number of it