Testing and requiresConfirmation

I have a RM with a table row action, that row action launches a modal with an approval action. I can get all the way up that point and it works fine in my test and will perform the approveAction, but if i add a confirmation to the approveAction, I cant seem to figure how to click the "Confirm" on the requiresConfirmation modal as it doesnt appear to have a mountAction for me to be able to call. This is wher i am so far:
Livewire::test(RftaResource\RelationManagers\ComparableUnitsRelationManager::class, [
'pageClass' => RftaResource\Pages\ViewRfta::class,
'ownerRecord' => $rfta,
])
->assertCanSeeTableRecords(collect([$comparable]))
->mountTableAction(ViewAction::class, record: $comparable->id)
->assertSee('Review Comparable Unit')
->assertSee('approveAction')
->mountTableAction('approveAction')
->callMountedTableAction() // requires confirmation
// now how do I click confirm on the requiresConfirmation() modal?
->assertHasNoTableActionErrors();
Livewire::test(RftaResource\RelationManagers\ComparableUnitsRelationManager::class, [
'pageClass' => RftaResource\Pages\ViewRfta::class,
'ownerRecord' => $rfta,
])
->assertCanSeeTableRecords(collect([$comparable]))
->mountTableAction(ViewAction::class, record: $comparable->id)
->assertSee('Review Comparable Unit')
->assertSee('approveAction')
->mountTableAction('approveAction')
->callMountedTableAction() // requires confirmation
// now how do I click confirm on the requiresConfirmation() modal?
->assertHasNoTableActionErrors();
15 Replies
LeandroFerreira
LeandroFerreira8mo ago
I think the approveAction will be triggered when you invoke the callMountedTableAction..
Mark Chaney
Mark ChaneyOP8mo ago
@Leandro Ferreira it does and processes great if i do not have requiresConfirmation() on that action, but as soon as I add it back, it doesnt complete
LeandroFerreira
LeandroFerreira8mo ago
hum.. Is the approveAction a extraModalFooterAction?
Mark Chaney
Mark ChaneyOP8mo ago
No, they are completely overriden with modalFooterActions()
LeandroFerreira
LeandroFerreira8mo ago
->mountTableAction('view', record: $comparable->id)
->assertSee('Approve action')
->call('mountTableAction', 'approveAction', $comparable->id)
->callMountedAction()
->callMountedTableAction()
->mountTableAction('view', record: $comparable->id)
->assertSee('Approve action')
->call('mountTableAction', 'approveAction', $comparable->id)
->callMountedAction()
->callMountedTableAction()
Mark Chaney
Mark ChaneyOP8mo ago
that seems to work, thanks! so why this way of doing it?
LeandroFerreira
LeandroFerreira8mo ago
you have another action that should be fired. So you need to do ->call()->call()...
Mark Chaney
Mark ChaneyOP8mo ago
right, but where are you targeting the confirmation
LeandroFerreira
LeandroFerreira8mo ago
if you inspect the code, we have two forms 1 - the approve action 2 - the confirmation
No description
LeandroFerreira
LeandroFerreira8mo ago
callMountedTableAction will submit the action
Mark Chaney
Mark ChaneyOP8mo ago
why is the approve action not a table action if it is indeed a table action class? sorry, just trying to wrap my head around it all so i can solve future issues. The inconsistency is what throws me a bit with some of this btw, thanks for jumping in and helping me with test issues. i really appreciate it
LeandroFerreira
LeandroFerreira8mo ago
You are right, sorry. We don't need to call ->callMountedAction() callMountedTableAction will do this
Mark Chaney
Mark ChaneyOP8mo ago
so it looks like the issue was really more with me doing
->mountTableAction('approveAction')
->mountTableAction('approveAction')
originally, which while was fine if i wanted to call just that action, but didnt allow the follow up ->callMountedTableAction() to handle the confirmation? Thus i had to do
->call('mountTableAction', 'approveAction', $comparable->id)
->call('mountTableAction', 'approveAction', $comparable->id)
instead before it? that looks to be the only difference
LeandroFerreira
LeandroFerreira8mo ago
I tried mountTableAction, but it didn’t work as expected. I’m not entirely sure why it failed, but in situations where I encounter issues with helpers, I find that using Livewire helps me achieve my results. If you encounter this issue, please feel free to submit a pull request ✌️
Mark Chaney
Mark ChaneyOP8mo ago
got it all working now with some comments and simplified a little
Livewire::test(RftaResource\RelationManagers\ComparableUnitsRelationManager::class, [
'pageClass' => RftaResource\Pages\ViewRfta::class,
'ownerRecord' => $rfta,
])
->assertCanSeeTableRecords(collect([$comparable]))
// Mount the ViewAction modal for the specified comparable unit record
->mountTableAction(ViewAction::class, record: $comparable->id)
// Assert that the $action is present in the ViewAction modal
->assertSee($action)
// Mount the $action within the ViewAction modal
->call('mountTableAction', $action)
->setTableActionData([
'note' => $note,
])
->assertTableActionDataSet([
'note' => $note,
])
// Call the mounted table $action and handle any confirmation modals
->callMountedTableAction()
// Assert that there are no errors during the table action execution
->assertHasNoTableActionErrors();
Livewire::test(RftaResource\RelationManagers\ComparableUnitsRelationManager::class, [
'pageClass' => RftaResource\Pages\ViewRfta::class,
'ownerRecord' => $rfta,
])
->assertCanSeeTableRecords(collect([$comparable]))
// Mount the ViewAction modal for the specified comparable unit record
->mountTableAction(ViewAction::class, record: $comparable->id)
// Assert that the $action is present in the ViewAction modal
->assertSee($action)
// Mount the $action within the ViewAction modal
->call('mountTableAction', $action)
->setTableActionData([
'note' => $note,
])
->assertTableActionDataSet([
'note' => $note,
])
// Call the mounted table $action and handle any confirmation modals
->callMountedTableAction()
// Assert that there are no errors during the table action execution
->assertHasNoTableActionErrors();
Want results from more Discord servers?
Add your server