Testting anonymous actions

I have an infolist (ViewProject.php) for my ProjectResource. This just displays a number of sections and groups. Of of those sections contains a number of anonymous actions, like:
Action::make('invite-teacher')
->label('Docent uitnodigen')
->icon('heroicon-m-academic-cap')
->color('darkGreen')
->disabled(function ($record) {
return !isset($record->teacher);
})
->requiresConfirmation()
->action(function ($record) {
$from = Filament::getTenant();
SendTeacherInviteEmail::dispatch($record, $from);
Notification::make('teacher-invited')
->title('Uitnodiging verzonden!')
->success()
->send();
}),
Action::make('invite-teacher')
->label('Docent uitnodigen')
->icon('heroicon-m-academic-cap')
->color('darkGreen')
->disabled(function ($record) {
return !isset($record->teacher);
})
->requiresConfirmation()
->action(function ($record) {
$from = Filament::getTenant();
SendTeacherInviteEmail::dispatch($record, $from);
Notification::make('teacher-invited')
->title('Uitnodiging verzonden!')
->success()
->send();
}),
The action itself works just fine, i just have no idea how to reach this action in a (pest) test. Can someone point me in the right direction or tell me how i can refactor if i need to rewrite my actions.
1 Reply
Tally
Tally2mo ago
Maybe you can create another action class for your logic so you can test it seperately. So for example a SendTeacherInvitationAction class (I use the Laravel Actions a lot, but a simple class will do as well https://www.laravelactions.com/)