diff --git a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php index 7ddf9d04b..4da1d5912 100644 --- a/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php +++ b/tests/Unit/Traits/Helpers/ColumnSelectHelpersTest.php @@ -2,6 +2,9 @@ namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Helpers; +use Illuminate\Support\Facades\Event; +use Rappasoft\LaravelLivewireTables\Events\ColumnsSelected; +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; use Rappasoft\LaravelLivewireTables\Tests\TestCase; final class ColumnSelectHelpersTest extends TestCase @@ -103,4 +106,99 @@ 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); + + } + + 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); + } }