Bug 1853301 - Refactor ReviewQualityCheckNavigationMiddleware to use TabsUseCases and SessionUseCases
Refactor LinkType class to support instances for each external link accessible from the review quality check featurefenix/120.0
parent
354be91be7
commit
9cac2fca23
@ -1,75 +1,56 @@
|
||||
package org.mozilla.fenix.shopping.middleware
|
||||
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import mozilla.components.feature.tabs.TabsUseCases
|
||||
import mozilla.components.support.test.ext.joinBlocking
|
||||
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class ReviewQualityCheckNavigationMiddlewareTest {
|
||||
|
||||
@get:Rule
|
||||
val coroutinesTestRule = MainCoroutineRule()
|
||||
private val dispatcher = coroutinesTestRule.testDispatcher
|
||||
private val scope = coroutinesTestRule.scope
|
||||
|
||||
@Test
|
||||
fun `WHEN opening an external link THEN the link should be opened in a new tab`() {
|
||||
var isOpenedInSelectedTab = false
|
||||
var isOpenedInNewTab = false
|
||||
val store = ReviewQualityCheckStore(
|
||||
middleware = listOf(
|
||||
ReviewQualityCheckNavigationMiddleware(
|
||||
openLink = { _, openInNewTab ->
|
||||
if (openInNewTab) {
|
||||
isOpenedInNewTab = true
|
||||
} else {
|
||||
isOpenedInSelectedTab = true
|
||||
}
|
||||
},
|
||||
scope = scope,
|
||||
),
|
||||
),
|
||||
private lateinit var store: ReviewQualityCheckStore
|
||||
private lateinit var browserStore: BrowserStore
|
||||
private lateinit var addTabUseCase: TabsUseCases.SelectOrAddUseCase
|
||||
private lateinit var middleware: ReviewQualityCheckNavigationMiddleware
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
browserStore = BrowserStore()
|
||||
addTabUseCase = TabsUseCases.SelectOrAddUseCase(browserStore)
|
||||
middleware = ReviewQualityCheckNavigationMiddleware(
|
||||
selectOrAddUseCase = addTabUseCase,
|
||||
context = testContext,
|
||||
scope = scope,
|
||||
)
|
||||
store = ReviewQualityCheckStore(
|
||||
middleware = listOf(middleware),
|
||||
)
|
||||
store.waitUntilIdle()
|
||||
dispatcher.scheduler.advanceUntilIdle()
|
||||
|
||||
store.dispatch(ReviewQualityCheckAction.OpenLink(ReviewQualityCheckState.LinkType.ExternalLink("www.mozilla.com"))).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertEquals(true, isOpenedInNewTab)
|
||||
assertEquals(false, isOpenedInSelectedTab)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN re-analzying a product THEN the link should be opened in the currently selected tab`() {
|
||||
var isOpenedInSelectedTab = false
|
||||
var isOpenedInNewTab = false
|
||||
val store = ReviewQualityCheckStore(
|
||||
middleware = listOf(
|
||||
ReviewQualityCheckNavigationMiddleware(
|
||||
openLink = { _, openInNewTab ->
|
||||
if (openInNewTab) {
|
||||
isOpenedInNewTab = true
|
||||
} else {
|
||||
isOpenedInSelectedTab = true
|
||||
}
|
||||
},
|
||||
scope = scope,
|
||||
),
|
||||
),
|
||||
)
|
||||
fun `WHEN opening an external link THEN the link should be opened in a new tab`() {
|
||||
val action = ReviewQualityCheckAction.OpenPoweredByLink
|
||||
store.waitUntilIdle()
|
||||
dispatcher.scheduler.advanceUntilIdle()
|
||||
assertEquals(0, browserStore.state.tabs.size)
|
||||
|
||||
store.dispatch(ReviewQualityCheckAction.OpenLink(ReviewQualityCheckState.LinkType.AnalyzeLink("www.mozilla.com"))).joinBlocking()
|
||||
store.dispatch(action).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertEquals(true, isOpenedInSelectedTab)
|
||||
assertEquals(false, isOpenedInNewTab)
|
||||
assertEquals(1, browserStore.state.tabs.size)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue