F
Filament2mo ago
CGM

How to test pages that extend extend ManageRelatedRecords (Create via Modal)

How would you properly setup a simple test for a custom page that extends ManageRelatedRecords? This is a standard page create using make:filament-page and selecting Relationship. The form is in a Modal and I think that is where I'm getting stuck. I would love to see an example of how to just see how to assert the successful submission of a create form (no errors) via the modal. I think I could plow through the rest from there. 🙂
4 Replies
CGM
CGM2mo ago
I'm making a little progress, but I'm having a very difficult time with submitting the form as well as any FormFill calls and form error checking calls. Is there any way to test the form portion of the code while skipping on the table action portion? I feel like I'm pulling in way too much here to test a few simple form conditions.
livewire(ManageReviewSites::class, [
'record' => $location->id,
])

->assertTableActionExists('create')
->mountTableAction('create', record: $location)
->setTableActionData([
'location_id' => $location->id,
])
->assertSet('mountedTableActionsData', ['' => ['location_id' => $location->id]])
->setTableActionData([
'name' => 'Test Review Site',
])
->assertSet('mountedTableActionsData', ['' => ['name' => 'Test Review Site', 'location_id' => $location->id]])
->callTableAction('create', record: $location)
->assertHasNoTableActionErrors();
livewire(ManageReviewSites::class, [
'record' => $location->id,
])

->assertTableActionExists('create')
->mountTableAction('create', record: $location)
->setTableActionData([
'location_id' => $location->id,
])
->assertSet('mountedTableActionsData', ['' => ['location_id' => $location->id]])
->setTableActionData([
'name' => 'Test Review Site',
])
->assertSet('mountedTableActionsData', ['' => ['name' => 'Test Review Site', 'location_id' => $location->id]])
->callTableAction('create', record: $location)
->assertHasNoTableActionErrors();
CGM
CGM2mo ago
Ok, I think I've found the right direction now. I was looking in Panels and Forms, but I think the testing docs I needed were in https://filamentphp.com/docs/3.x/actions/testing. I'm still struggling on actually submitting the "Create" action from the Relation Manager Page to actully save the form.
CGM
CGM2mo ago
Should ->callMountedAction() be submitting the create form? This is I suppose what is the 'standard create action' on a relation page. I haven't really customized anything yet.
it('should be testable', function () {
$location = Location::factory()->create();
$user = User::factory()->create();
$this->actingAs($user);

expect($location->reviewSites)->toBeEmpty();

livewire(ManageReviewSites::class, [
'record' => $location->id,
])
->assertTableActionExists('create')
->mountTableAction('create', record: $location)
->setTableActionData([
'location_id' => $location->id,
])
->assertSet('mountedTableActionsData', ['' => ['location_id' => $location->id]])
->setTableActionData([
'name' => 'Test Review Site',
])
->assertSet('mountedTableActionsData', ['' => ['name' => 'Test Review Site', 'location_id' => $location->id]])
->callTableAction('create', record: $location)
->callMountedAction()
->assertHasNoTableActionErrors();

expect($location->refresh()->reviewSites)->toHaveCount(1);
});
it('should be testable', function () {
$location = Location::factory()->create();
$user = User::factory()->create();
$this->actingAs($user);

expect($location->reviewSites)->toBeEmpty();

livewire(ManageReviewSites::class, [
'record' => $location->id,
])
->assertTableActionExists('create')
->mountTableAction('create', record: $location)
->setTableActionData([
'location_id' => $location->id,
])
->assertSet('mountedTableActionsData', ['' => ['location_id' => $location->id]])
->setTableActionData([
'name' => 'Test Review Site',
])
->assertSet('mountedTableActionsData', ['' => ['name' => 'Test Review Site', 'location_id' => $location->id]])
->callTableAction('create', record: $location)
->callMountedAction()
->assertHasNoTableActionErrors();

expect($location->refresh()->reviewSites)->toHaveCount(1);
});
Dan Harrin
Dan Harrin2mo ago
callTableAction is doing to mount, fill the form, and submit callMountedAction is used if you want to manually mount, and then set the data, and then use it to submit
Want results from more Discord servers?
Add your server
More Posts