Testing modal form in resource relation

I want to test creating an address which is a sub-resource of customers but the form opens in a modal rather than go to a dedicated form page. How can I test this? I've tried the below and this isn't working
public function test_a_new_address_can_be_created(): void
{
$customer = Customer::factory()->create();

$livewire = Livewire::test(
name: AddressesRelationManager::class,
params: [
'ownerRecord' => $customer,
'pageClass' => EditCustomer::class,
],
);

$livewire
->mountTableAction('create')
->fillForm([
'line_1' => $line1 = 'Test Line 1',
'line_2' => $line2 = 'Test Line 2',
'city' => $city = 'Test City',
'state' => $state = 'Test State',
'postal_code' => $postalCode = 'TE1 1ST',
'type' => $type = AddressType::BILLING->value,
])
->callTableAction('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(CustomerAddress::class, [
'line_1' => $line1,
'line_2' => $line2,
'city' => $city,
'state' => $state,
'postal_code' => $postalCode,
'type' => $type,
]);
}
public function test_a_new_address_can_be_created(): void
{
$customer = Customer::factory()->create();

$livewire = Livewire::test(
name: AddressesRelationManager::class,
params: [
'ownerRecord' => $customer,
'pageClass' => EditCustomer::class,
],
);

$livewire
->mountTableAction('create')
->fillForm([
'line_1' => $line1 = 'Test Line 1',
'line_2' => $line2 = 'Test Line 2',
'city' => $city = 'Test City',
'state' => $state = 'Test State',
'postal_code' => $postalCode = 'TE1 1ST',
'type' => $type = AddressType::BILLING->value,
])
->callTableAction('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(CustomerAddress::class, [
'line_1' => $line1,
'line_2' => $line2,
'city' => $city,
'state' => $state,
'postal_code' => $postalCode,
'type' => $type,
]);
}
No description
13 Replies
Aethyrion
AethyrionOP6d ago
Anyone able to point me in the right direction with this?
LeandroFerreira
try callMountedTableAction() instead of callTableAction('create')
Aethyrion
AethyrionOP6d ago
No bueno. I get the same error as in that screengrab fillForm has a second argument $form which defaults to "form", as this is a relation manager form do I need to pass in a form name? Not sure what I'd pass in though or how I'd find the name
Punyapal Shah
Punyapal Shah6d ago
use setTableActionData at the place of fillForm
Aethyrion
AethyrionOP6d ago
Hmm, still the same. This is what the test looks like at the moment with these couple of updates:
$customer = Customer::factory()->create();

$livewire = Livewire::test(
name: AddressesRelationManager::class,
params: [
'ownerRecord' => $customer,
'pageClass' => EditCustomer::class,
],
);

$livewire
->mountTableAction('create')
->setTableActionData([
'line_1' => $line1 = 'Test Line 1',
'line_2' => $line2 = 'Test Line 2',
'city' => $city = 'Test City',
'state' => $state = 'Test State',
'postal_code' => $postalCode = 'TE1 1ST',
'type' => $type = AddressType::BILLING->value,
])
->callMountedTableAction()
->assertHasNoFormErrors();
$customer = Customer::factory()->create();

$livewire = Livewire::test(
name: AddressesRelationManager::class,
params: [
'ownerRecord' => $customer,
'pageClass' => EditCustomer::class,
],
);

$livewire
->mountTableAction('create')
->setTableActionData([
'line_1' => $line1 = 'Test Line 1',
'line_2' => $line2 = 'Test Line 2',
'city' => $city = 'Test City',
'state' => $state = 'Test State',
'postal_code' => $postalCode = 'TE1 1ST',
'type' => $type = AddressType::BILLING->value,
])
->callMountedTableAction()
->assertHasNoFormErrors();
It's weird because the error says that InfoList is being passed into form(), but I dd it out and it's an instance of Filament\Forms\Form which is what I expect So I'm not sure where InfoList is coming from
Aethyrion
AethyrionOP6d ago
No description
Aethyrion
AethyrionOP6d ago
Actually it is
No description
Punyapal Shah
Punyapal Shah5d ago
best
->callTableAction('create', data: [
'line_1' => $line1 = 'Test Line 1',
'line_2' => $line2 = 'Test Line 2',
'city' => $city = 'Test City',
'state' => $state = 'Test State',
'postal_code' => $postalCode = 'TE1 1ST',
'type' => $type = AddressType::BILLING->value,
])
->callTableAction('create', data: [
'line_1' => $line1 = 'Test Line 1',
'line_2' => $line2 = 'Test Line 2',
'city' => $city = 'Test City',
'state' => $state = 'Test State',
'postal_code' => $postalCode = 'TE1 1ST',
'type' => $type = AddressType::BILLING->value,
])
Aethyrion
AethyrionOP5d ago
Still getting that same error 😮‍💨 I'm not sure exactly what an InfoList is, but I'm not explicitly using one in anything I've set up so far The form itself works fine if I were to create an address manually
LeandroFerreira
Did you solve it?
Aethyrion
AethyrionOP2d ago
Unfortunately not. I keep getting that same error about InfoList Which I don’t understand why because I’m not using an info list anywhere
LeandroFerreira
LeandroFerreirathis hour
let me try that..
Aethyrion
AethyrionOP12h ago
Any joy?

Did you find this page helpful?