|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use OpenSpout\Reader\XLSX\Reader;
|
| 4 | +use PowerComponents\LivewirePowerGrid\Facades\PowerGrid; |
| 5 | + |
4 | 6 | use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\ExportTable;
|
5 | 7 |
|
6 | 8 | use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire;
|
7 | 9 |
|
8 |
| -use PowerComponents\LivewirePowerGrid\{Button,Column}; |
| 10 | +use PowerComponents\LivewirePowerGrid\{Button,Column, PowerGridFields}; |
9 | 11 |
|
10 | 12 | it('properly export xls - all data', function () {
|
11 | 13 | livewire(ExportTable::class)
|
@@ -128,6 +130,100 @@ public function actions($row): array
|
128 | 130 | 'data' => [$exportWithAction::class],
|
129 | 131 | ]);
|
130 | 132 |
|
| 133 | +$exportWithHtml = new class () extends ExportTable { |
| 134 | + public function fields(): PowerGridFields |
| 135 | + { |
| 136 | + return PowerGrid::fields() |
| 137 | + ->add('nameWithHtml', function ($dish) { |
| 138 | + return sprintf( |
| 139 | + '<a> %s </a>', |
| 140 | + e($dish->name) |
| 141 | + ); |
| 142 | + }); |
| 143 | + } |
| 144 | + |
| 145 | + public function columns(): array |
| 146 | + { |
| 147 | + return [ |
| 148 | + Column::add() |
| 149 | + ->title('nameWithHtml') |
| 150 | + ->field('nameWithHtml'), |
| 151 | + ]; |
| 152 | + } |
| 153 | +}; |
| 154 | + |
| 155 | +it('properly export csv with tags', function (string $component) { |
| 156 | + $downloadedFile = livewire($component, ['testStripHtml' => false]) |
| 157 | + ->set('checkboxValues', [ |
| 158 | + 0 => '1', |
| 159 | + ]) |
| 160 | + ->call('exportToCsv', true) |
| 161 | + ->assertFileDownloaded('export.csv'); |
| 162 | + |
| 163 | + $headings = ['nameWithHtml']; |
| 164 | + |
| 165 | + $rows = [ |
| 166 | + ['a Pastel de Nata a'], |
| 167 | + ]; |
| 168 | + |
| 169 | + expect($downloadedFile)->toBeCsvDownload($headings, $rows); |
| 170 | +})->with('export_with_html')->requiresOpenSpout(); |
| 171 | + |
| 172 | +it('properly export csv without tags', function (string $component) { |
| 173 | + $downloadedFile = livewire($component, ['testStripHtml' => true]) |
| 174 | + ->set('checkboxValues', [ |
| 175 | + 0 => '1', |
| 176 | + ]) |
| 177 | + ->call('exportToCsv', true) |
| 178 | + ->assertFileDownloaded('export.csv'); |
| 179 | + |
| 180 | + $headings = ['nameWithHtml']; |
| 181 | + |
| 182 | + $rows = [ |
| 183 | + [' Pastel de Nata '], |
| 184 | + ]; |
| 185 | + |
| 186 | + expect($downloadedFile)->toBeCsvDownload($headings, $rows); |
| 187 | +})->with('export_with_html')->requiresOpenSpout(); |
| 188 | + |
| 189 | +it('properly export xls with tags', function (string $component) { |
| 190 | + $downloadedFile = livewire($component, ['testStripHtml' => false]) |
| 191 | + ->set('checkboxValues', [ |
| 192 | + 0 => '1', |
| 193 | + ]) |
| 194 | + ->call('exportToXLS', true) |
| 195 | + ->assertFileDownloaded('export.xlsx'); |
| 196 | + |
| 197 | + $headings = ['nameWithHtml']; |
| 198 | + |
| 199 | + $rows = [ |
| 200 | + ['a Pastel de Nata a'], |
| 201 | + ]; |
| 202 | + |
| 203 | + expect($downloadedFile)->toBeXLSDownload($headings, $rows); |
| 204 | +})->with('export_with_html')->requiresOpenSpout(); |
| 205 | + |
| 206 | +it('properly export xls without tags', function (string $component) { |
| 207 | + $downloadedFile = livewire($component, ['testStripHtml' => true]) |
| 208 | + ->set('checkboxValues', [ |
| 209 | + 0 => '1', |
| 210 | + ]) |
| 211 | + ->call('exportToXLS', true) |
| 212 | + ->assertFileDownloaded('export.xlsx'); |
| 213 | + |
| 214 | + $headings = ['nameWithHtml']; |
| 215 | + |
| 216 | + $rows = [ |
| 217 | + [' Pastel de Nata '], |
| 218 | + ]; |
| 219 | + |
| 220 | + expect($downloadedFile)->toBeXLSDownload($headings, $rows); |
| 221 | +})->with('export_with_html')->requiresOpenSpout(); |
| 222 | + |
| 223 | +dataset('export_with_html', [ |
| 224 | + 'html' => [$exportWithHtml::class], |
| 225 | +]); |
| 226 | + |
131 | 227 | /*
|
132 | 228 | |--------------------------------------------------------------------------
|
133 | 229 | | Expectations for this test
|
|
0 commit comments