To fill a form with data, pass the data to fillForm():
If you have multiple schemas on a Livewire component, you can specify which form you want to fill using fillForm([...], 'createPostForm').
Testing form field and infolist entry state
To check that a form has data, use assertSchemaStateSet():
If you have multiple schemas on a Livewire component, you can specify which schema you want to check using assertSchemaStateSet([...], 'createPostForm').
You may also find it useful to pass a function to the assertSchemaStateSet() method, which allows you to access the form $state and perform additional assertions:
You can return an array from the function if you want Filament to continue to assert the schema state after the function has been run.
Use assertHasFormErrors() to ensure that data is properly validated in a form:
And assertHasNoFormErrors() to ensure there are no validation errors:
If you have multiple schemas on a Livewire component, you can pass the name of a specific form as the second parameter like assertHasFormErrors(['title' => 'required'], 'createPostForm') or assertHasNoFormErrors([], 'createPostForm').
To check that a Livewire component has a form, use assertSchemaExists('form'):
If you have multiple schemas on a Livewire component, you can pass the name of a specific form like assertSchemaExists('createPostForm').
To ensure that a form has a given field, pass the field name to assertFormFieldExists():
You may pass a function as an additional argument to assert that a field passes a given “truth test”. This is useful for asserting that a field has a specific configuration:
To assert that a form does not have a given field, pass the field name to assertFormFieldDoesNotExist():
If you have multiple schemas on a Livewire component, you can specify which form you want to check for the existence of the field like assertFormFieldExists('title', 'createPostForm').
To ensure that a field is visible, pass the name to assertFormFieldVisible():
Or to ensure that a field is hidden you can pass the name to assertFormFieldHidden():
For both assertFormFieldHidden() and assertFormFieldVisible() you can pass the name of a specific form the field belongs to as the second argument like assertFormFieldHidden('title', 'createPostForm').
To ensure that a field is enabled, pass the name to assertFormFieldEnabled():
Or to ensure that a field is disabled you can pass the name to assertFormFieldDisabled():
For both assertFormFieldEnabled() and assertFormFieldDisabled() you can pass the name of a specific form the field belongs to as the second argument like assertFormFieldEnabled('title', 'createPostForm').
Testing other schema components
If you need to check if a particular schema component exists rather than a field, you may use assertSchemaComponentExists(). As components do not have names, this method uses the key() provided by the developer:
To assert that a schema does not have a given component, pass the component key to assertSchemaComponentDoesNotExist():
To check if the component exists and passes a given truth test, you can pass a function to the checkComponentUsing argument of assertSchemaComponentExists(), returning true or false if the component passes the test or not:
If you want more informative test results, you can embed an assertion within your truth test callback:
Testing the visibility of schema components
To ensure that a schema component is visible, pass the key to assertSchemaComponentVisible():
Or to ensure that a schema component is hidden you can pass the key to assertSchemaComponentHidden():
For both assertSchemaComponentHidden() and assertSchemaComponentVisible() you can pass the name of a specific schema the component belongs to as the second argument like assertSchemaComponentHidden('comments-section', 'createPostForm').
Testing repeaters
Use Repeater::fake() to give repeater items predictable numeric keys instead of UUIDs when asserting their state. Call the returned function after the test to restore normal key generation:
You may also find it useful to test the number of items in a repeater by passing a function to the assertSchemaStateSet() method:
Testing repeater actions
Use callAction() with TestAction::make()->schemaComponent() to call a repeater action and then assert its result.
To interact with an action on a particular repeater item, you need to pass in the item argument with the key of that repeater item. If your repeater is reading from a relationship, you should prefix the ID (key) of the related record with record- to form the key of the repeater item:
Testing builders
Use Builder::fake() to give builder blocks predictable numeric keys instead of UUIDs when asserting their state. Call the returned function after the test to restore normal key generation:
You can also test the number of blocks in a builder by passing a function to assertSchemaStateSet():
Testing wizards
To go to a wizard’s next step, use goToNextWizardStep():
You can also go to the previous step by calling goToPreviousWizardStep():
If you want to go to a specific step, use goToWizardStep(), then the assertWizardCurrentStep method which can ensure you are on the desired step without validation errors from the previous:
If you have multiple schemas on a single Livewire component, any of the wizard test helpers can accept a schema parameter: