Skip to content

Commit 94b6471

Browse files
committed
Move Visuals tests to Visuals section, clean up tests
1 parent 1f3a15c commit 94b6471

File tree

7 files changed

+181
-44
lines changed

7 files changed

+181
-44
lines changed

tests/DataTableComponentTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests;
44

5-
use Livewire\Livewire;
65
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\NoColumnsTable;
76
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\NoPrimaryKeyTable;
87
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
@@ -27,12 +26,6 @@ public function test_primary_key_can_be_checked_for_existence(): void
2726
$this->assertFalse($this->basicTable->hasPrimaryKey());
2827
}
2928

30-
public function test_primary_key_has_to_be_set(): void
31-
{
32-
$this->expectException(\Illuminate\View\ViewException::class);
33-
Livewire::test(NoPrimaryKeyTable::class)
34-
->call('setSearch', 'abcd');
35-
}
3629

3730
public function test_default_fingerprint_will_always_be_the_same_for_same_datatable(): void
3831
{

tests/Unit/Traits/Configuration/ComponentConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function test_can_set_th_attributes(): void
7373
return ['default' => true, 'here' => 'there'];
7474
});
7575

76-
$this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[0]), ['default' => false, 'default-colors' => false, 'default-styling' => false, 'this' => 'that']);
77-
$this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[1]), ['default' => true, 'default-colors' => false, 'default-styling' => false, 'here' => 'there']);
76+
$this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[0]), ['scope' => 'col', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'this' => 'that']);
77+
$this->assertSame($this->basicTable->getThAttributes($this->basicTable->columns()[1]), ['scope' => 'col', 'default' => true, 'default-colors' => false, 'default-styling' => false, 'here' => 'there']);
7878
}
7979

8080
public function test_can_set_th_sort_button_attributes(): void

tests/Unit/Traits/WithCustomisationsTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,12 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits;
44

5-
use Livewire\Component;
65
use Livewire\Features\SupportPageComponents\PageComponentConfig;
7-
use Livewire\Livewire;
86
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
97
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
108

119
final class WithCustomisationsTest extends TestCase
1210
{
13-
public function test_can_use_as_nested(): void
14-
{
15-
$test = Livewire::test([new class extends Component
16-
{
17-
public function render()
18-
{
19-
return <<<'HTML'
20-
<div>
21-
<div>ParentComponentTest</div>
22-
<div> <livewire:child /></div>
23-
</div>
24-
HTML;
25-
}
26-
},
27-
'child' => new class extends PetsTable
28-
{
29-
public function configure(): void
30-
{
31-
parent::configure();
32-
$this->setLayout('livewire-tables::tests.layout1');
33-
34-
}
35-
},
36-
])
37-
->assertSee('ParentComponentTest')
38-
->assertSee('Cartman');
39-
40-
}
4111

4212
public function test_can_use_as_full_page(): void
4313
{

tests/Unit/Visuals/BulkActionsVisualsTest.php

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function exportBulk($items)
192192
})->assertDontSee('Bulk Actions');
193193
}
194194

195-
public function test_bulk_dropdown_can_have_customised_classes(): void
195+
public function test_bulk_dropdown_can_have_customised_classes_with_no_defaults(): void
196196
{
197197
Livewire::test(new class extends PetsTable
198198
{
@@ -202,7 +202,7 @@ public function configure(): void
202202
$this->setBulkActionsThAttributes([
203203
'class' => 'bg-yellow-500 dark:bg-yellow-800',
204204
'default' => false,
205-
'default-styling' => true,
205+
'default-styling' => false,
206206
'default-colors' => false,
207207
]);
208208

@@ -224,4 +224,106 @@ public function exportBulk($items)
224224
'wire:key="table-thead-bulk-actions"',
225225
]);
226226
}
227+
228+
public function test_bulk_dropdown_can_have_customised_classes_with_default_styling(): void
229+
{
230+
Livewire::test(new class extends PetsTable
231+
{
232+
public function configure(): void
233+
{
234+
$this->setPrimaryKey('id');
235+
$this->setBulkActionsThAttributes([
236+
'class' => 'bg-yellow-500 dark:bg-yellow-800',
237+
'default' => false,
238+
'default-styling' => true,
239+
'default-colors' => false,
240+
]);
241+
242+
}
243+
244+
public function bulkActions(): array
245+
{
246+
return ['exportBulk' => 'exportBulk'];
247+
}
248+
249+
public function exportBulk($items)
250+
{
251+
return $items;
252+
}
253+
})->assertSee('Bulk Actions')
254+
->assertSeeHtmlInOrder([
255+
'scope="col"',
256+
'class="table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left laravel-livewire-tables-reorderingMinimised bg-yellow-500 dark:bg-yellow-800"',
257+
'wire:key="table-thead-bulk-actions"',
258+
]);
259+
}
260+
261+
262+
public function test_bulk_dropdown_can_have_customised_classes_with_default_colors(): void
263+
{
264+
Livewire::test(new class extends PetsTable
265+
{
266+
public function configure(): void
267+
{
268+
$this->setPrimaryKey('id');
269+
$this->setBulkActionsThAttributes([
270+
'class' => 'text-lg',
271+
'default' => false,
272+
'default-styling' => false,
273+
'default-colors' => true,
274+
]);
275+
276+
}
277+
278+
public function bulkActions(): array
279+
{
280+
return ['exportBulk' => 'exportBulk'];
281+
}
282+
283+
public function exportBulk($items)
284+
{
285+
return $items;
286+
}
287+
})->assertSee('Bulk Actions')
288+
->assertSeeHtmlInOrder([
289+
'scope="col"',
290+
'class="bg-gray-50 dark:bg-gray-800 text-lg"',
291+
'wire:key="table-thead-bulk-actions"',
292+
]);
293+
}
294+
295+
public function test_bulk_dropdown_can_have_customised_classes_with_defaults(): void
296+
{
297+
Livewire::test(new class extends PetsTable
298+
{
299+
public function configure(): void
300+
{
301+
$this->setPrimaryKey('id');
302+
$this->setBulkActionsThAttributes([
303+
'class' => 'text-lg',
304+
'default' => true,
305+
'default-styling' => true,
306+
'default-colors' => true,
307+
]);
308+
309+
}
310+
311+
public function bulkActions(): array
312+
{
313+
return ['exportBulk' => 'exportBulk'];
314+
}
315+
316+
public function exportBulk($items)
317+
{
318+
return $items;
319+
}
320+
})->assertSee('Bulk Actions')
321+
->assertSeeHtmlInOrder([
322+
'scope="col"',
323+
'class="table-cell px-3 py-2 md:px-6 md:py-3 text-center md:text-left laravel-livewire-tables-reorderingMinimised bg-gray-50 dark:bg-gray-800 text-lg"',
324+
'wire:key="table-thead-bulk-actions"',
325+
]);
326+
}
327+
328+
227329
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Visuals;
4+
5+
use Exception;
6+
use Illuminate\View\ViewException;
7+
use Livewire\Livewire;
8+
use PHPUnit\Framework\Attributes\Group;
9+
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
10+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\{BrokenSecondaryHeaderTable, NoBuildMethodTable, NoPrimaryKeyTable};
11+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\{PetsTable,PetsTableAttributes};
12+
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
13+
use Livewire\Component;
14+
15+
#[Group('Visuals')]
16+
final class CustomisationsVisualsTest extends TestCase
17+
{
18+
public function test_can_use_as_nested(): void
19+
{
20+
$test = Livewire::test([new class extends Component
21+
{
22+
public function render()
23+
{
24+
return <<<'HTML'
25+
<div>
26+
<div>ParentComponentTest</div>
27+
<div> <livewire:child /></div>
28+
</div>
29+
HTML;
30+
}
31+
},
32+
'child' => new class extends PetsTable
33+
{
34+
public function configure(): void
35+
{
36+
parent::configure();
37+
$this->setLayout('livewire-tables::tests.layout1');
38+
39+
}
40+
},
41+
])
42+
->assertSee('ParentComponentTest')
43+
->assertSee('Cartman');
44+
45+
}
46+
47+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Visuals;
4+
5+
use Exception;
6+
use Illuminate\View\ViewException;
7+
use Livewire\Livewire;
8+
use PHPUnit\Framework\Attributes\Group;
9+
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
10+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables\{BrokenSecondaryHeaderTable, NoBuildMethodTable, NoPrimaryKeyTable};
11+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\{PetsTable,PetsTableAttributes};
12+
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
13+
use Livewire\Component;
14+
15+
#[Group('Visuals')]
16+
final class DataTableComponentVisualsTest extends TestCase
17+
{
18+
public function test_primary_key_has_to_be_set(): void
19+
{
20+
$this->expectException(\Illuminate\View\ViewException::class);
21+
Livewire::test(NoPrimaryKeyTable::class)
22+
->call('setSearch', 'abcd');
23+
}
24+
25+
}

tests/Unit/Visuals/SortingVisualsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function test_th_headers_are_buttons_with_sorting_enabled(): void
3737
Livewire::test(PetsTable::class)
3838
->assertSeeHtmlInOrder([
3939
'wire:click="sortBy(\'id\')"',
40-
'class="flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none text-gray-500 dark:text-gray-400"',
40+
'class="text-gray-500 dark:text-gray-400 flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none"',
4141
]);
4242
}
4343

@@ -58,12 +58,12 @@ public function test_th_headers_are_not_buttons_until_sorting_enabled(): void
5858
->call('setSortingDisabled')
5959
->assertDontSeeHtml('<button
6060
wire:click="sortBy(\'id\')"
61-
class="flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none text-gray-500 dark:text-gray-400"
61+
class="text-gray-500 dark:text-gray-400 flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none"
6262
>')
6363
->call('setSortingEnabled')
6464
->assertSeeHtmlInOrder([
6565
'wire:click="sortBy(\'id\')"',
66-
'class="flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none text-gray-500 dark:text-gray-400"',
66+
'class="text-gray-500 dark:text-gray-400 flex items-center space-x-1 text-left text-xs leading-4 font-medium uppercase tracking-wider group focus:outline-none"',
6767
]);
6868

6969
}

0 commit comments

Comments
 (0)