Testing Header Action

I have the following in my EditTenantProfile
protected function getHeaderActions(): array
{
    return [
        Actions\Action::make('Delete Website')
            ->name('delete')
            ->icon('heroicon-m-x-mark')
            ->color('danger')
            ->requiresConfirmation()
            ->action(function () {
                $tenant = tenant(); // these two lines are wrong but I'm writing the test
                $tenant->delete();  // before I fix it.

                Notifications\Notification::make()
                    ->danger()
                    ->title('Website deleted')
                    ->body('The website has been deleted.')
                    ->send();
            }),
    ];
}


I'm trying to write a test and have got this far, however it doesn't work.
public function test_can_delete_website(): void
{
    $tenant = $this->getTenant();
    $this->visitPage($tenant);

    Livewire::test(EditTeamProfile::class, ['tenant' => $tenant])
        ->assertSee('Delete Website')
        ->call('delete') // Adjust the method name if different in your code
        ->assertEmitted('confirming-action')
        ->call('confirmAction')
        ->assertEmitted('actionFinished', function ($payload) {
            return $payload['title'] === 'Website deleted' &&
                $payload['body'] === 'The website has been deleted.' &&
                $payload['danger'] === true;
        });

    // Confirm tenant is deleted
    $this->assertDatabaseMissing('tenants', [
        'id' => $tenant->id,
    ]);
}


Does anyone have any good examples of tests for HeaderActions, they would be willing to share?
Solution
https://filamentphp.com/docs/3.x/actions/prebuilt-actions/create#halting-the-creation-process
Actions\Action::make('deleteWebsite')

->callAction('deleteWebsite');

?
Was this page helpful?