|
|
@ -7,11 +7,9 @@ package org.mozilla.fenix.home.recentbookmarks
|
|
|
|
import io.mockk.coEvery
|
|
|
|
import io.mockk.coEvery
|
|
|
|
import io.mockk.coVerify
|
|
|
|
import io.mockk.coVerify
|
|
|
|
import io.mockk.mockk
|
|
|
|
import io.mockk.mockk
|
|
|
|
import io.mockk.spyk
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
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.runBlockingTest
|
|
|
|
import kotlinx.coroutines.test.runBlockingTest
|
|
|
|
import mozilla.components.concept.storage.BookmarkNode
|
|
|
|
import mozilla.components.concept.storage.BookmarkNode
|
|
|
|
import mozilla.components.concept.storage.BookmarkNodeType
|
|
|
|
import mozilla.components.concept.storage.BookmarkNodeType
|
|
|
@ -20,8 +18,6 @@ import mozilla.components.support.test.middleware.CaptureActionsMiddleware
|
|
|
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
|
|
|
import mozilla.components.support.test.rule.MainCoroutineRule
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
|
|
|
|
|
import org.junit.Assert.assertNull
|
|
|
|
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.Test
|
|
|
@ -36,7 +32,6 @@ class RecentBookmarksFeatureTest {
|
|
|
|
private val middleware = CaptureActionsMiddleware<HomeFragmentState, HomeFragmentAction>()
|
|
|
|
private val middleware = CaptureActionsMiddleware<HomeFragmentState, HomeFragmentAction>()
|
|
|
|
private val homeStore = HomeFragmentStore(middlewares = listOf(middleware))
|
|
|
|
private val homeStore = HomeFragmentStore(middlewares = listOf(middleware))
|
|
|
|
private val bookmarksUseCases: BookmarksUseCase = mockk(relaxed = true)
|
|
|
|
private val bookmarksUseCases: BookmarksUseCase = mockk(relaxed = true)
|
|
|
|
private val scope = TestCoroutineScope()
|
|
|
|
|
|
|
|
private val testDispatcher = TestCoroutineDispatcher()
|
|
|
|
private val testDispatcher = TestCoroutineDispatcher()
|
|
|
|
private val bookmark = BookmarkNode(
|
|
|
|
private val bookmark = BookmarkNode(
|
|
|
|
type = BookmarkNodeType.ITEM,
|
|
|
|
type = BookmarkNodeType.ITEM,
|
|
|
@ -58,7 +53,6 @@ class RecentBookmarksFeatureTest {
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
@After
|
|
|
|
fun cleanUp() {
|
|
|
|
fun cleanUp() {
|
|
|
|
scope.cleanupTestCoroutines()
|
|
|
|
|
|
|
|
testDispatcher.cleanupTestCoroutines()
|
|
|
|
testDispatcher.cleanupTestCoroutines()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -68,13 +62,14 @@ class RecentBookmarksFeatureTest {
|
|
|
|
val feature = RecentBookmarksFeature(
|
|
|
|
val feature = RecentBookmarksFeature(
|
|
|
|
homeStore,
|
|
|
|
homeStore,
|
|
|
|
bookmarksUseCases,
|
|
|
|
bookmarksUseCases,
|
|
|
|
scope
|
|
|
|
CoroutineScope(testDispatcher),
|
|
|
|
|
|
|
|
testDispatcher
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
feature.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(emptyList<BookmarkNode>(), homeStore.state.recentBookmarks)
|
|
|
|
assertEquals(emptyList<BookmarkNode>(), homeStore.state.recentBookmarks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature.start()
|
|
|
|
|
|
|
|
|
|
|
|
testDispatcher.advanceUntilIdle()
|
|
|
|
testDispatcher.advanceUntilIdle()
|
|
|
|
homeStore.waitUntilIdle()
|
|
|
|
homeStore.waitUntilIdle()
|
|
|
|
|
|
|
|
|
|
|
@ -86,23 +81,4 @@ class RecentBookmarksFeatureTest {
|
|
|
|
assertEquals(listOf(bookmark), it.recentBookmarks)
|
|
|
|
assertEquals(listOf(bookmark), it.recentBookmarks)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `WHEN the feature is destroyed THEN the job is cancelled`() {
|
|
|
|
|
|
|
|
val feature = spyk(RecentBookmarksFeature(
|
|
|
|
|
|
|
|
homeStore,
|
|
|
|
|
|
|
|
bookmarksUseCases,
|
|
|
|
|
|
|
|
scope
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertNull(feature.job)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(feature.job)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(exactly = 1) { feature.stop() }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|