test relationmanager CreateAction

Hello guys, could somebody submit some example code how to test a relation manager create action? - how to fill the form, how to submit the form? Based on the documentation here: i wrote this test, but it fails, cannot see the text:
$this->actingAs($user)
->get(EventResource::getUrl('view', ['tenant' => $tenant->slug, 'record' => $event->id]))
->assertSuccessful();

livewire(EventResource\RelationManagers\AttendeeRelationManager::class,
[
'ownerRecord' => $event,
'pageClass' => EventResource\Pages\ViewEvent::class,
])
->assertSuccessful()
->mountAction(CreateAction::class)
->assertSee('Create Attendee');
$this->actingAs($user)
->get(EventResource::getUrl('view', ['tenant' => $tenant->slug, 'record' => $event->id]))
->assertSuccessful();

livewire(EventResource\RelationManagers\AttendeeRelationManager::class,
[
'ownerRecord' => $event,
'pageClass' => EventResource\Pages\ViewEvent::class,
])
->assertSuccessful()
->mountAction(CreateAction::class)
->assertSee('Create Attendee');
2 Replies
Vp
Vp3w ago
This is how I test for normal --simple resource, since relation manager create also uses modal I guess you can do like this as well
it('can create new data', function () {
$newData = AnnouncementFactory::new()->create();

livewire(AnnouncementResource\Pages\ManageAnnouncements::class)
->mountAction('create')
->setActionData([
'title' => $newData->title,
'detail' => $newData->detail,
])
->callMountedAction();

$this->assertDatabaseHas(Announcement::class, [
'title' => $newData->title,
'detail' => $newData->detail,
]);
});
it('can create new data', function () {
$newData = AnnouncementFactory::new()->create();

livewire(AnnouncementResource\Pages\ManageAnnouncements::class)
->mountAction('create')
->setActionData([
'title' => $newData->title,
'detail' => $newData->detail,
])
->callMountedAction();

$this->assertDatabaseHas(Announcement::class, [
'title' => $newData->title,
'detail' => $newData->detail,
]);
});
Roland Barkóczi
Roland BarkócziOP3w ago
Thank you Vp. With your help I managed to write test for the relationmanager like this:
livewire(EventResource\RelationManagers\AttendeeRelationManager::class,
[
'ownerRecord' => $event,
'pageClass' => EventResource\Pages\ViewEvent::class,
])
->assertSuccessful()
->mountTableAction('create')
->assertSee('Create Attendee')
->setTableActionData($attendee->toArray())
->callMountedTableAction()
->assertHasNoActionErrors();
livewire(EventResource\RelationManagers\AttendeeRelationManager::class,
[
'ownerRecord' => $event,
'pageClass' => EventResource\Pages\ViewEvent::class,
])
->assertSuccessful()
->mountTableAction('create')
->assertSee('Create Attendee')
->setTableActionData($attendee->toArray())
->callMountedTableAction()
->assertHasNoActionErrors();
Want results from more Discord servers?
Add your server