Calling an action in a test
You can call an action by passing its name or class tocallAction():
Testing table actions
To test table actions, you can use aTestAction object with the table() method. This object receives the name of the action you want to test, and replaces the name of the action in any testing method you want to use. For example:
Testing table header actions
To test a header action, you can use thetable() method without passing in a specific record to test with:
Testing table bulk actions
To test a bulk action, first callselectTableRecords() and pass in any records you want to select. Then, use the TestAction’s bulk() method to specify the action you want to test. For example:
Testing actions in a schema
If an action belongs to a component in a resource’s infolist, for example, if it is in thebelowContent() method of an infolist entry, you can use the TestAction object with the schemaComponent() method. This object receives the name of the action you want to test and replaces the name of the action in any testing method you want to use. For example:
Testing actions inside another action’s schema / form
If an action belongs to a component in another action’sschema() (or form()), for example, if it is in the belowContent() method of a form field in an action modal, you can use the TestAction object with the schemaComponent() method. This object receives the name of the action you want to test and replaces the name of the action in any testing method you want to use. You should pass an array of TestAction objects in order, for example:
Testing resource getFormActions()
For details on how to test custom actions in the getFormActions() of a resource page, refer to the Testing resources documentation.
Testing forms in action modals
To pass an array of data into an action, use thedata parameter:
fillForm():
Testing validation errors in an action modal’s form
assertHasNoFormErrors() is used to assert that no validation errors occurred when submitting the action form.
To check if a validation error has occurred with the data, use assertHasFormErrors(), similar to assertHasErrors() in Livewire:
assertSchemaStateSet() method:
Testing the content of an action modal
To assert the content of a modal, you should first mount the action (rather than call it which closes the modal). You can then useassertMountedActionModalSee(), assertMountedActionModalDontSee(), assertMountedActionModalSeeHtml() or assertMountedActionModalDontSeeHtml() to assert the modal contains the content that you expect it to:
Testing the existence of an action
To ensure that an action exists or doesn’t, you can use theassertActionExists() or assertActionDoesNotExist() method:
Testing the visibility of an action
To ensure an action is hidden or visible for a user, you can use theassertActionHidden() or assertActionVisible() methods:
Testing disabled actions
To ensure an action is enabled or disabled for a user, you can use theassertActionEnabled() or assertActionDisabled() methods:
assertActionListInOrder():
assertActionHidden() method:
Testing the label of an action
To ensure an action has the correct label, you can useassertActionHasLabel() and assertActionDoesNotHaveLabel():
Testing the icon of an action
To ensure an action’s button is showing the correct icon, you can useassertActionHasIcon() or assertActionDoesNotHaveIcon():
Testing the color of an action
To ensure that an action’s button is displaying the right color, you can useassertActionHasColor() or assertActionDoesNotHaveColor():
Testing the URL of an action
To ensure an action has the correct URL, you can useassertActionHasUrl(), assertActionDoesNotHaveUrl(), assertActionShouldOpenUrlInNewTab(), and assertActionShouldNotOpenUrlInNewTab():
Testing action arguments
To test action arguments, you can use aTestAction object with the arguments() method. This object receives the name of the action you want to test and replaces the name of the action in any testing method you want to use. For example:
Testing if an action has been halted
To check if an action has been halted, you can useassertActionHalted():
Using action class names in tests
Filament includes a host of prebuilt actions such asCreateAction, EditAction and DeleteAction, and you can use these class names in your tests instead of action names, for example:
make() method, the name of your action is not discoverable by Filament unless it runs the make() method, which is not efficient. To use your own action class names in your tests, you can add an #[ActionName] attribute to your action class, which Filament can use to discover the name of your action. The name passed to the #[ActionName] attribute should be the same as the name of the action you would normally use in your tests. For example:
Action class, you can add a getDefaultName() static method to the class, which will be used to discover the name of the action. It also allows users to omit the name of the action from the make() method when instantiating it. For example: