testing table action

Maybe I am being dumb but hopefully someone can help.

I have a simple Resource that has a table and it also has a custom page.

The custom page is listed in the getPages() function on the resource

public static function getPages(): array
    {
        return [
            'stats' => Pages\FirmStats::route('/{record}/stats'),
        ];
    }


I have a row action to open a new custom page.

$table->columns(...)->actions([
    Tables\Actions\Action::make('stats')
      ->icon('heroicon-o-chart-pie')
      ->label('Stats')
      ->url(fn (Firm $record): string => FirmResource::getUrl('stats', ['record' => $record])),
])


This works fine in the browser. It opens the URL as expected.

I'm trying to write a simple test and I can't work out how. I am looking at the docs here https://filamentphp.com/docs/3.x/tables/testing#url and there should be a simple assertTableActionHasUrl

However when I use that in our test it fails because the Action isn't loading the current record in to the Action and I'm not sure how to proceed.

test('firms have a link to their stats page', function() {
        $firm = Firm::factory()->create();

        livewire(FirmResource\Pages\ListFirms::class)
            ->loadTable()
            ->assertCanSeeTableRecords([$firm])
            ->assertTableActionExists('stats')
            ->assertTableActionHasUrl('stats', FirmResource::getUrl('stats', ['record' => $firm]));
    });

// TypeError: App\Filament\Resources\FirmResource::App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\Firm, null given

So the error is happening on the ->url(fn(Firm $record)) in the action...

Any advice ?
Was this page helpful?