Bug 1826590 - Fix ClassCastException in ShareControllerTest.

Also verify dismiss calls.
fenix/116.0
mcarare 1 year ago committed by mergify[bot]
parent a731b1dbbd
commit e01dd40dc2

@ -18,6 +18,7 @@ import io.mockk.slot
import io.mockk.spyk import io.mockk.spyk
import io.mockk.verify import io.mockk.verify
import io.mockk.verifyOrder import io.mockk.verifyOrder
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.advanceUntilIdle
import mozilla.components.concept.engine.prompt.ShareData import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.concept.sync.Device import mozilla.components.concept.sync.Device
@ -417,16 +418,18 @@ class ShareControllerTest {
val deviceId = slot<String>() val deviceId = slot<String>()
val tabsShared = slot<List<TabData>>() val tabsShared = slot<List<TabData>>()
every { sendTabUseCases.sendToDeviceAsync(any(), any<List<TabData>>()) } returns CompletableDeferred(true)
every { navController.currentDestination?.id } returns R.id.shareFragment
controller.handleShareToDevice(deviceToShareTo) controller.handleShareToDevice(deviceToShareTo)
assertNotNull(SyncAccount.sendTab.testGetValue()) assertNotNull(SyncAccount.sendTab.testGetValue())
assertEquals(1, SyncAccount.sendTab.testGetValue()!!.size) assertEquals(1, SyncAccount.sendTab.testGetValue()!!.size)
assertNull(SyncAccount.sendTab.testGetValue()!!.single().extra) assertNull(SyncAccount.sendTab.testGetValue()!!.single().extra)
// Verify all the needed methods are called. verifyOrder {
verify {
sendTabUseCases.sendToDeviceAsync(capture(deviceId), capture(tabsShared)) sendTabUseCases.sendToDeviceAsync(capture(deviceId), capture(tabsShared))
// dismiss() is also to be called, but at the moment cannot test it in a coroutine. dismiss(ShareController.Result.SUCCESS)
} }
assertTrue(deviceId.isCaptured) assertTrue(deviceId.isCaptured)
@ -438,6 +441,9 @@ class ShareControllerTest {
@Test @Test
@Suppress("DeferredResultUnused") @Suppress("DeferredResultUnused")
fun `handleShareToAllDevices calls handleShareToDevice multiple times`() { fun `handleShareToAllDevices calls handleShareToDevice multiple times`() {
every { sendTabUseCases.sendToAllAsync(any<List<TabData>>()) } returns CompletableDeferred(true)
every { navController.currentDestination?.id } returns R.id.shareFragment
val devicesToShareTo = listOf( val devicesToShareTo = listOf(
Device( Device(
"deviceId0", "deviceId0",
@ -466,7 +472,7 @@ class ShareControllerTest {
verifyOrder { verifyOrder {
sendTabUseCases.sendToAllAsync(capture(tabsShared)) sendTabUseCases.sendToAllAsync(capture(tabsShared))
// dismiss() is also to be called, but at the moment cannot test it in a coroutine. dismiss(ShareController.Result.SUCCESS)
} }
// SendTabUseCases should send a the `shareTabs` mapped to tabData // SendTabUseCases should send a the `shareTabs` mapped to tabData

Loading…
Cancel
Save