hint action tests

hey i got a hint action setup on a simple Select that opens a Form inside a modal.
Select::make('chooseProfile') ->hintAction( Action::make('createNewProfile')->label('newProfileAction')->form([ Grid::make()->schema([ TextInput::make('newProfile') ->required() ]) ]) )
how do i call that nested action when testing the livewire component in order to write tests for the form displayed in the modal? when i try using call action i get:
Failed asserting that an action with name [createNewProfile] exists on the [App\Livewire\ProfileForm] page.
15 Replies
bwurtz999
bwurtz9995mo ago
@AncientFriend Were you ever able to figure this out?
bwurtz999
bwurtz9995mo ago
@awcodes thank you I tried following those docs but I kept getting a weird error about infolists (https://discord.com/channels/883083792112300104/1260726161785356438) I'm guessing the issue is becuse I'm trying to test a hint action within a relation manager
awcodes
awcodes5mo ago
Shouldn’t matter. Can sure more code than just the action? You might need to mount the form action too. Before calling it. Seems weird to be testing these together though. In my mind it would be a test to call the table action. But a separate test for actions in the create / edit for the related form. If that makes sense. Ie, if the create / edit form for the related record works then you can expect it to work when loaded by the table action too.
bwurtz999
bwurtz9995mo ago
I'm not sure I understand what you mean. How could I test this hint action on it's own? The hint action is only available through the EditAction form. Don't I have to call the table action before running this test? I just tried using
->callTableAction(EditAction::class, $item)
->mountFormComponentAction('category_id', 'createCategory')
->callFormComponentAction(
->callTableAction(EditAction::class, $item)
->mountFormComponentAction('category_id', 'createCategory')
->callFormComponentAction(
but got the same error about an Infolist I appreciate your responses and any further insight you can provide. Thank you!
awcodes
awcodes5mo ago
I’m sure there’s a proper way to do it, I’ll get back to you. I’m away from the computer right now though. Do you have a resource for category or is it a simple resource?
bwurtz999
bwurtz9995mo ago
I actually don't have a resource for it at all. The code examples I've showed are simplified. What I'm actually trying to modify are EventCategorys. The organization has Categorys that are used to create all the EventCategory models for an event. This way the EventCategory can be renamed or modified for a specific event without changing it for all events. The EventCategory models are created initially in protected function afterCreate() of the CreateEvent class after the event has been saved. Do you think I need to create a resource for EventCategory in order for this testing to work?
LeandroFerreira
LeandroFerreira5mo ago
Did you add a form to a custom page? Would you like to test the createNewProfile action? Is it?
bwurtz999
bwurtz9995mo ago
This is within the EditAction of a table record within a relation manager It is not a custom page What is createNewProfile?
LeandroFerreira
LeandroFerreira5mo ago
could you share some code you are using? sorry, this was the main question from AncientFriend
bwurtz999
bwurtz9995mo ago
/**
* create a new menu category for this flight
*/
it('can create a new flight menu category', function () {
$flight = Flight::where([
['airline_id', auth()->user()->team_id],
['depart_time', '>=', now()],
])
->inRandomOrder()
->first();

$teamProfileItem = TeamProfileSelectedItem::where('flight_id', $flight->id)
->inRandomOrder()
->first();

$name = Str::random(10);

$paymentCodeType = PaymentCodeType::where('airline_id', auth()->user()->team_id)
->inRandomOrder()
->first();

livewire(TeamProfileItemsRelationManager::class, [
'ownerRecord' => $flight,
'pageClass' => EditFlight::class,
])
->callTableAction(EditAction::class, $teamProfileItem)
->mountFormComponentAction('flight_payment_code_category_id', 'createFlightCategory')
->callFormComponentAction('flight_payment_code_category_id', 'createFlightCategory', data: [
'name' => $name,
'payment_code_type_id' => $paymentCodeType->id,
])
->assertHasNoFormComponentActionErrors();
})->group('development');
/**
* create a new menu category for this flight
*/
it('can create a new flight menu category', function () {
$flight = Flight::where([
['airline_id', auth()->user()->team_id],
['depart_time', '>=', now()],
])
->inRandomOrder()
->first();

$teamProfileItem = TeamProfileSelectedItem::where('flight_id', $flight->id)
->inRandomOrder()
->first();

$name = Str::random(10);

$paymentCodeType = PaymentCodeType::where('airline_id', auth()->user()->team_id)
->inRandomOrder()
->first();

livewire(TeamProfileItemsRelationManager::class, [
'ownerRecord' => $flight,
'pageClass' => EditFlight::class,
])
->callTableAction(EditAction::class, $teamProfileItem)
->mountFormComponentAction('flight_payment_code_category_id', 'createFlightCategory')
->callFormComponentAction('flight_payment_code_category_id', 'createFlightCategory', data: [
'name' => $name,
'payment_code_type_id' => $paymentCodeType->id,
])
->assertHasNoFormComponentActionErrors();
})->group('development');
Select::make('flight_payment_code_category_id')
->hintAction(
ActionsAction::make('createFlightCategory')
->label('Create New Category')
->form([
TextInput::make('name')
->required()
->columnSpanFull(),
Select::make('payment_code_type_id')
->label('Payment Code Type')
->required()
->options(PaymentCodeType::pluck('name', 'id')),
Toggle::make('menu_section')
->label('Menu Section')
->inline(false)
->hint('Should this category have it\'s own section in the menu export.'),
Textarea::make('notes'),

])
->action(function ($data, $set, $livewire) {
// truncated to fit in one post...
})
)
->options(function ($livewire) {
return FlightPaymentCodeCategory::where('flight_id', $livewire->ownerRecord->id)
->pluck('name', 'id');
}),
Select::make('flight_payment_code_category_id')
->hintAction(
ActionsAction::make('createFlightCategory')
->label('Create New Category')
->form([
TextInput::make('name')
->required()
->columnSpanFull(),
Select::make('payment_code_type_id')
->label('Payment Code Type')
->required()
->options(PaymentCodeType::pluck('name', 'id')),
Toggle::make('menu_section')
->label('Menu Section')
->inline(false)
->hint('Should this category have it\'s own section in the menu export.'),
Textarea::make('notes'),

])
->action(function ($data, $set, $livewire) {
// truncated to fit in one post...
})
)
->options(function ($livewire) {
return FlightPaymentCodeCategory::where('flight_id', $livewire->ownerRecord->id)
->pluck('name', 'id');
}),
// error message
Tests\Feature\DeltaOwner\KitchenMenuRelationManager > it can create a new flight menu category TypeError
App\Filament\Resources\FlightResource\RelationManagers\TeamProfileItemsRelationManager::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/robertwurtz/Sites/flylogik/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 56

at app/Filament/Resources/FlightResource/RelationManagers/TeamProfileItemsRelationManager.php:48
44▕ protected static ?string $modelLabel = 'Item for This Specific Flight';
45▕
46▕ protected static bool $isLazy = false;
47▕
➜ 48▕ public function form(Form $form): Form
49▕ {
50▕ return $form
51▕ ->schema([
52▕ Select::make('payment_code_id')

1 app/Filament/Resources/FlightResource/RelationManagers/TeamProfileItemsRelationManager.php:48
+11 vendor frames
13 tests/Feature/DeltaOwner/KitchenMenuRelationManager.php:176
// error message
Tests\Feature\DeltaOwner\KitchenMenuRelationManager > it can create a new flight menu category TypeError
App\Filament\Resources\FlightResource\RelationManagers\TeamProfileItemsRelationManager::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/robertwurtz/Sites/flylogik/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 56

at app/Filament/Resources/FlightResource/RelationManagers/TeamProfileItemsRelationManager.php:48
44▕ protected static ?string $modelLabel = 'Item for This Specific Flight';
45▕
46▕ protected static bool $isLazy = false;
47▕
➜ 48▕ public function form(Form $form): Form
49▕ {
50▕ return $form
51▕ ->schema([
52▕ Select::make('payment_code_id')

1 app/Filament/Resources/FlightResource/RelationManagers/TeamProfileItemsRelationManager.php:48
+11 vendor frames
13 tests/Feature/DeltaOwner/KitchenMenuRelationManager.php:176
line 48 is just public function form(Form $form): Form from the relation manager so I feel like I don't have a whole lot to go on When I use the form as a user it works as expected. So I can't figure out why I'm getting an error about an Infolist when I try to run a test
LeandroFerreira
LeandroFerreira5mo ago
try this
livewire(TeamProfileItemsRelationManager::class, [
'ownerRecord' => $flight,
'pageClass' => EditFlight::class,
])
->mountTableAction(EditAction::class, $teamProfileItem)
->call('mountFormComponentAction',
component:'mountedTableActionsData.0.flight_payment_code_category_id',
name: 'createFlightCategory'
)
->callMountedAction()
livewire(TeamProfileItemsRelationManager::class, [
'ownerRecord' => $flight,
'pageClass' => EditFlight::class,
])
->mountTableAction(EditAction::class, $teamProfileItem)
->call('mountFormComponentAction',
component:'mountedTableActionsData.0.flight_payment_code_category_id',
name: 'createFlightCategory'
)
->callMountedAction()
bwurtz999
bwurtz9995mo ago
Yup this worked! Thank you! How do I fill the form with data? Sorry to keep asking so many questions - when I search for mountFormComponentAction in the Filament docs I get no results. Am I missing this somewhere?
LeandroFerreira
LeandroFerreira5mo ago
try ->set('mountedFormComponentActionsData.0.your_field', 'value') you sometimes need to dive into the source code to achieve what you want.. @AncientFriend share the whole code
bwurtz999
bwurtz9995mo ago
Here is the full solution:
livewire(TeamProfileItemsRelationManager::class, [
'ownerRecord' => $flight,
'pageClass' => EditFlight::class,
])
->mountTableAction(EditAction::class, $teamProfileItem)
->call('mountFormComponentAction',
component:'mountedTableActionsData.0.flight_payment_code_category_id',
name: 'createFlightCategory',
)
->callMountedAction()
->set('mountedFormComponentActionsData.0.name', $name)
->set('mountedFormComponentActionsData.0.payment_code_type_id', $paymentCodeType->id)
->callMountedFormComponentAction()
->assertHasNoFormComponentActionErrors();
livewire(TeamProfileItemsRelationManager::class, [
'ownerRecord' => $flight,
'pageClass' => EditFlight::class,
])
->mountTableAction(EditAction::class, $teamProfileItem)
->call('mountFormComponentAction',
component:'mountedTableActionsData.0.flight_payment_code_category_id',
name: 'createFlightCategory',
)
->callMountedAction()
->set('mountedFormComponentActionsData.0.name', $name)
->set('mountedFormComponentActionsData.0.payment_code_type_id', $paymentCodeType->id)
->callMountedFormComponentAction()
->assertHasNoFormComponentActionErrors();
Want results from more Discord servers?
Add your server