mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #13519 from filamentphp/fix/testing-grouped-action-visiblity-with-group-auth
fix: Testing grouped action visibility with grouped authorization
This commit is contained in:
@@ -19,4 +19,21 @@ trait BelongsToGroup
|
||||
{
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
public function getRootGroup(): ?ActionGroup
|
||||
{
|
||||
$group = $this->getGroup();
|
||||
|
||||
while ($group) {
|
||||
$parentGroup = $group->getGroup();
|
||||
|
||||
if (! $parentGroup) {
|
||||
break;
|
||||
}
|
||||
|
||||
$group = $parentGroup;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ trait HasActions
|
||||
return null;
|
||||
}
|
||||
|
||||
if (($actionGroup = $action->getGroup()) instanceof HasRecord) {
|
||||
if (($actionGroup = $action->getRootGroup()) instanceof HasRecord) {
|
||||
$actionGroup->record($mountedRecord);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Filament\Tables\Testing;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Contracts\HasRecord;
|
||||
use Filament\Actions\Testing\TestsActions as BaseTestsActions;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
@@ -277,6 +278,10 @@ class TestsActions
|
||||
$action = $this->instance()->getTable()->getAction($name);
|
||||
$action->record($record);
|
||||
|
||||
if (($actionGroup = $action->getRootGroup()) instanceof HasRecord) {
|
||||
$actionGroup->record($record);
|
||||
}
|
||||
|
||||
Assert::assertFalse(
|
||||
$action->isHidden(),
|
||||
message: filled($record) ?
|
||||
@@ -309,6 +314,10 @@ class TestsActions
|
||||
$action = $this->instance()->getTable()->getAction($name);
|
||||
$action->record($record);
|
||||
|
||||
if (($actionGroup = $action->getRootGroup()) instanceof HasRecord) {
|
||||
$actionGroup->record($record);
|
||||
}
|
||||
|
||||
$livewireClass = $this->instance()::class;
|
||||
$prettyName = implode(' > ', $name);
|
||||
|
||||
@@ -348,6 +357,10 @@ class TestsActions
|
||||
$action = $this->instance()->getTable()->getAction($name);
|
||||
$action->record($record);
|
||||
|
||||
if (($actionGroup = $action->getRootGroup()) instanceof HasRecord) {
|
||||
$actionGroup->record($record);
|
||||
}
|
||||
|
||||
Assert::assertFalse(
|
||||
$action->isDisabled(),
|
||||
message: filled($record) ?
|
||||
@@ -380,6 +393,10 @@ class TestsActions
|
||||
$action = $this->instance()->getTable()->getAction($name);
|
||||
$action->record($record);
|
||||
|
||||
if (($actionGroup = $action->getRootGroup()) instanceof HasRecord) {
|
||||
$actionGroup->record($record);
|
||||
}
|
||||
|
||||
$livewireClass = $this->instance()::class;
|
||||
$prettyName = implode(' > ', $name);
|
||||
|
||||
|
||||
@@ -76,9 +76,13 @@ it('can call an action and halt', function () {
|
||||
});
|
||||
|
||||
it('can hide an action', function () {
|
||||
$post = Post::factory()->create();
|
||||
|
||||
livewire(PostsTable::class)
|
||||
->assertTableActionVisible('visible')
|
||||
->assertTableActionHidden('hidden');
|
||||
->assertTableActionHidden('hidden')
|
||||
->assertTableActionVisible('groupedWithVisibleGroupCondition', $post)
|
||||
->assertTableActionHidden('groupedWithHiddenGroupCondition', $post);
|
||||
});
|
||||
|
||||
it('can disable an action', function () {
|
||||
|
||||
@@ -11,6 +11,7 @@ use Filament\Tables\Table;
|
||||
use Filament\Tests\Models\Post;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Livewire\Component;
|
||||
|
||||
@@ -129,6 +130,12 @@ class PostsTable extends Component implements HasForms, Tables\Contracts\HasTabl
|
||||
Tables\Actions\Action::make('enabled'),
|
||||
Tables\Actions\Action::make('disabled')
|
||||
->disabled(),
|
||||
Tables\Actions\ActionGroup::make([
|
||||
Tables\Actions\Action::make('groupedWithVisibleGroupCondition'),
|
||||
])->visible(fn (?Model $record): bool => $record !== null),
|
||||
Tables\Actions\ActionGroup::make([
|
||||
Tables\Actions\Action::make('groupedWithHiddenGroupCondition'),
|
||||
])->hidden(fn (?Model $record): bool => $record !== null),
|
||||
Tables\Actions\Action::make('hasIcon')
|
||||
->icon('heroicon-m-pencil-square'),
|
||||
Tables\Actions\Action::make('hasLabel')
|
||||
|
||||
Reference in New Issue
Block a user