Skip to content

Commit acb3474

Browse files
Merge pull request #329 from CodeWithDennis/add-select-column-has-options-test
Add SelectColumnHasOptionsTest to verify select column options
2 parents 5fb6867 + 5002359 commit acb3474

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This package generates comprehensive PEST tests for your Filament resources. Her
5353
- **CanNotDisplayTrashedRecordsByDefault** - Tests that trashed records are not displayed by default if soft deletes are enabled
5454
- **ColumnHasDescriptionBelowTest** - Tests that columns with descriptions display them below
5555
- **ColumnHasDescriptionAboveTest** - Tests that columns with descriptions display them above
56+
- **SelectColumnHasOptionsTest** - Tests that select columns have the correct options
5657
- **ColumnHasExtraAttributesTest** - Tests that columns with extra attributes render them correctly
5758

5859
### Table Functionality Tests
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
it('`select-column :dataset` has the correct options', function (string $column, array $options): void {
2+
$record = {{ $getResourceModel() }}::factory()->create();
3+
4+
livewire({{ $getPageClass('index') }}::class)
5+
->assertTableSelectColumnHasOptions($column, $options, $record);
6+
})->with([
7+
@foreach ($getResourceTableSelectColumns() as $column)
8+
['{{ $column->getName() }}',
9+
{!! var_export($column->getOptions(), true) !!}
10+
],
11+
@endforeach
12+
]);

src/Commands/FilamentTestsCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HasColumnTest;
2828
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HasFilterTest;
2929
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HidesColumnTest;
30+
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\SelectColumnHasOptionsTest;
3031
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\ShowsColumnTest;
3132
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\View\CanRenderViewPageTest;
3233
use Illuminate\Console\Command;
@@ -75,6 +76,7 @@ protected function getRenderers(): array
7576
HidesColumnTest::class,
7677
ColumnHasDescriptionAboveTest::class,
7778
ColumnHasDescriptionBelowTest::class,
79+
SelectColumnHasOptionsTest::class,
7880
ColumnHasExtraAttributesTest::class,
7981
CanSortColumnTest::class,
8082
CanSearchColumnTest::class,

src/Concerns/Resources/InteractsWithTables.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ public function getResourceTableTextColumnsWithDescriptionBelow(): Collection
174174
->filter(fn (TextColumn $column): bool => filled($column->getDescriptionBelow()));
175175
}
176176

177+
public function getResourceTableSelectColumns(): Collection
178+
{
179+
return $this->getResourceTableColumns()
180+
->filter(fn (Column $column): bool => $column instanceof \Filament\Tables\Columns\SelectColumn);
181+
}
182+
177183
public function getResourceTableColumnsWithExtraAttributes(): Collection
178184
{
179185
return $this->getResourceTableColumns()
@@ -183,5 +189,6 @@ public function getResourceTableColumnsWithExtraAttributes(): Collection
183189
public function getResourceTableFilters(): Collection
184190
{
185191
return collect($this->getResourceTable()->getFilters());
192+
186193
}
187194
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index;
4+
5+
use CodeWithDennis\FilamentTests\TestRenderers\BaseTest;
6+
7+
class SelectColumnHasOptionsTest extends BaseTest
8+
{
9+
public ?string $view = 'filament-tests::resources.pages.index.select-column-has-options';
10+
11+
public function getShouldRender(): bool
12+
{
13+
return $this->hasPage('index')
14+
&& $this->getResourceTableSelectColumns()->isNotEmpty();
15+
}
16+
}

0 commit comments

Comments
 (0)