From 5ecfab6a931358ebac61efa4604fe09b4396ab63 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Mon, 10 Feb 2025 19:04:25 +0100 Subject: [PATCH] WIP --- packages/infolists/src/ComponentContainer.php | 5 +- tests/src/Infolists/Fixtures/Livewire.php | 34 ++++++++++ tests/src/Infolists/LivewireTest.php | 65 +++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 tests/src/Infolists/Fixtures/Livewire.php create mode 100644 tests/src/Infolists/LivewireTest.php diff --git a/packages/infolists/src/ComponentContainer.php b/packages/infolists/src/ComponentContainer.php index 1e4931b176..8d451a8cbd 100644 --- a/packages/infolists/src/ComponentContainer.php +++ b/packages/infolists/src/ComponentContainer.php @@ -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 */ diff --git a/tests/src/Infolists/Fixtures/Livewire.php b/tests/src/Infolists/Fixtures/Livewire.php new file mode 100644 index 0000000000..093acef424 --- /dev/null +++ b/tests/src/Infolists/Fixtures/Livewire.php @@ -0,0 +1,34 @@ +data = $data; + + return $this; + } + + public function getData() + { + return $this->data; + } +} diff --git a/tests/src/Infolists/LivewireTest.php b/tests/src/Infolists/LivewireTest.php new file mode 100644 index 0000000000..9b481daddf --- /dev/null +++ b/tests/src/Infolists/LivewireTest.php @@ -0,0 +1,65 @@ +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; + } +}