FilamentF
Filament13mo ago
sohail

Filament Test Fails for Force Delete Action but Works in Browser

I'm testing a
ForceDeleteAction
for an organization in a Filament table builder Liveware component using Pest. The functionality works perfectly in the browser but fails during the test, with the error:

Failed asserting that a row in the table [organizations] does not match the attributes {
    "id": "9db0f9f5-e8b5-4470-9d58-98cb00c76574"
}.


Here’s my test code:

it('can permanently delete trashed organization', function () {
    $user = User::factory()->create(['email_verified_at' => now()]);
    $this->actingAs($user);
    $organization = Organization::factory()->trashed()->create();

    livewire(Index::class)
        ->callTableAction(ForceDeleteAction::class, $organization, ['confirmation' => 'Confirm'])
        ->assertHasNoTableActionErrors();

    $this->assertModelMissing($organization);
});


And here is the
ForceDeleteAction
implementation:

ForceDeleteAction::make()
    ->label('Delete Permanently')
    ->requiresConfirmation()
    ->icon('fal-trash')
    ->modalIcon(false)
    ->modalWidth(MaxWidth::Large)
    ->modalHeading('Delete Organization')
    ->modalContent(view('components.confirmation-warning'))
    ->modalSubmitActionLabel('Yes, Delete Organization')
    ->successNotificationTitle('Organization has been delete permanently')
    ->form(Organization::confirmationForm());


it works in the browser. However, in the test, it appears that the model is still present in the database, causing
assertModelMissing
to fail.

Additional Details:

  • The
    Organization
    model uses soft deletes.
  • The database has a
    deleted_at
    column.
  • The
    trashed()
    state in the factory correctly sets the
    deleted_at
    column.
What could cause the action to work in the browser but fail during the test? How can I resolve this discrepancy?
Solution
yes
 livewire(Index::class)
        ->filterTable('trashed', 1) // make sure the trashed filtered is active
        ->callTableAction(ForceDeleteAction::class, $organization, ['confirmation' => 'Confirm'])
        ->assertHasNoTableActionErrors();
Was this page helpful?