Bug 1855209 - Show the shopping CFRs only once for loaded product pages

fenix/120.0
Alexandru2909 8 months ago committed by mergify[bot]
parent 5df74fbfab
commit 31f8156dd6

@ -23,6 +23,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.transformWhile
@ -107,15 +108,18 @@ class BrowserToolbarCFRPresenter(
ToolbarCFR.SHOPPING, ToolbarCFR.SHOPPING_OPTED_IN -> {
scope = browserStore.flowScoped { flow ->
flow.mapNotNull { it.selectedTab }
val shouldShowCfr: Boolean? = flow.mapNotNull { it.selectedTab }
.filter { it.isProductUrl && it.content.progress == 100 && !it.content.loading }
.distinctUntilChanged()
.collect {
if (toolbar.findViewById<View>(R.id.mozac_browser_toolbar_page_actions).isVisible) {
scope?.cancel()
showShoppingCFR(getCFRToShow() == ToolbarCFR.SHOPPING_OPTED_IN)
}
}
.map { toolbar.findViewById<View>(R.id.mozac_browser_toolbar_page_actions).isVisible }
.filter { it }
.firstOrNull()
if (shouldShowCfr == true) {
showShoppingCFR(getCFRToShow() == ToolbarCFR.SHOPPING_OPTED_IN)
}
scope?.cancel()
}
}

@ -16,6 +16,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.ShoppingProductAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.CustomTabSessionState
import mozilla.components.browser.state.state.TabSessionState
@ -255,7 +256,7 @@ class BrowserToolbarCFRPresenterTest {
}
@Test
fun `GIVEN the user opted in the shopping feature AND the opted in shopping CFR should be shown WHEN the tab is not loading THEN the CFR is shown`() {
fun `GIVEN the user opted in the shopping feature AND the opted in shopping CFR should be shown WHEN the tab finishes loading THEN the CFR is shown`() {
val tab = createTab(url = "")
val browserStore = createBrowserStore(
tab = tab,
@ -290,6 +291,40 @@ class BrowserToolbarCFRPresenterTest {
verify { presenter.showShoppingCFR(eq(true)) }
}
@Test
fun `GIVEN the user opted in the shopping feature AND the opted in shopping CFR should be shown WHEN opening a loaded product page THEN the CFR is shown`() {
val tab1 = createTab(url = "", id = "tab1")
val tab2 = createTab(url = "", id = "tab2")
val browserStore = BrowserStore(
initialState = BrowserState(
tabs = listOf(tab1, tab2),
selectedTabId = tab2.id,
),
)
val presenter = createPresenter(
settings = mockk {
every { shouldShowTotalCookieProtectionCFR } returns false
every { shouldShowReviewQualityCheckCFR } returns true
every { shouldShowEraseActionCFR } returns false
every { reviewQualityCheckOptInTimeInMillis } returns System.currentTimeMillis() - Settings.TWO_DAYS_MS
},
browserStore = browserStore,
)
every { presenter.showShoppingCFR(any()) } just Runs
presenter.start()
assertNotNull(presenter.scope)
browserStore.dispatch(ShoppingProductAction.UpdateProductUrlStatusAction(tab1.id, true)).joinBlocking()
browserStore.dispatch(ContentAction.UpdateProgressAction(tab1.id, 100)).joinBlocking()
verify(exactly = 0) { presenter.showShoppingCFR(any()) }
browserStore.dispatch(TabListAction.SelectTabAction(tab1.id)).joinBlocking()
verify(exactly = 1) { presenter.showShoppingCFR(any()) }
}
/**
* Creates and return a [spyk] of a [BrowserToolbarCFRPresenter] that can handle actually showing CFRs.
*/

Loading…
Cancel
Save