how to test a view modal action?
Hello Folks,
i'm testing my Laravel Filament application and i want to test if guests can access a view which opens via a modal.
i want to test if a guest or people without permission can access the view modal as Action. i have allready a test to check if the table gets rendered and showed. that is forbidden and redirects, that works. but i would like to test if someone could open only a action and i don't know right how to test a modal action that only works for a administrator.
my code at this time :
someone a idea ?
4 Replies
you can use laravel's policies for that
yeah i have laravel policys and that works great, but i want to use tests to be sure that everything works like it should. and that, even if can not open a list as table, i also can not open a view modal as action without accessing the table/listing
If you are using policies, you shouldn't be able to view the action button if you don't have this permission, right?
maybe
assertActionVisible
assertActionHidden
https://filamentphp.com/docs/3.x/actions/testing#action-statethen i'm getting when i test the action directly this error :
FAILED Tests\Feature\Filament\UserResourceTest > a guest can not access user details ComponentNotFoundException
Unable to find component: [Filament\Tables\Actions\ViewAction]
i don't know if it is possible to render the action without the table ?
so when i test if i can open a ListUsers::class and then the ViewAction as Admin, it works, but when i do it as user i get this error :
FAILED Tests\Feature\Filament\UserResourceTest > a guest can not access user details Error
Call to a member function getTable() on null