© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
38 replies
Mark Chaney

Testing Table Action with modal

My action code is
public function removeAction(): Action
{
    ray('running remove action');

    return Action::make('removeAction')
        ->label('Remove')
        ->icon('heroicon-o-x-circle')
        ->color('danger')
        ->modalHeading(fn($record) => 'Remove ' . $record->user->name)
        ->modalDescription(fn($record) => 'Are you sure you want to de-associate this property manager?')
        ->action(function ($record) {
            ray($record);
            return $record->update(['property_management_company_id' => null]);
        })
        ->successNotificationTitle('Property manager has been de-associated.')
        ->visible($this->propertyManagementCompany !== null)
        ->after(fn() => $this->emitTo(ViewPropertyManagementCompany::class, '$refresh'));
}
public function removeAction(): Action
{
    ray('running remove action');

    return Action::make('removeAction')
        ->label('Remove')
        ->icon('heroicon-o-x-circle')
        ->color('danger')
        ->modalHeading(fn($record) => 'Remove ' . $record->user->name)
        ->modalDescription(fn($record) => 'Are you sure you want to de-associate this property manager?')
        ->action(function ($record) {
            ray($record);
            return $record->update(['property_management_company_id' => null]);
        })
        ->successNotificationTitle('Property manager has been de-associated.')
        ->visible($this->propertyManagementCompany !== null)
        ->after(fn() => $this->emitTo(ViewPropertyManagementCompany::class, '$refresh'));
}
with my test being
it('disassociate property manager with property management company', function () {
    /* @phpstan-ignore-next-line */
    $user = login();
    /* @phpstan-ignore-next-line */
    $this->withSession(['tenant' => $user->tenant]);

    $propertyManagementCompany = PropertyManagementCompany::factory()->create();
    $propertyManager = PropertyManager::factory()->create([
        'property_management_company_id' => $propertyManagementCompany->id,
    ]);

    /* @phpstan-ignore-next-line */
    $this->get('/property-managers/companies/' . $propertyManagementCompany->id);

    Livewire::test(PropertyManagersTable::class, ['propertyManagementCompany' => $propertyManagementCompany])
        ->assertTableActionExists('removeAction')
        ->callTableAction('removeAction', record: $propertyManager)
        ->assertHasNoErrors();

    expect($propertyManager->fresh()->property_management_company_id)->toBeNull();
});
it('disassociate property manager with property management company', function () {
    /* @phpstan-ignore-next-line */
    $user = login();
    /* @phpstan-ignore-next-line */
    $this->withSession(['tenant' => $user->tenant]);

    $propertyManagementCompany = PropertyManagementCompany::factory()->create();
    $propertyManager = PropertyManager::factory()->create([
        'property_management_company_id' => $propertyManagementCompany->id,
    ]);

    /* @phpstan-ignore-next-line */
    $this->get('/property-managers/companies/' . $propertyManagementCompany->id);

    Livewire::test(PropertyManagersTable::class, ['propertyManagementCompany' => $propertyManagementCompany])
        ->assertTableActionExists('removeAction')
        ->callTableAction('removeAction', record: $propertyManager)
        ->assertHasNoErrors();

    expect($propertyManager->fresh()->property_management_company_id)->toBeNull();
});
, while it runs the action method, it never seems to get to the removeAction method, it never gets to the ->action() within it. Only my tests are failing. Its working great in the actual browser. Im assuming i need to call something else?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

testing table action
FilamentFFilament / ❓┊help
2y ago
Table action testing
FilamentFFilament / ❓┊help
3y ago
table action modal
FilamentFFilament / ❓┊help
3y ago
Modal Action in Form with Table Modal Body
FilamentFFilament / ❓┊help
9mo ago