2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-02 03:40:16 +00:00

Fix up HistoryMetadataController tests

This commit is contained in:
Grisha Kruglov 2021-10-13 11:16:12 -07:00 committed by Grisha Kruglov
parent a9e598b6b6
commit f58191db8f

View File

@ -14,6 +14,8 @@ import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.browser.state.action.HistoryMetadataAction
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.storage.DocumentType import mozilla.components.concept.storage.DocumentType
import mozilla.components.concept.storage.HistoryMetadata import mozilla.components.concept.storage.HistoryMetadata
import mozilla.components.concept.storage.HistoryMetadataKey import mozilla.components.concept.storage.HistoryMetadataKey
@ -24,9 +26,10 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserFragmentDirections
import org.mozilla.fenix.historymetadata.HistoryMetadataGroup import org.mozilla.fenix.historymetadata.HistoryMetadataGroup
import org.mozilla.fenix.home.HomeFragmentAction
import org.mozilla.fenix.home.HomeFragmentDirections import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.HomeFragmentStore
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
class HistoryMetadataControllerTest { class HistoryMetadataControllerTest {
@ -38,6 +41,8 @@ class HistoryMetadataControllerTest {
private val navController = mockk<NavController>(relaxed = true) private val navController = mockk<NavController>(relaxed = true)
private lateinit var storage: HistoryMetadataStorage private lateinit var storage: HistoryMetadataStorage
private lateinit var homeFragmentStore: HomeFragmentStore
private lateinit var store: BrowserStore
private val scope = TestCoroutineScope() private val scope = TestCoroutineScope()
private lateinit var controller: DefaultHistoryMetadataController private lateinit var controller: DefaultHistoryMetadataController
@ -48,9 +53,13 @@ class HistoryMetadataControllerTest {
every { id } returns R.id.homeFragment every { id } returns R.id.homeFragment
} }
storage = mockk(relaxed = true) storage = mockk(relaxed = true)
homeFragmentStore = mockk(relaxed = true)
store = mockk(relaxed = true)
controller = spyk( controller = spyk(
DefaultHistoryMetadataController( DefaultHistoryMetadataController(
homeStore = homeFragmentStore,
store = store,
navController = navController, navController = navController,
scope = scope, scope = scope,
storage = storage storage = storage
@ -126,14 +135,15 @@ class HistoryMetadataControllerTest {
controller.handleRemoveGroup(historyGroup.title) controller.handleRemoveGroup(historyGroup.title)
testDispatcher.advanceUntilIdle() testDispatcher.advanceUntilIdle()
verify {
store.dispatch(HistoryMetadataAction.DisbandSearchGroupAction(searchTerm = historyGroup.title))
}
verify {
homeFragmentStore.dispatch(HomeFragmentAction.DisbandSearchGroupAction(searchTerm = historyGroup.title))
}
coVerify { coVerify {
storage.deleteHistoryMetadata(historyGroup.title) storage.deleteHistoryMetadata(historyGroup.title)
} }
verify {
navController.navigate(
BrowserFragmentDirections.actionGlobalHome()
)
}
} }
} }