Testing page footer actions in v4

I'm attempting to call a page footer action in a test for a resource page. Typically, in an EditRecord page for example, we would have these footer actions:
protected function getFormActions(): array
{
return [
$this->getSaveFormAction(), // Uses `->submit('save')` or `->action(...)`
$this->getCancelFormAction(), // Uses an Alpine click handler
];
}
protected function getFormActions(): array
{
return [
$this->getSaveFormAction(), // Uses `->submit('save')` or `->action(...)`
$this->getCancelFormAction(), // Uses an Alpine click handler
];
}
One essentially fires the public save() function through wire:submit and the other uses JS (and doesn't really need testing). For those that call public functions, typically one can test by using ->call(…) in the test, bypassing having to mount the action, etc. For header actions, ->callAction(TestAction::make('header_action')) works because it's at the top level of the component, but footer actions cannot be resolved and called by the same function. Consider a custom footer action:
protected function getFormActions(): array
{
return [
// ...

Action::make('footer_action')
->action(function () {
// ...
}),
];
}
protected function getFormActions(): array
{
return [
// ...

Action::make('footer_action')
->action(function () {
// ...
}),
];
}
Attempting ->callAction(TestAction::make('footer_action')) leads to a failed assertion that the footer action is visible. The composition of pages has changed in v4 with schemas, Form components, EmbeddedSchemas etc., and it's quite confusing to know exactly which combinations of $component and $schema parameters to use with ->schemaComponent($component, $schema) on TestAction. It would seem that now, these actions have become children of an Actions component in the footer of a Form, which eventually forms part of the content Schema. What function calls should I make on the Livewire Testable to target these (form) footer actions?
4 Replies
mrkbingham
mrkbingham4w ago
@Jonathan Christiani did you make any progress on this one? I'm hitting the same issue
Jonathan Christiani
No I think it’s a bug from filament
mrkbingham
mrkbingham2w ago
Okay @Jonathan Christiani I've got a proposal over here to resolve this issue: https://github.com/filamentphp/filament/pull/17875
GitHub
[4.x] Add key to form actions content component for use with testin...
Description This is a proposal to add an explicit key to the default form action components. If there is any modification to the behavior of the default actions in the form, such as a modal to conf...
mrkbingham
mrkbingham2w ago
But, for now, here's a workaround I'm using. By adding this to your resource page, it adds a key to the action group for the form:
/**
* TODO: Remove this override - this is only needed because of a bug in Filament v4 wherein you cannot access the form actions.
*
* @return Component
*/
public function getFormActionsContentComponent(): Component
{
return Actions::make($this->getFormActions())
->alignment($this->getFormActionsAlignment())
->fullWidth($this->hasFullWidthFormActions())
->sticky($this->areFormActionsSticky())
->key('form-actions-content-component');
}
/**
* TODO: Remove this override - this is only needed because of a bug in Filament v4 wherein you cannot access the form actions.
*
* @return Component
*/
public function getFormActionsContentComponent(): Component
{
return Actions::make($this->getFormActions())
->alignment($this->getFormActionsAlignment())
->fullWidth($this->hasFullWidthFormActions())
->sticky($this->areFormActionsSticky())
->key('form-actions-content-component');
}
Which then makes this TestAction work in your tests: TestAction::make('save')->schemaComponent('form-actions-content-component', 'content')

Did you find this page helpful?