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.

Tables\Actions\ViewAction::make()
->label('')
->slideOver()
->modalWidth(MaxWidth::Medium),

Tables\Actions\ViewAction::make()
->label('')
->slideOver()
->modalWidth(MaxWidth::Medium),
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 :
Livewire::test(ViewAction::class, [
'record' => $user->getRouteKey()
])
->assertForbidden();
Livewire::test(ViewAction::class, [
'record' => $user->getRouteKey()
])
->assertForbidden();
someone a idea ?
4 Replies
parte
parte9mo ago
you can use laravel's policies for that
Frittenfred
FrittenfredOP9mo ago
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
LeandroFerreira
LeandroFerreira9mo ago
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-state
Frittenfred
FrittenfredOP9mo ago
then 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 :
Livewire::test(UserResource\Pages\ListUsers::class)
->assertTableActionDoesNotExist(\Filament\Tables\Actions\ViewAction::class);
Livewire::test(UserResource\Pages\ListUsers::class)
->assertTableActionDoesNotExist(\Filament\Tables\Actions\ViewAction::class);
FAILED Tests\Feature\Filament\UserResourceTest > a guest can not access user details Error Call to a member function getTable() on null
Want results from more Discord servers?
Add your server