Bug 1856894 - Fix review checker shopping icon tint

fenix/120.0
rahulsainani 1 year ago committed by mergify[bot]
parent baa1958b0f
commit 7bc745dc39

@ -256,8 +256,8 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
reviewQualityCheckAvailable = it
safeInvalidateBrowserToolbarView()
},
onBottomSheetCollapsed = {
reviewQualityCheck.setSelected(selected = false, notifyListener = false)
onBottomSheetStateChange = {
reviewQualityCheck.setSelected(selected = it, notifyListener = false)
},
),
owner = this,

@ -77,5 +77,5 @@ data class AppState(
val pendingDeletionHistoryItems: Set<PendingDeletionHistory> = emptySet(),
val wallpaperState: WallpaperState = WallpaperState.default,
val standardSnackbarError: StandardSnackbarError? = null,
val shoppingSheetExpanded: Boolean = false,
val shoppingSheetExpanded: Boolean? = null,
) : State

@ -7,8 +7,6 @@ package org.mozilla.fenix.shopping
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import mozilla.components.browser.state.selector.selectedTab
@ -26,14 +24,14 @@ import org.mozilla.fenix.components.AppStore
* @property shoppingExperienceFeature Reference to the [ShoppingExperienceFeature].
* @property onAvailabilityChange Invoked when availability of this feature changes based on feature
* flag and when the loaded page is a supported product page.
* @property onBottomSheetCollapsed Invoked when the bottom sheet is collapsed.
* @property onBottomSheetStateChange Invoked when the bottom sheet is collapsed or expanded.
*/
class ReviewQualityCheckFeature(
private val appStore: AppStore,
private val browserStore: BrowserStore,
private val shoppingExperienceFeature: ShoppingExperienceFeature,
private val onAvailabilityChange: (isAvailable: Boolean) -> Unit,
private val onBottomSheetCollapsed: () -> Unit,
private val onBottomSheetStateChange: (isExpanded: Boolean) -> Unit,
) : LifecycleAwareFeature {
private var scope: CoroutineScope? = null
private var appStoreScope: CoroutineScope? = null
@ -54,11 +52,7 @@ class ReviewQualityCheckFeature(
appStoreScope = appStore.flowScoped { flow ->
flow.mapNotNull { it.shoppingSheetExpanded }
.distinctUntilChanged()
.drop(1) // Needed to ignore the initial emission from the Store setup
.filterNot { it }
.collect {
onBottomSheetCollapsed()
}
.collect(onBottomSheetStateChange)
}
}

@ -19,6 +19,7 @@ import org.junit.Test
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.shopping.fake.FakeShoppingExperienceFeature
class ReviewQualityCheckFeatureTest {
@ -35,7 +36,7 @@ class ReviewQualityCheckFeatureTest {
onAvailabilityChange = {
availability = it
},
onBottomSheetCollapsed = {},
onBottomSheetStateChange = {},
)
tested.start()
@ -65,7 +66,7 @@ class ReviewQualityCheckFeatureTest {
onAvailabilityChange = {
availability = it
},
onBottomSheetCollapsed = {},
onBottomSheetStateChange = {},
)
tested.start()
@ -95,7 +96,7 @@ class ReviewQualityCheckFeatureTest {
onAvailabilityChange = {
availability = it
},
onBottomSheetCollapsed = {},
onBottomSheetStateChange = {},
)
tested.start()
@ -130,7 +131,7 @@ class ReviewQualityCheckFeatureTest {
onAvailabilityChange = {
availability = it
},
onBottomSheetCollapsed = {},
onBottomSheetStateChange = {},
)
tested.start()
@ -168,7 +169,7 @@ class ReviewQualityCheckFeatureTest {
onAvailabilityChange = {
availability = it
},
onBottomSheetCollapsed = {},
onBottomSheetStateChange = {},
)
tested.start()
@ -209,7 +210,7 @@ class ReviewQualityCheckFeatureTest {
availability = it
availabilityCount++
},
onBottomSheetCollapsed = {},
onBottomSheetStateChange = {},
)
tested.start()
@ -222,20 +223,20 @@ class ReviewQualityCheckFeatureTest {
}
@Test
fun `WHEN the shopping sheet is collapsed THEN the collapsed callback is called`() {
fun `WHEN the shopping sheet is collapsed THEN the callback is called with false`() {
val appStore = AppStore(
initialState = AppState(
shoppingSheetExpanded = true,
),
)
var callbackCalled = false
var isExpanded: Boolean? = null
val tested = ReviewQualityCheckFeature(
appStore = appStore,
browserStore = BrowserStore(),
shoppingExperienceFeature = FakeShoppingExperienceFeature(),
onAvailabilityChange = {},
onBottomSheetCollapsed = {
callbackCalled = true
onBottomSheetStateChange = {
isExpanded = it
},
)
@ -243,24 +244,24 @@ class ReviewQualityCheckFeatureTest {
appStore.dispatch(AppAction.ShoppingSheetStateUpdated(expanded = false)).joinBlocking()
assertTrue(callbackCalled)
assertFalse(isExpanded!!)
}
@Test
fun `WHEN the shopping sheet is expanded THEN the collapsed callback is not called`() {
fun `WHEN the shopping sheet is expanded THEN the collapsed callback is called with true`() {
val appStore = AppStore(
initialState = AppState(
shoppingSheetExpanded = false,
),
)
var callbackCalled = false
var isExpanded: Boolean? = null
val tested = ReviewQualityCheckFeature(
appStore = appStore,
browserStore = BrowserStore(),
shoppingExperienceFeature = FakeShoppingExperienceFeature(),
onAvailabilityChange = {},
onBottomSheetCollapsed = {
callbackCalled = true
onBottomSheetStateChange = {
isExpanded = it
},
)
@ -268,14 +269,34 @@ class ReviewQualityCheckFeatureTest {
appStore.dispatch(AppAction.ShoppingSheetStateUpdated(expanded = true)).joinBlocking()
assertFalse(callbackCalled)
assertTrue(isExpanded!!)
}
}
class FakeShoppingExperienceFeature(
private val enabled: Boolean = true,
) : ShoppingExperienceFeature {
@Test
fun `WHEN the feature is restarted THEN first emission is collected to set the tint`() {
val appStore = AppStore(
initialState = AppState(
shoppingSheetExpanded = false,
),
)
var isExpanded: Boolean? = null
val tested = ReviewQualityCheckFeature(
appStore = appStore,
browserStore = BrowserStore(),
shoppingExperienceFeature = FakeShoppingExperienceFeature(),
onAvailabilityChange = {},
onBottomSheetStateChange = {
isExpanded = it
},
)
tested.start()
tested.stop()
// emulate emission
appStore.dispatch(AppAction.ShoppingSheetStateUpdated(expanded = false)).joinBlocking()
override val isEnabled: Boolean
get() = enabled
tested.start()
assertFalse(isExpanded!!)
}
}

@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.shopping.fake
import org.mozilla.fenix.shopping.ShoppingExperienceFeature
class FakeShoppingExperienceFeature(
private val enabled: Boolean = true,
) : ShoppingExperienceFeature {
override val isEnabled: Boolean
get() = enabled
}
Loading…
Cancel
Save