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

fenix/125.0
DreVla 4 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].
*
* @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.
*/
class ReviewQualityCheckBottomSheetStateFeature(
store: ReviewQualityCheckStore,
private val isScreenReaderEnabled: Boolean,
private val onRequestStateUpdate: (expanded: BottomSheetViewState) -> 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
}.map {
when (it.second) {
is ReviewQualityCheckState.NotOptedIn -> BottomSheetViewState.FULL_VIEW
else -> BottomSheetViewState.HALF_VIEW
if (isScreenReaderEnabled) {
onRequestStateUpdate(BottomSheetViewState.FULL_VIEW)
} else {
val initial = Pair<ReviewQualityCheckState?, ReviewQualityCheckState?>(null, null)
flow.scan(initial) { acc, value ->
Pair(acc.second, value)
}.filter {
it.first is ReviewQualityCheckState.Initial
}.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.BottomSheetDialogFragment
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.lazyStore
import org.mozilla.fenix.ext.requireComponents
@ -118,7 +119,10 @@ class ReviewQualityCheckFragment : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bottomSheetStateFeature.set(
feature = ReviewQualityCheckBottomSheetStateFeature(store) { bottomSheetState ->
feature = ReviewQualityCheckBottomSheetStateFeature(
store,
requireContext().isScreenReaderEnabled,
) { bottomSheetState ->
if (bottomSheetState == BottomSheetViewState.FULL_VIEW) {
behavior?.state = BottomSheetBehavior.STATE_EXPANDED
}

@ -28,6 +28,7 @@ class ReviewQualityCheckBottomSheetStateFeatureTest {
onRequestStateUpdate = {
updatedState = it
},
isScreenReaderEnabled = false,
)
tested.start()
@ -55,6 +56,7 @@ class ReviewQualityCheckBottomSheetStateFeatureTest {
onRequestStateUpdate = {
updatedState = it
},
isScreenReaderEnabled = false,
)
assertEquals(ReviewQualityCheckState.Initial, store.state)
@ -63,4 +65,31 @@ class ReviewQualityCheckBottomSheetStateFeatureTest {
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