Table action testing

Im not really sure how to use callTableAction() for testing. Also to verify, this does work for headerActions too, right? I have a button that creates an export of the table contents and I am looking to verify the action works. Would love to verify even the contents of the csv it creates by comparing csv rows to table rows. The problem obviously is that it creates a dynamic file, so not as easy to evaluate. This is what I have so far and i know my code is wrong after the $response. Tried to go super simple to even just check file type and size:
->headerActions([
    Action::make('export')
        ->label('Export')
        ->icon('heroicon-o-arrow-down-tray')
        ->action(function ($livewire) {
            return (new ProjectsReportExport($livewire->getFilteredTableQuery()))->download('projects_report_' . now()->timestamp . '.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
        })
        ->tooltip('This will export the table along with any applied filters to a CSV file.')
        ->after(function ($action) {
            Notification::make()->success()->title('Export Complete')->send();
        }),
]);
and
it('can export projects report to csv', function () {
// Set up
    login();
    Project::factory()->count(10)->create();

// Call the export action and capture the response
    $response = Livewire::test(ProjectsReport::class)->callTableAction('export');

// Assert
// Check if the response is not empty
    expect($response)->notEmpty();

// Check if the response has the correct Content-Type header
    $headers = $response->headers->all();
    expect($headers['content-type'][0])->toBe('text/csv');

// Check if the file size is greater than 100 bytes
    $fileSize = strlen($response->getContent());
    expect($fileSize)->toBeGreaterThan(100);
});
Was this page helpful?