Bug 1850610 - Fix review checker onboarding bottom sheet height
parent
1d386b729c
commit
32e8ef35a1
@ -0,0 +1,35 @@
|
||||
/* 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
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.scan
|
||||
import mozilla.components.lib.state.helpers.AbstractBinding
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
|
||||
|
||||
/**
|
||||
* View-bound feature that requests the bottom sheet to be expanded when the store state changes
|
||||
* from [ReviewQualityCheckState.Initial] to [ReviewQualityCheckState.NotOptedIn].
|
||||
*
|
||||
* @param store The store to observe.
|
||||
* @param onRequestStateExpanded Callback to request the bottom sheet to be expanded.
|
||||
*/
|
||||
class ReviewQualityCheckBottomSheetStateFeature(
|
||||
store: ReviewQualityCheckStore,
|
||||
private val onRequestStateExpanded: () -> Unit,
|
||||
) : AbstractBinding<ReviewQualityCheckState>(store) {
|
||||
override suspend fun onState(flow: Flow<ReviewQualityCheckState>) {
|
||||
val initial = Pair<ReviewQualityCheckState?, ReviewQualityCheckState?>(null, null)
|
||||
flow.scan(initial) { acc, value ->
|
||||
Pair(acc.second, value)
|
||||
}.filter {
|
||||
it.first is ReviewQualityCheckState.Initial && it.second is ReviewQualityCheckState.NotOptedIn
|
||||
}.collect {
|
||||
onRequestStateExpanded()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/* 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
|
||||
|
||||
import mozilla.components.support.test.ext.joinBlocking
|
||||
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
|
||||
|
||||
class ReviewQualityCheckBottomSheetStateFeatureTest {
|
||||
|
||||
@get:Rule
|
||||
val coroutinesTestRule = MainCoroutineRule()
|
||||
|
||||
@Test
|
||||
fun `WHEN store state changes to not opted in from any other state THEN callback is not invoked`() {
|
||||
val store = ReviewQualityCheckStore(emptyList())
|
||||
var isInvoked = false
|
||||
val tested = ReviewQualityCheckBottomSheetStateFeature(
|
||||
store = store,
|
||||
onRequestStateExpanded = {
|
||||
isInvoked = true
|
||||
},
|
||||
)
|
||||
|
||||
tested.start()
|
||||
store.dispatch(ReviewQualityCheckAction.OptInCompleted(isProductRecommendationsEnabled = true))
|
||||
.joinBlocking()
|
||||
store.dispatch(ReviewQualityCheckAction.OptOutCompleted(emptyList())).joinBlocking()
|
||||
|
||||
assertFalse(isInvoked)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN store state changes to not opted in from initial state THEN callback is invoked`() {
|
||||
val store = ReviewQualityCheckStore(emptyList())
|
||||
var isInvoked = false
|
||||
val tested = ReviewQualityCheckBottomSheetStateFeature(
|
||||
store = store,
|
||||
onRequestStateExpanded = {
|
||||
isInvoked = true
|
||||
},
|
||||
)
|
||||
assertEquals(ReviewQualityCheckState.Initial, store.state)
|
||||
|
||||
tested.start()
|
||||
store.dispatch(ReviewQualityCheckAction.OptOutCompleted(emptyList())).joinBlocking()
|
||||
|
||||
assertTrue(isInvoked)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue