This commit is contained in:
Ralph J. Smit
2025-02-10 19:04:25 +01:00
parent 26d99a5be2
commit 5ecfab6a93
3 changed files with 102 additions and 2 deletions
@@ -45,11 +45,12 @@ class ComponentContainer extends ViewComponent
protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
{
return match ($parameterName) {
'record' => [$this->getRecord()],
'livewire' => [$this->getLivewire()],
'record' => [$this->getRecord()],
default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
};
}
/**
* @return array<mixed>
*/
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Filament\Tests\Infolists\Fixtures;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Infolists\Concerns\InteractsWithInfolists;
use Filament\Infolists\Contracts\HasInfolists;
use Livewire\Component;
class Livewire extends Component implements HasForms, HasInfolists
{
use InteractsWithForms;
use InteractsWithInfolists;
public $data;
public static function make(): static
{
return new static;
}
public function data($data): static
{
$this->data = $data;
return $this;
}
public function getData()
{
return $this->data;
}
}
+65
View File
@@ -0,0 +1,65 @@
<?php
use Filament\Infolists;
use Filament\Tests\Infolists\Fixtures\Livewire;
use Filament\Tests\TestCase;
use function Filament\Tests\livewire;
uses(TestCase::class);
it('can inject the correct `$livewire` for infolists outside a panel', function () {
livewire(TestComponentWithInfolist::class)
->assertOk()
->assertSee('First Entry Label')
->assertSee('First Entry State')
->assertSee('Second Entry Label')
->assertSee('Second Entry State');
});
class TestComponentWithInfolist extends Livewire
{
public function mount(): void
{
$this->data([
'first_entry' => 'First Entry State',
'second_entry' => 'Second Entry State',
]);
}
public function infolist(Infolists\Infolist $infolist): Infolists\Infolist
{
return $infolist
->state($this->data)
->schema(function (TestComponentWithInfolist $livewire) {
expect($livewire)->toBe($this);
return [
Infolists\Components\TextEntry::make('first_entry')
->label('First Entry Label'),
];
});
}
public function infolistWithCustomName(Infolists\Infolist $infolist): Infolists\Infolist
{
return $infolist
->state($this->data)
->schema(function (TestComponentWithInfolist $livewire) {
expect($livewire)->toBe($this);
return [
Infolists\Components\TextEntry::make('second_entry')
->label('Second Entry Label'),
];
});
}
public function render(): string
{
return <<<'BLADE'
{{ $this->infolist }}
{{ $this->infolistWithCustomName }}
BLADE;
}
}