Skip to content

Commit b8a86f8

Browse files
committed
Additional Tests for LivewireComponentColumn
1 parent b7ca663 commit b8a86f8

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire;
4+
5+
use Illuminate\Support\Facades\App;
6+
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
7+
use Rappasoft\LaravelLivewireTables\Views\Column;
8+
use Rappasoft\LaravelLivewireTables\Views\Columns\LivewireComponentColumn;
9+
10+
11+
class PetsTableWithLivewireColumn extends BaseTable
12+
{
13+
public $model = Pet::class;
14+
15+
public function changeLocale(string $locale)
16+
{
17+
App::setLocale($locale);
18+
}
19+
20+
public function configure(): void
21+
{
22+
$this->setPrimaryKey('id');
23+
}
24+
25+
public function columns(): array
26+
{
27+
return [
28+
Column::make('ID', 'id')
29+
->sortable(),
30+
Column::make('Name', 'name')
31+
->sortable(),
32+
LivewireComponentColumn::make("LW","name")
33+
->component('test-livewire-column-component')->attributes(function ($columnValue, $row) {
34+
return [
35+
'type' => 'test',
36+
'name' => $row->name,
37+
];
38+
}),
39+
];
40+
}
41+
}

tests/TestServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class TestServiceProvider extends ServiceProvider
1111
public function boot(): void
1212
{
1313
Blade::component('test-component', TestComponent::class);
14+
15+
\Livewire\Livewire::component('test-livewire-column-component', \Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\TestLivewireColumnComponent::class);
16+
1417
$this->loadViewsFrom(__DIR__.'/views', 'livewire-tables-test');
1518

1619
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Visuals\Columns;
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\{PetsTableWithLivewireColumn};
12+
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
13+
14+
#[Group('Visuals')]
15+
final class LivewireComponentColumnVisualsTest extends TestCase
16+
{
17+
private $testErrors;
18+
19+
public function test_icon_column_renders_correctly(): void
20+
{
21+
Livewire::test(PetsTableWithLivewireColumn::class)
22+
->assertSeeHtmlInOrder([
23+
'<div>Name:Ben</div><div>Type:test</div>',
24+
'<div>Name:Cartman</div><div>Type:test</div>',
25+
]);
26+
27+
}
28+
29+
public function test_icon_column_renders_correctly_with_asc_sort(): void
30+
{
31+
$temp = new class extends PetsTableWithLivewireColumn
32+
{
33+
public function configure(): void
34+
{
35+
parent::configure();
36+
37+
$this->setDefaultSort('name', 'asc');
38+
39+
}
40+
};
41+
Livewire::test($temp)
42+
->assertSeeHtmlInOrder([
43+
'<div>Name:Ben</div><div>Type:test</div>',
44+
'<div>Name:Cartman</div><div>Type:test</div>',
45+
]);
46+
}
47+
48+
public function test_icon_column_renders_correctly_with_desc_sort(): void
49+
{
50+
$temp = new class extends PetsTableWithLivewireColumn
51+
{
52+
public function configure(): void
53+
{
54+
parent::configure();
55+
56+
$this->setDefaultSort('name', 'desc');
57+
58+
}
59+
};
60+
Livewire::test($temp)
61+
->assertSeeHtmlInOrder([
62+
'<div>Name:Cartman</div><div>Type:test</div>',
63+
'<div>Name:Ben</div><div>Type:test</div>',
64+
]);
65+
}
66+
}

0 commit comments

Comments
 (0)