© 2026 Hedgehog Software, LLC

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

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();
        }),
]);
->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);
});
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);
});
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
Testing Table Action with modal
FilamentFFilament / ❓┊help
3y ago
Testing Table Header action in relation manager?
FilamentFFilament / ❓┊help
2y ago
Failing test when calling testing a table action
FilamentFFilament / ❓┊help
14mo ago