F
Filament2mo ago
Maxi

How to test modal actions?

I registered a modal action using the registerModalActions() function and when I mount the "parent" action and use the assertSee() function to check for the modal action's label I can find it just fine, but if I try to actuall call the modal action it says that no action with that name exists on my page, do I maybe have to load the action differently? This is how I'm currently trying to access it:
it('can use modal action', function () {
// boilerplate
livewire(PageResource::class)
->mountAction(ImportAction::class)
->assertActionExists('mymodalaction') // -> returns: Failed asserting that it exists
->assertSee('The label of my modal action'); // returns: true
})->only();
it('can use modal action', function () {
// boilerplate
livewire(PageResource::class)
->mountAction(ImportAction::class)
->assertActionExists('mymodalaction') // -> returns: Failed asserting that it exists
->assertSee('The label of my modal action'); // returns: true
})->only();
11 Replies
Maxi
MaxiOP2mo ago
Bump
Maxi
MaxiOP2mo ago
I already checked out the docs but I can't find anything on modal actions specifically. And if they're treated like normal actions then I think I found a bug.
toeknee
toeknee2mo ago
Actions are modal actions, except if you are using a form you need to pass in the data.
Maxi
MaxiOP2mo ago
Okay so if I register an action in a modal, I should be able to access it if I mount the action that opens my modal, right?
toeknee
toeknee2mo ago
Did you see part one? https://filamentphp.com/docs/3.x/actions/testing#getting-started It says about passing data into an action? the data would normally come from the form so that's how you would do it.
Maxi
MaxiOP2mo ago
Sorry, maybe I explained my problem wrong but I don't want to pass any data into the modal action or in general do anything, I just want to test if the action exists (->assertActionExists()). I had to remove some stuff from the action since it's work related, but here's how the modal action is created and how I display it inside of the modal:
<?php

class ImportAction extends Action
{

protected function setUp(): void
{
parent::setUp();


$this->modalDescription(): Htmlable => $action->getModalAction('mymodalaction'));


// ...

$this->registerModalActions([
Action::make('mymodalaction')
->label('My modalaction')
->disabled(),
]);

// ...
}
}
<?php

class ImportAction extends Action
{

protected function setUp(): void
{
parent::setUp();


$this->modalDescription(): Htmlable => $action->getModalAction('mymodalaction'));


// ...

$this->registerModalActions([
Action::make('mymodalaction')
->label('My modalaction')
->disabled(),
]);

// ...
}
}
Maxi
MaxiOP2mo ago
And it does display if I click on the ImportAction.
No description
Maxi
MaxiOP2mo ago
But when I run my test as described I get a Failed asserting that an action with name [mymodalaction] exists on ... error. If I change the test to: ->assertSee('My modalaction'); then it passes. Bump
toeknee
toeknee2mo ago
Do you have a user check on the visible for the action?
Maxi
MaxiOP2mo ago
No :(
Want results from more Discord servers?
Add your server