Testing infolist actions

Hey @hasnayeen
7 Replies
Patrick Boivin
Patrick BoivinOP15mo ago
Starting a new thread here, regarding your question So I don't have a ton of experience testing infolists but I've explored it previously by reaching into the component instance in the test. Something like this:
$testable = Livewire::test(ViewPage::class, ['record' => ...]);

/** @var ViewPage $page */
$page = $testable->instance();

$this->assertArrayHasKey(
'myCustomAction',
$page->getInfolist('infolist')->getComponents()[0]->getActions()
);
$testable = Livewire::test(ViewPage::class, ['record' => ...]);

/** @var ViewPage $page */
$page = $testable->instance();

$this->assertArrayHasKey(
'myCustomAction',
$page->getInfolist('infolist')->getComponents()[0]->getActions()
);
I guess in your case you could instead access the action object, run the action, and make your assertion in the DB Something to experiment
Hasnayeen
Hasnayeen15mo ago
I already saw your answer to other post, trying to do exactly that but couldn't access the action as it's too nested and the it all very cyclical
Patrick Boivin
Patrick BoivinOP15mo ago
Hmm. Is it important that the action be in the infolist for the test? Can you extract just this action in your codebase, and then simplify your test around the action class?
Hasnayeen
Hasnayeen15mo ago
that's a good idea but the action is one-off so kinda hesitant to extract that to a separate class but if I can't find any other way then probably do this. Thanks for the suggestion ok did this according to your suggestion -> access the action object, run the action, and make your assertion in the DB
Patrick Boivin
Patrick BoivinOP15mo ago
Awesome. How did you get around your cyclical issues?
Hasnayeen
Hasnayeen15mo ago
retrieved the action using name
$page->getInfolist('infolist')
->getComponent('input')
->getAction('create')
->formData([
'keys' => [
'name' => 'Test',
]
])
->call();
$page->getInfolist('infolist')
->getComponent('input')
->getAction('create')
->formData([
'keys' => [
'name' => 'Test',
]
])
->call();
Isama
Isama13mo ago
i came up with something like this if you add a section you might need to add another ->getChildComponents()[0] after the first one
$livewire = livewire(ViewInviteeInfoList::class, ['record' => $invitee->getRouteKey()]);

$livewire ->instance()
->getInfolist('infolist')
->getComponents()[0]
->getChildComponents()[0] // this is the index of your action in your actions group - if you dont have one you might not need getChildComponents()
->getAction('delete_invitee')
->call();
$livewire = livewire(ViewInviteeInfoList::class, ['record' => $invitee->getRouteKey()]);

$livewire ->instance()
->getInfolist('infolist')
->getComponents()[0]
->getChildComponents()[0] // this is the index of your action in your actions group - if you dont have one you might not need getChildComponents()
->getAction('delete_invitee')
->call();
Want results from more Discord servers?
Add your server