|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use OpenSpout\Reader\XLSX\Reader;
|
4 |
| -use PowerComponents\LivewirePowerGrid\{Button,Column, PowerGridFields}; |
| 4 | +use PowerComponents\LivewirePowerGrid\{Button, Column, Components\SetUp\Exportable, PowerGridFields}; |
5 | 5 | use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
|
6 | 6 | use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\ExportTable;
|
7 | 7 |
|
@@ -224,6 +224,59 @@ public function columns(): array
|
224 | 224 | 'html' => [$exportWithHtml::class],
|
225 | 225 | ]);
|
226 | 226 |
|
| 227 | +$exportWithQueryOptions = new class() extends ExportTable |
| 228 | +{ |
| 229 | + public string $testSortField = ''; |
| 230 | + |
| 231 | + public string $testSortDirection = ''; |
| 232 | + |
| 233 | + public function setUp(): array |
| 234 | + { |
| 235 | + $this->showCheckBox(); |
| 236 | + |
| 237 | + return [ |
| 238 | + PowerGrid::exportable('export') |
| 239 | + ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV) |
| 240 | + ->queryOptions([ |
| 241 | + 'sortField' => $this->testSortField, |
| 242 | + 'sortDirection' => $this->testSortDirection, |
| 243 | + ]), |
| 244 | + ]; |
| 245 | + } |
| 246 | + |
| 247 | + public function fields(): PowerGridFields |
| 248 | + { |
| 249 | + return PowerGrid::fields() |
| 250 | + ->add('name', function ($dish) { |
| 251 | + return $dish->name; |
| 252 | + }); |
| 253 | + } |
| 254 | + |
| 255 | + public function columns(): array |
| 256 | + { |
| 257 | + return [ |
| 258 | + Column::add() |
| 259 | + ->title('name') |
| 260 | + ->field('name'), |
| 261 | + ]; |
| 262 | + } |
| 263 | +}; |
| 264 | + |
| 265 | +it('properly exports with query options', function ($component, $options, $expectedRows) { |
| 266 | + $downloadedFile = livewire($component, $options) |
| 267 | + ->set('checkboxValues', [0 => '1', 1 => '3']) |
| 268 | + ->call('exportToCsv', true) |
| 269 | + ->assertFileDownloaded('export.csv'); |
| 270 | + |
| 271 | + expect($downloadedFile)->toBeCsvDownload(['name'], $expectedRows); |
| 272 | + |
| 273 | +})->with('export_with_query_options')->requiresOpenSpout(); |
| 274 | + |
| 275 | +dataset('export_with_query_options', [ |
| 276 | + 'desc' => [$exportWithQueryOptions::class, ['testSortField' => 'name', 'testSortDirection' => 'desc'], [['Pastel de Nata'], ['Carne Louca']]], |
| 277 | + 'asc' => [$exportWithQueryOptions::class, ['testSortField' => 'name', 'testSortDirection' => 'asc'], [['Carne Louca'], ['Pastel de Nata']]], |
| 278 | +]); |
| 279 | + |
227 | 280 | /*
|
228 | 281 | |--------------------------------------------------------------------------
|
229 | 282 | | Expectations for this test
|
|
0 commit comments