KarlBoosterBär
KarlBoosterBär
FFilament
Created by KarlBoosterBär on 9/17/2024 in #❓┊help
Test Form Component Action
I have got a second test to assert the validation errors which passes too:
it('has form errors on create', function() {
livewire(ListLocationTariffs::class, ['record' => $this->location->uuid])
->callAction('createTariff')
->setActionData([])
->callMountedAction()
->assertHasErrors(['mountedActionsData.0.name' => 'required','mountedActionsData.0.type' => 'required', 'mountedActionsData.0.starts_at' => 'required']);
});
it('has form errors on create', function() {
livewire(ListLocationTariffs::class, ['record' => $this->location->uuid])
->callAction('createTariff')
->setActionData([])
->callMountedAction()
->assertHasErrors(['mountedActionsData.0.name' => 'required','mountedActionsData.0.type' => 'required', 'mountedActionsData.0.starts_at' => 'required']);
});
Now when i add the ->assertFormFieldExists('mountedActionsData.0.name') function the test fails with this error message: "Failed asserting that a field with the name [data.mountedActionsData.0.name] exists on the form with the name [form] on the [App\Filament\Customer\Resources\LocationResource\Pages\ListLocationTariffs] component." I don't know if my test overall is correct and how i can test the form fields. Would be really nice if someone could help me with this.
5 replies
FFilament
Created by KarlBoosterBär on 9/17/2024 in #❓┊help
Test Form Component Action
The Form looks like this:
public static function form(Form $form): Form
{

return $form
->schema([

/**
* GENERAL SECTION
*/
Section::make()
->heading('Allgemein')
->description('Geben Sie hier die Informationen ein, die zur Auffindbarkeit des Tarifs und zur korrekten Zuordnung benötigt werden.')
->columns(2)
->schema([

/**
* TYPE FIELD
*/
Select::make('type')
->label('Medium')
->columnSpan(1)
->options(MediumType::class)
->searchable()
->required()
->live()
->disabled(function (string $operation): bool {
return $operation !== 'create';
}),

/**
* NAME FIELD
*/
TextInput::make('name')
->label('Name')
->placeholder('Stromtarif')
->columnSpan(1)
->required()
->autocomplete(false)
->minLength(3)
->maxLength(255),

/**
* DESCRIPTION FIELD
*/
TextInput::make('description')
->label('Beschreibung')
->placeholder('Wird vssl. zum Ende des Jahres gekündigt')
->columnSpan(2)
->nullable(),
...
public static function form(Form $form): Form
{

return $form
->schema([

/**
* GENERAL SECTION
*/
Section::make()
->heading('Allgemein')
->description('Geben Sie hier die Informationen ein, die zur Auffindbarkeit des Tarifs und zur korrekten Zuordnung benötigt werden.')
->columns(2)
->schema([

/**
* TYPE FIELD
*/
Select::make('type')
->label('Medium')
->columnSpan(1)
->options(MediumType::class)
->searchable()
->required()
->live()
->disabled(function (string $operation): bool {
return $operation !== 'create';
}),

/**
* NAME FIELD
*/
TextInput::make('name')
->label('Name')
->placeholder('Stromtarif')
->columnSpan(1)
->required()
->autocomplete(false)
->minLength(3)
->maxLength(255),

/**
* DESCRIPTION FIELD
*/
TextInput::make('description')
->label('Beschreibung')
->placeholder('Wird vssl. zum Ende des Jahres gekündigt')
->columnSpan(2)
->nullable(),
...
5 replies