#Creating a test for ToggleColumn

13 messages · Page 1 of 1 (latest)

normal token
#
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

normal token
#

bump

normal token
#

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');
normal token
#

bump

normal token
#

bump

grim garden
#

What exactly are you seeing in your tests?

#

Ie what are the failing outputs?

normal token
#

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
grim garden
#

Is ‘is_active’ an action?

normal token
#

i would assume so, cause its a ToggleColumn.

grim garden
#

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.