© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•15mo ago•
2 replies
arnaudsf

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!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Open action modals inside a modal
FilamentFFilament / ❓┊help
3y ago
Filament v4 action modal, inside action modal
FilamentFFilament / ❓┊help
5mo ago
fileUpload inside Action Modal
FilamentFFilament / ❓┊help
3y ago
Delete action inside modal - alignment
FilamentFFilament / ❓┊help
4mo ago