Bug 1857544 - [a11y]Fully expand review checker when screen reader on

fenix/125.0
DreVla 5 months ago committed by mergify[bot]
parent 0e9c6b63ff
commit d20b65c304

@ -18,25 +18,31 @@ import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
* the store state changes from [ReviewQualityCheckState.Initial] to [ReviewQualityCheckState.NotOptedIn]. * the store state changes from [ReviewQualityCheckState.Initial] to [ReviewQualityCheckState.NotOptedIn].
* *
* @param store The store to observe. * @param store The store to observe.
* @param isScreenReaderEnabled Used to fully expand bottom sheet when a screen reader is on.
* @param onRequestStateUpdate Callback to request the bottom sheet to be updated. * @param onRequestStateUpdate Callback to request the bottom sheet to be updated.
*/ */
class ReviewQualityCheckBottomSheetStateFeature( class ReviewQualityCheckBottomSheetStateFeature(
store: ReviewQualityCheckStore, store: ReviewQualityCheckStore,
private val isScreenReaderEnabled: Boolean,
private val onRequestStateUpdate: (expanded: BottomSheetViewState) -> Unit, private val onRequestStateUpdate: (expanded: BottomSheetViewState) -> Unit,
) : AbstractBinding<ReviewQualityCheckState>(store) { ) : AbstractBinding<ReviewQualityCheckState>(store) {
override suspend fun onState(flow: Flow<ReviewQualityCheckState>) { override suspend fun onState(flow: Flow<ReviewQualityCheckState>) {
val initial = Pair<ReviewQualityCheckState?, ReviewQualityCheckState?>(null, null) if (isScreenReaderEnabled) {
flow.scan(initial) { acc, value -> onRequestStateUpdate(BottomSheetViewState.FULL_VIEW)
Pair(acc.second, value) } else {
}.filter { val initial = Pair<ReviewQualityCheckState?, ReviewQualityCheckState?>(null, null)
it.first is ReviewQualityCheckState.Initial flow.scan(initial) { acc, value ->
}.map { Pair(acc.second, value)
when (it.second) { }.filter {
is ReviewQualityCheckState.NotOptedIn -> BottomSheetViewState.FULL_VIEW it.first is ReviewQualityCheckState.Initial
else -> BottomSheetViewState.HALF_VIEW }.map {
when (it.second) {
is ReviewQualityCheckState.NotOptedIn -> BottomSheetViewState.FULL_VIEW
else -> BottomSheetViewState.HALF_VIEW
}
}.collect {
onRequestStateUpdate(it)
} }
}.collect {
onRequestStateUpdate(it)
} }
} }
} }

@ -21,6 +21,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.content.isScreenReaderEnabled
import org.mozilla.fenix.components.appstate.AppAction import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.lazyStore import org.mozilla.fenix.components.lazyStore
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
@ -118,7 +119,10 @@ class ReviewQualityCheckFragment : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
bottomSheetStateFeature.set( bottomSheetStateFeature.set(
feature = ReviewQualityCheckBottomSheetStateFeature(store) { bottomSheetState -> feature = ReviewQualityCheckBottomSheetStateFeature(
store,
requireContext().isScreenReaderEnabled,
) { bottomSheetState ->
if (bottomSheetState == BottomSheetViewState.FULL_VIEW) { if (bottomSheetState == BottomSheetViewState.FULL_VIEW) {
behavior?.state = BottomSheetBehavior.STATE_EXPANDED behavior?.state = BottomSheetBehavior.STATE_EXPANDED
} }

@ -28,6 +28,7 @@ class ReviewQualityCheckBottomSheetStateFeatureTest {
onRequestStateUpdate = { onRequestStateUpdate = {
updatedState = it updatedState = it
}, },
isScreenReaderEnabled = false,
) )
tested.start() tested.start()
@ -55,6 +56,7 @@ class ReviewQualityCheckBottomSheetStateFeatureTest {
onRequestStateUpdate = { onRequestStateUpdate = {
updatedState = it updatedState = it
}, },
isScreenReaderEnabled = false,
) )
assertEquals(ReviewQualityCheckState.Initial, store.state) assertEquals(ReviewQualityCheckState.Initial, store.state)
@ -63,4 +65,31 @@ class ReviewQualityCheckBottomSheetStateFeatureTest {
assertEquals(BottomSheetViewState.FULL_VIEW, updatedState) assertEquals(BottomSheetViewState.FULL_VIEW, updatedState)
} }
@Test
fun `GIVEN an accessibility screen reader is enabled WHEN user opens bottom sheet THEN it is opened fully`() {
val store = ReviewQualityCheckStore(middleware = emptyList())
var updatedState: BottomSheetViewState? = null
val tested = ReviewQualityCheckBottomSheetStateFeature(
store = store,
onRequestStateUpdate = {
updatedState = it
},
isScreenReaderEnabled = true,
)
tested.start()
store.dispatch(
ReviewQualityCheckAction.OptInCompleted(
isProductRecommendationsEnabled = true,
productRecommendationsExposure = true,
productVendor = ReviewQualityCheckState.ProductVendor.WALMART,
isHighlightsExpanded = false,
isInfoExpanded = false,
isSettingsExpanded = false,
),
).joinBlocking()
assertEquals(BottomSheetViewState.FULL_VIEW, updatedState)
}
} }

Loading…
Cancel
Save