diff --git a/tests/src/Forms/StateTest.php b/tests/src/Forms/StateTest.php index 51a9b64bcc..64a28815d3 100644 --- a/tests/src/Forms/StateTest.php +++ b/tests/src/Forms/StateTest.php @@ -511,6 +511,29 @@ test('hidden components are excluded from state dehydration except if they are m ->dehydrateState()->not()->toBe([]); }); +test('hidden components are excluded from state dehydration even if their parent component has a state path', function () { + $container = ComponentContainer::make(Livewire::make()) + ->statePath('data') + ->components([ + (new Component) + ->statePath('nested') + ->schema([ + (new Component) + ->statePath(Str::random()) + ->default(Str::random()) + ->hidden(), + ]), + ]) + ->fill(); + + expect($container) + ->dehydrateState()->toBe([ + 'data' => [ + 'nested' => [], + ], + ]); +}); + test('disabled components are excluded from state dehydration', function () { $container = ComponentContainer::make(Livewire::make()) ->statePath('data') @@ -709,46 +732,3 @@ test('parent sibling state can be retrieved absolutely from another component', expect($placeholder) ->getContent()->toBe($state); }); - -test( - 'conditionally hidden and non-dehydrated field within a section (with state path) is incorrectly dehydrated when hidden', - function () { - $container = ComponentContainer::make(Livewire::make()) - ->components([ - Section::make('User Information') - ->statePath('data') - ->schema([ - Radio::make('show_input') - ->label('Control Input Visibility') - ->options([ - 'show' => 'Show', - 'hide' => 'Hide', - ]) - ->live(), - - TextInput::make('name') - ->label('Conditional Name') - ->hidden(fn (Get $get): bool => $get('show_input') === 'hide' || $get('show_input') === null) - ->dehydrated(fn (Get $get): bool => $get('show_input') === 'show'), - ]), - ]) - ->fill([ - 'data' => [ - 'show_input' => 'hide', - 'name' => 'lorem ipsum', - ], - ]); - - $dehydratedState = $container->dehydrateState(); - - // Assert: Expect 'name' field NOT to be present in dehydrated state when 'show_input' is 'hide' - // This assertion is designed to FAIL due to the bug, thus documenting it. - expect($dehydratedState) - ->toBe([ - 'data' => [ - 'show_input' => 'hide', - // 'name' field with 'lorem ipsum' should NOT be here if the bug was fixed. - ], - ]); - } -);