FilamentF
Filament2y ago
Ron

How to test Header/Footer Actions in a Section Form Component

callFormComponentAction fails with error "Call to a member function getKey() on null" when attempting to test calling a section header action.

Can callFormComponentAction() be used to test Header/Footer actions on Form Sections.

Test Code:
it('can toggle form edit', function () {
    $order = $this->getOrders(1);

    // Arrange
    livewire(OrderRentalHistory::class, ['record' => $order->id])
        ->assertFormFieldIsDisabled('address')
        ->callFormComponentAction('rental-history', 'edit-form')
        ->assertFormFieldIsEnabled('address');

});

Form Code:
Section::make('Rental History')
                ->key('rental-history')
                ->headerActions([
                    Action::make('edit-form')
                        ->label('Edit')
                        ->button()
                        ->icon('mdi-pencil')
                        ->action(fn (Get $get, Set $set) => $set('form-editable', ! $get('form-editable'))),
                ])
                ->schema([
                    Hidden::make('form-editable')
                        ->live(),
                    TextInput::make('address')
                        ->prefixIcon('mdi-map-marker')
                        ->disabled(fn (Get $get) => ! $get('form-editable')),

                ]),
Was this page helpful?