From 12fd5b3787509801bf65b2a713597b587a37c91d Mon Sep 17 00:00:00 2001 From: Matthieu Lempereur Date: Sat, 19 Oct 2024 16:56:09 +0200 Subject: [PATCH] feat: make column action no exportable by default (#1741) --- src/Column.php | 3 ++- tests/Feature/ExportTest.php | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Column.php b/src/Column.php index df1a38fac..e30f3e565 100644 --- a/src/Column.php +++ b/src/Column.php @@ -93,7 +93,8 @@ public static function action(string $title): self { return (new static()) ->title($title) - ->isAction(); + ->isAction() + ->visibleInExport(false); } public function isAction(): Column diff --git a/tests/Feature/ExportTest.php b/tests/Feature/ExportTest.php index 5d270eb06..be95bb4e1 100644 --- a/tests/Feature/ExportTest.php +++ b/tests/Feature/ExportTest.php @@ -5,6 +5,8 @@ use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; +use PowerComponents\LivewirePowerGrid\{Button,Column}; + it('properly export xls - all data', function () { livewire(ExportTable::class) ->call('exportToXLS', false) @@ -85,6 +87,47 @@ expect()->notToBeFileDownloaded($component); })->requiresOpenSpout(); +$exportWithAction = new class () extends ExportTable { + public function columns(): array + { + return [ + Column::action('Foo') + ->visibleInExport(true), + ]; + } + + public function actions($row): array + { + return [ + Button::add('Foo'), + ]; + } +}; + +it('properly export xls with action', function (string $component) { + $downloadedFile = livewire($component) + ->call('exportToXLS', false) + ->assertFileDownloaded('export.xlsx'); + + $headings = ['Foo']; + + expect($downloadedFile)->toBeXLSDownload($headings, []); +})->with('export_with_action')->requiresOpenSpout(); + +it('properly export csv with action', function (string $component) { + $downloadedFile = livewire($component) + ->call('exportToCsv', false) + ->assertFileDownloaded('export.csv'); + + $headings = ['Foo']; + + expect($downloadedFile)->toBeCsvDownload($headings, []); +})->with('export_with_action')->requiresOpenSpout(); + +dataset('export_with_action', [ + 'data' => [$exportWithAction::class], +]); + /* |-------------------------------------------------------------------------- | Expectations for this test