Skip to content

Commit 2326017

Browse files
Merge pull request #328 from CodeWithDennis/add-extra-attributes-test
Add test for columns with extra attributes
2 parents d768bcf + a9a3ebb commit 2326017

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
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+
- **ColumnHasExtraAttributesTest** - Tests that columns with extra attributes render them correctly
5657

5758
### Table Functionality Tests
5859
- **CanSearchColumnTest** - Tests that searchable columns work correctly
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
it('`:dataset` column has the extra attributes', function (string $column, array $attributes): void {
2+
$record = {{ $getResourceModel() }}::factory()->create();
3+
4+
livewire({{ $getPageClass('index') }}::class)
5+
->assertTableColumnHasExtraAttributes($column, $attributes, $record);
6+
})->with([
7+
@foreach ($getResourceTableColumnsWithExtraAttributes() as $column)
8+
['{{ $column->getName() }}',
9+
{!! var_export($column->getExtraAttributes(), true) !!}
10+
],
11+
@endforeach
12+
]);

src/Commands/FilamentTestsCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\CanSortColumnTest;
2424
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\ColumnHasDescriptionAboveTest;
2525
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\ColumnHasDescriptionBelowTest;
26+
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\ColumnHasExtraAttributesTest;
2627
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HasColumnTest;
2728
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HasFilterTest;
2829
use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HidesColumnTest;
@@ -33,13 +34,13 @@
3334

3435
class FilamentTestsCommand extends Command
3536
{
37+
use InteractsWithFilesystem;
38+
use InteractsWithUserInput;
39+
3640
protected Collection $panels;
3741

3842
protected Collection $resources;
3943

40-
use InteractsWithFilesystem;
41-
use InteractsWithUserInput;
42-
4344
protected $signature = 'make:filament-test
4445
{--skip-pint : Skip running Pint on generated files}
4546
{--force : Overwrite existing test files without confirmation}';
@@ -74,6 +75,7 @@ protected function getRenderers(): array
7475
HidesColumnTest::class,
7576
ColumnHasDescriptionAboveTest::class,
7677
ColumnHasDescriptionBelowTest::class,
78+
ColumnHasExtraAttributesTest::class,
7779
CanSortColumnTest::class,
7880
CanSearchColumnTest::class,
7981
CanSearchColumnIndividuallyTest::class,

src/Concerns/Resources/InteractsWithTables.php

Lines changed: 6 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 getResourceTableColumnsWithExtraAttributes(): Collection
178+
{
179+
return $this->getResourceTableColumns()
180+
->filter(fn (Column $column): bool => $column->getExtraAttributes() !== []);
181+
}
182+
177183
public function getResourceTableFilters(): Collection
178184
{
179185
return collect($this->getResourceTable()->getFilters());
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 ColumnHasExtraAttributesTest extends BaseTest
8+
{
9+
public ?string $view = 'filament-tests::resources.pages.index.column-has-extra-attributes';
10+
11+
public function getShouldRender(): bool
12+
{
13+
return $this->hasPage('index')
14+
&& $this->getResourceTableColumnsWithExtraAttributes()->isNotEmpty();
15+
}
16+
}

0 commit comments

Comments
 (0)