Testing: How to call a table action within a relation manager?
Hi, I have this Action within my
I'm looking to write a test for this custom action:
However, I'm getting the error:
Any ideas here on how to call
CountriesRelationManager
:
// CountriesRelationManager.php
public function table(Table $table): Table
{
return $table
// ...
->actions([
// ...
Action::make('moveUp')
->action(function (Action $action) {
$action->getRecord()->moveOrderUp();
}),
]);
// ...
}
// CountriesRelationManager.php
public function table(Table $table): Table
{
return $table
// ...
->actions([
// ...
Action::make('moveUp')
->action(function (Action $action) {
$action->getRecord()->moveOrderUp();
}),
]);
// ...
}
it('allows moves sort order up on assicated children', function () {
$continent = Continent::factory()
->hasCountries(2)
->create();
livewire(CountriesRelationManager::class, [
'pageClass' => EditContinent::class,
'ownerRecord' => $continent,
])
->callTableColumnAction('moveUp', $continent->countries->last()->id);
expect($continent->countries->first()->fresh()->sort_order)->toBe(2);
expect($continent->countries->last()->fresh()->sort_order)->toBe(1);
});
it('allows moves sort order up on assicated children', function () {
$continent = Continent::factory()
->hasCountries(2)
->create();
livewire(CountriesRelationManager::class, [
'pageClass' => EditContinent::class,
'ownerRecord' => $continent,
])
->callTableColumnAction('moveUp', $continent->countries->last()->id);
expect($continent->countries->first()->fresh()->sort_order)->toBe(2);
expect($continent->countries->last()->fresh()->sort_order)->toBe(1);
});
Failed asserting that a table column with name [moveUp] exists on the [App\Filament\Resources\ContinentResource\RelationManagers\CountriesRelationManager] component.
Failed asserting that null is an instance of class Filament\Tables\Columns\Column.
Failed asserting that a table column with name [moveUp] exists on the [App\Filament\Resources\ContinentResource\RelationManagers\CountriesRelationManager] component.
Failed asserting that null is an instance of class Filament\Tables\Columns\Column.
moveUp
? Much appreciated!0 Replies