Creating a test for ToggleColumn

Tables\Columns\ToggleColumn::make('is_active')
->onIcon('heroicon-o-eye')
->offIcon('heroicon-o-eye-slash')
->label('Visibility'),
Tables\Columns\ToggleColumn::make('is_active')
->onIcon('heroicon-o-eye')
->offIcon('heroicon-o-eye-slash')
->label('Visibility'),
i am wondering how to make the test for ToggleColumn
No description
8 Replies
Rolland
Rolland2mo ago
bump this is what i have so far:
// T7. Test visibility toggle column functionality
it('has functioning visibility toggle column', function () {
$category = Category::factory()->create(['is_active' => true]);

livewire(ListCategories::class)
->assertCanRenderTableColumn('is_active')
->assertTableColumnStateSet('is_active', true, $category)
->callTableColumnAction('is_active', $category)
->assertTableColumnStateSet('is_active', false, $category);

$category->refresh();
expect($category->is_active)->toBeFalse();
})->group('table');
// T7. Test visibility toggle column functionality
it('has functioning visibility toggle column', function () {
$category = Category::factory()->create(['is_active' => true]);

livewire(ListCategories::class)
->assertCanRenderTableColumn('is_active')
->assertTableColumnStateSet('is_active', true, $category)
->callTableColumnAction('is_active', $category)
->assertTableColumnStateSet('is_active', false, $category);

$category->refresh();
expect($category->is_active)->toBeFalse();
})->group('table');
bump bump
awcodes
awcodes2mo ago
What exactly are you seeing in your tests? Ie what are the failing outputs?
Rolland
Rolland2mo ago
the output:
FAILED Tests\Feature\Filament\CategoryResource\ListTest > `Category Table` it has functioning visibility toggle column
Failed asserting that a table column with name [is_active] has value of [] for record [11] on the [App\Filament\Resources\CategoryResource\Pages\ListCategories] component.
Failed asserting that false is true.

at vendor\filament\tables\src\Testing\TestsColumns.php:193
189▕ if (is_array($value)) {
190▕ $value = json_encode($value);
191▕ }
192▕
193▕ Assert::assertTrue(
194▕ $state == $value,
195▕ message: "Failed asserting that a table column with name [{$name}] has value of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
196▕ );
197▕

1 vendor\filament\tables\src\Testing\TestsColumns.php:193
2 vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:123
FAILED Tests\Feature\Filament\CategoryResource\ListTest > `Category Table` it has functioning visibility toggle column
Failed asserting that a table column with name [is_active] has value of [] for record [11] on the [App\Filament\Resources\CategoryResource\Pages\ListCategories] component.
Failed asserting that false is true.

at vendor\filament\tables\src\Testing\TestsColumns.php:193
189▕ if (is_array($value)) {
190▕ $value = json_encode($value);
191▕ }
192▕
193▕ Assert::assertTrue(
194▕ $state == $value,
195▕ message: "Failed asserting that a table column with name [{$name}] has value of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
196▕ );
197▕

1 vendor\filament\tables\src\Testing\TestsColumns.php:193
2 vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:123
awcodes
awcodes2mo ago
Is ‘is_active’ an action?
Rolland
Rolland2mo ago
i would assume so, cause its a ToggleColumn.
awcodes
awcodes2mo ago
I don’t think it’s an action. Especially when the action has the same name as a record field. I could be wrong though.
Rolland
Rolland2mo ago
hmm. i think im going to skip this testing.. thank you for trying 😄
Want results from more Discord servers?
Add your server