arnaudsf
arnaudsf
FFilament
Created by arnaudsf on 1/14/2025 in #❓┊help
Submit deferred filters in a modal on enter key press
Hi, does anyone know how to submit a deferred filter form located inside a modal when pressing the Enter key on the keyboard?
5 replies
FFilament
Created by arnaudsf on 12/9/2024 in #❓┊help
test select action inside modal
In my LeadResource, on the ListRecord page, I have a "Create" action that opens a form modal to create a new lead. The form includes a select field with an action to create a new customer on the fly. When the user creates a customer, the customer ID should be associated with the new lead. I'm trying to write a test to verify: - 1/ The new customer is created successfully. - 2/ The ID of the newly created customer matches the one associated with the newly created lead. Here’s what I have so far for testing the lead creation:
it('can create a record', function () {
$lead = $this->organization->leads()->get()->random();

$customer = $lead->customers()->with('contacts')->first();

livewire(ListLeads::class)
->callAction('create', data: [
'owner_id' => $lead->owner->id,
'status_id' => $lead->status_id,
...
])
->assertHasNoActionErrors();
});
it('can create a record', function () {
$lead = $this->organization->leads()->get()->random();

$customer = $lead->customers()->with('contacts')->first();

livewire(ListLeads::class)
->callAction('create', data: [
'owner_id' => $lead->owner->id,
'status_id' => $lead->status_id,
...
])
->assertHasNoActionErrors();
});
Now, I want to test the nested action for creating a customer. I’ve attempted this:
livewire(ListLeads::class)
->callAction('create')
->mountFormComponentAction('mountedActionsData.0.customer_id', 'createCustomer')
->assertFormComponentActionDataSet([
'contact.first_name' => $firstName,
'contact.last_name' => fake()->lastName(),
'contact.zipcode' => fake()->postcode(),
'contact.city' => fake()->city(),
'contact.country' => 'FR',
])
->callMountedFormComponentAction()
->assertHasNoFormComponentActionErrors();
livewire(ListLeads::class)
->callAction('create')
->mountFormComponentAction('mountedActionsData.0.customer_id', 'createCustomer')
->assertFormComponentActionDataSet([
'contact.first_name' => $firstName,
'contact.last_name' => fake()->lastName(),
'contact.zipcode' => fake()->postcode(),
'contact.city' => fake()->city(),
'contact.country' => 'FR',
])
->callMountedFormComponentAction()
->assertHasNoFormComponentActionErrors();
` However, I’m struggling with the following: - 1/ How to properly test the createCustomer action within the context of the "Create" action? - 2/ How to assert that the new customer's ID is correctly associated with the newly created lead? Any suggestions or examples for testing nested actions in Livewire? Thanks in advance for your help!
3 replies