|
|
@ -4,26 +4,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.mozilla.fenix.home
|
|
|
|
package org.mozilla.fenix.home
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.mockk.mockk
|
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
|
|
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
|
|
|
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
|
|
|
|
|
|
|
import mozilla.components.browser.state.action.ContentAction.UpdateIconAction
|
|
|
|
|
|
|
|
import mozilla.components.browser.state.action.ContentAction.UpdateTitleAction
|
|
|
|
import mozilla.components.browser.state.action.TabListAction
|
|
|
|
import mozilla.components.browser.state.action.TabListAction
|
|
|
|
import mozilla.components.browser.state.state.BrowserState
|
|
|
|
import mozilla.components.browser.state.state.BrowserState
|
|
|
|
import mozilla.components.browser.state.state.createTab
|
|
|
|
import mozilla.components.browser.state.state.createTab
|
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
import mozilla.components.browser.state.store.BrowserStore
|
|
|
|
import mozilla.components.support.test.ext.joinBlocking
|
|
|
|
import mozilla.components.support.test.ext.joinBlocking
|
|
|
|
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
|
|
|
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
|
|
|
|
|
|
|
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.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
|
|
|
|
|
import org.junit.Assert.assertNull
|
|
|
|
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.Test
|
|
|
|
|
|
|
|
import org.mozilla.fenix.home.HomeFragmentAction.RecentTabsChange
|
|
|
|
import org.mozilla.fenix.home.recenttabs.RecentTabsListFeature
|
|
|
|
import org.mozilla.fenix.home.recenttabs.RecentTabsListFeature
|
|
|
|
|
|
|
|
|
|
|
|
class RecentTabsListFeatureTest {
|
|
|
|
class RecentTabsListFeatureTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var homeStore: HomeFragmentStore
|
|
|
|
|
|
|
|
private lateinit var middleware: CaptureActionsMiddleware<HomeFragmentState, HomeFragmentAction>
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalCoroutinesApi::class)
|
|
|
|
@OptIn(ExperimentalCoroutinesApi::class)
|
|
|
|
@get:Rule
|
|
|
|
@get:Rule
|
|
|
|
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
|
|
|
|
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
|
|
|
fun setup() {
|
|
|
|
|
|
|
|
middleware = CaptureActionsMiddleware()
|
|
|
|
|
|
|
|
homeStore = HomeFragmentStore(middlewares = listOf(middleware))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
|
|
|
fun teardown() {
|
|
|
|
|
|
|
|
middleware.reset()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun `GIVEN no selected tab WHEN the feature starts THEN dispatch an empty list`() {
|
|
|
|
fun `GIVEN no selected tab WHEN the feature starts THEN dispatch an empty list`() {
|
|
|
|
val browserStore = BrowserStore()
|
|
|
|
val browserStore = BrowserStore()
|
|
|
@ -53,7 +77,6 @@ class RecentTabsListFeatureTest {
|
|
|
|
selectedTabId = "1"
|
|
|
|
selectedTabId = "1"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
val homeStore = HomeFragmentStore()
|
|
|
|
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
browserStore = browserStore,
|
|
|
|
browserStore = browserStore,
|
|
|
|
homeStore = homeStore
|
|
|
|
homeStore = homeStore
|
|
|
@ -83,7 +106,6 @@ class RecentTabsListFeatureTest {
|
|
|
|
selectedTabId = "1"
|
|
|
|
selectedTabId = "1"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
val homeStore = HomeFragmentStore()
|
|
|
|
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
browserStore = browserStore,
|
|
|
|
browserStore = browserStore,
|
|
|
|
homeStore = homeStore
|
|
|
|
homeStore = homeStore
|
|
|
@ -122,7 +144,6 @@ class RecentTabsListFeatureTest {
|
|
|
|
selectedTabId = "1"
|
|
|
|
selectedTabId = "1"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
val homeStore = HomeFragmentStore()
|
|
|
|
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
browserStore = browserStore,
|
|
|
|
browserStore = browserStore,
|
|
|
|
homeStore = homeStore
|
|
|
|
homeStore = homeStore
|
|
|
@ -141,4 +162,54 @@ class RecentTabsListFeatureTest {
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(0, homeStore.state.recentTabs.size)
|
|
|
|
assertEquals(0, homeStore.state.recentTabs.size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `WHEN the selected tabs title or icon update THEN update the home store`() {
|
|
|
|
|
|
|
|
val browserStore = BrowserStore(
|
|
|
|
|
|
|
|
BrowserState(
|
|
|
|
|
|
|
|
tabs = listOf(
|
|
|
|
|
|
|
|
createTab(
|
|
|
|
|
|
|
|
url = "https://www.mozilla.org",
|
|
|
|
|
|
|
|
id = "1"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
selectedTabId = "1"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
val feature = RecentTabsListFeature(
|
|
|
|
|
|
|
|
browserStore = browserStore,
|
|
|
|
|
|
|
|
homeStore = homeStore
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feature.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homeStore.waitUntilIdle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
middleware.assertLastAction(RecentTabsChange::class) {
|
|
|
|
|
|
|
|
val tab = it.recentTabs.first()
|
|
|
|
|
|
|
|
assertTrue(tab.content.title.isEmpty())
|
|
|
|
|
|
|
|
assertNull(tab.content.icon)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browserStore.dispatch(UpdateTitleAction("1", "test")).joinBlocking()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homeStore.waitUntilIdle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
middleware.assertLastAction(RecentTabsChange::class) {
|
|
|
|
|
|
|
|
val tab = it.recentTabs.first()
|
|
|
|
|
|
|
|
assertEquals("test", tab.content.title)
|
|
|
|
|
|
|
|
assertNull(tab.content.icon)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browserStore.dispatch(UpdateIconAction("1", "https://www.mozilla.org", mockk()))
|
|
|
|
|
|
|
|
.joinBlocking()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homeStore.waitUntilIdle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
middleware.assertLastAction(RecentTabsChange::class) {
|
|
|
|
|
|
|
|
val tab = it.recentTabs.first()
|
|
|
|
|
|
|
|
assertEquals("test", tab.content.title)
|
|
|
|
|
|
|
|
assertNotNull(tab.content.icon)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|