From 987701505a8b41dd0cea6d408d43c59ead625a71 Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Tue, 12 Nov 2024 22:46:06 +0000 Subject: [PATCH 1/4] Add test for ColumnsSelected Event dispatch --- .../Helpers/ColumnSelectHelpersTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php index 7ddf9d04b..e96980653 100644 --- a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php @@ -2,7 +2,11 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers; + +use Illuminate\Support\Facades\Event; +use Rappasoft\LaravelLivewireTables\Events\ColumnsSelected; use Rappasoft\LaravelLivewireTables\Tests\TestCase; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; final class ColumnSelectHelpersTest extends TestCase { @@ -103,4 +107,42 @@ public function test_get_currently_selected_cols_works(): void $this->assertSame(8, count($this->basicTable->getDefaultVisibleColumns())); } + + public function test_event_fires_for_columnselect(): void + { + Event::fake(); + + $testTable = new class extends PetsTable + { + public function configure(): void + { + parent::configure(); + } + }; + $testTable->configure(); + $testTable->boot(); + $testTable->bootedComponentUtilities(); + $testTable->bootedWithData(); + $testTable->bootedWithColumns(); + $testTable->bootedWithColumnSelect(); + $testTable->bootedWithSecondaryHeader(); + $testTable->booted(); + + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg'], $testTable->selectedColumns); + + $testTable->disableColumnSelectEvent(); + $testTable->selectedColumns = ['id', 'sort', 'name', 'age', 'breed', 'other', 'rowimg']; + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'rowimg'], $testTable->selectedColumns); + $testTable->updatedSelectedColumns(); + Event::assertNotDispatched(ColumnsSelected::class); + + $testTable->enableColumnSelectEvent(); + + $testTable->selectedColumns = ['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg']; + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg'], $testTable->selectedColumns); + $testTable->updatedSelectedColumns(); + Event::assertDispatched(ColumnsSelected::class); + + } + } From 2642368f2ed2fd45680d0540c741289719c45dbe Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 12 Nov 2024 22:46:38 +0000 Subject: [PATCH 2/4] Fix styling --- tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php index e96980653..f1bb7faea 100644 --- a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php @@ -2,11 +2,10 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers; - use Illuminate\Support\Facades\Event; use Rappasoft\LaravelLivewireTables\Events\ColumnsSelected; -use Rappasoft\LaravelLivewireTables\Tests\TestCase; use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; +use Rappasoft\LaravelLivewireTables\Tests\TestCase; final class ColumnSelectHelpersTest extends TestCase { @@ -144,5 +143,4 @@ public function configure(): void Event::assertDispatched(ColumnsSelected::class); } - } From bb000c6df3ba364c18f2496cdcc00900562daf21 Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Tue, 12 Nov 2024 22:48:50 +0000 Subject: [PATCH 3/4] Apply Separate Tests --- .../Helpers/ColumnSelectHelpersTest.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php index f1bb7faea..01b17a24d 100644 --- a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php @@ -143,4 +143,63 @@ public function configure(): void Event::assertDispatched(ColumnsSelected::class); } + + public function test_event_does_fire_for_columnselect(): void + { + Event::fake(); + + $testTable = new class extends PetsTable + { + public function configure(): void + { + parent::configure(); + $this->enableColumnSelectEvent(); + } + }; + $testTable->configure(); + $testTable->boot(); + $testTable->bootedComponentUtilities(); + $testTable->bootedWithData(); + $testTable->bootedWithColumns(); + $testTable->bootedWithColumnSelect(); + $testTable->bootedWithSecondaryHeader(); + $testTable->booted(); + + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg'], $testTable->selectedColumns); + + $testTable->selectedColumns = ['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg']; + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg'], $testTable->selectedColumns); + $testTable->updatedSelectedColumns(); + Event::assertDispatched(ColumnsSelected::class); + + } + + public function test_event_does_not_fire_for_columnselect(): void + { + Event::fake(); + + $testTable = new class extends PetsTable + { + public function configure(): void + { + parent::configure(); + $this->disableColumnSelectEvent(); + } + }; + $testTable->configure(); + $testTable->boot(); + $testTable->bootedComponentUtilities(); + $testTable->bootedWithData(); + $testTable->bootedWithColumns(); + $testTable->bootedWithColumnSelect(); + $testTable->bootedWithSecondaryHeader(); + $testTable->booted(); + + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'link', 'rowimg'], $testTable->selectedColumns); + $testTable->selectedColumns = ['id', 'sort', 'name', 'age', 'breed', 'other', 'rowimg']; + $this->assertSame(['id', 'sort', 'name', 'age', 'breed', 'other', 'rowimg'], $testTable->selectedColumns); + $testTable->updatedSelectedColumns(); + Event::assertNotDispatched(ColumnsSelected::class); + } + } From 36680ca2c318a3c0b68d41a79131605937591919 Mon Sep 17 00:00:00 2001 From: lrljoe Date: Tue, 12 Nov 2024 22:49:19 +0000 Subject: [PATCH 4/4] Fix styling --- tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php index 01b17a24d..4da1d5912 100644 --- a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php @@ -201,5 +201,4 @@ public function configure(): void $testTable->updatedSelectedColumns(); Event::assertNotDispatched(ColumnsSelected::class); } - }