Bug 1846713 - Improve package structure within shopping package

fenix/118.0
rahulsainani 10 months ago committed by mergify[bot]
parent f453859870
commit 01fa755817

@ -17,8 +17,8 @@ import androidx.lifecycle.lifecycleScope
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.shopping.state.ReviewQualityCheckPreferencesImpl
import org.mozilla.fenix.shopping.state.ReviewQualityCheckStore
import org.mozilla.fenix.shopping.di.ReviewQualityCheckMiddlewareProvider
import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
import org.mozilla.fenix.shopping.ui.ReviewQualityCheckBottomSheet
import org.mozilla.fenix.theme.FirefoxTheme
@ -30,10 +30,10 @@ class ReviewQualityCheckFragment : BottomSheetDialogFragment() {
private var behavior: BottomSheetBehavior<View>? = null
private val store by lazy {
ReviewQualityCheckStore(
reviewQualityCheckPreferences = ReviewQualityCheckPreferencesImpl(
requireComponents.settings,
middleware = ReviewQualityCheckMiddlewareProvider.provideMiddleware(
settings = requireComponents.settings,
scope = lifecycleScope,
),
scope = lifecycleScope,
)
}

@ -0,0 +1,39 @@
/* 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.di
import kotlinx.coroutines.CoroutineScope
import org.mozilla.fenix.shopping.middleware.ReviewQualityCheckPreferencesImpl
import org.mozilla.fenix.shopping.middleware.ReviewQualityCheckPreferencesMiddleware
import org.mozilla.fenix.shopping.store.ReviewQualityCheckMiddleware
import org.mozilla.fenix.utils.Settings
/**
* Provides middleware for review quality check store.
*/
object ReviewQualityCheckMiddlewareProvider {
/**
* Provides middlewares for review quality check feature.
*
* @param settings The [Settings] instance to use.
* @param scope The [CoroutineScope] to use for launching coroutines.
*/
fun provideMiddleware(
settings: Settings,
scope: CoroutineScope,
): List<ReviewQualityCheckMiddleware> =
listOf(providePreferencesMiddleware(settings, scope))
private fun providePreferencesMiddleware(
settings: Settings,
scope: CoroutineScope,
) = ReviewQualityCheckPreferencesMiddleware(
reviewQualityCheckPreferences = ReviewQualityCheckPreferencesImpl(
settings,
),
scope = scope,
)
}

@ -2,7 +2,7 @@
* 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.state
package org.mozilla.fenix.shopping.middleware
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@ -2,13 +2,15 @@
* 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.state
package org.mozilla.fenix.shopping.middleware
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import mozilla.components.lib.state.Middleware
import mozilla.components.lib.state.MiddlewareContext
import mozilla.components.lib.state.Store
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
import org.mozilla.fenix.shopping.store.ReviewQualityCheckMiddleware
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
/**
* Middleware for getting and setting review quality check user preferences.
@ -19,7 +21,7 @@ import mozilla.components.lib.state.Store
class ReviewQualityCheckPreferencesMiddleware(
private val reviewQualityCheckPreferences: ReviewQualityCheckPreferences,
private val scope: CoroutineScope,
) : Middleware<ReviewQualityCheckState, ReviewQualityCheckAction> {
) : ReviewQualityCheckMiddleware {
override fun invoke(
context: MiddlewareContext<ReviewQualityCheckState, ReviewQualityCheckAction>,

@ -2,7 +2,7 @@
* 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.state
package org.mozilla.fenix.shopping.store
import mozilla.components.lib.state.Action

@ -0,0 +1,12 @@
/* 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.store
import mozilla.components.lib.state.Middleware
/**
* Middleware typealias for review quality check.
*/
typealias ReviewQualityCheckMiddleware = Middleware<ReviewQualityCheckState, ReviewQualityCheckAction>

@ -2,7 +2,7 @@
* 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.state
package org.mozilla.fenix.shopping.store
import mozilla.components.lib.state.State

@ -2,25 +2,20 @@
* 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.state
package org.mozilla.fenix.shopping.store
import kotlinx.coroutines.CoroutineScope
import mozilla.components.lib.state.Store
/**
* Store for review quality check feature.
*
* @param reviewQualityCheckPreferences The [ReviewQualityCheckPreferences] instance to use.
* @param scope The [CoroutineScope] to use for launching coroutines.
* @param middleware The list of middlewares to use.
*/
class ReviewQualityCheckStore(
reviewQualityCheckPreferences: ReviewQualityCheckPreferences,
scope: CoroutineScope,
middleware: List<ReviewQualityCheckMiddleware>,
) : Store<ReviewQualityCheckState, ReviewQualityCheckAction>(
initialState = ReviewQualityCheckState.Initial,
middleware = listOf(
ReviewQualityCheckPreferencesMiddleware(reviewQualityCheckPreferences, scope),
),
middleware = middleware,
reducer = ::reducer,
) {
init {

@ -24,8 +24,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.compose.SwitchWithLabel
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.compose.button.SecondaryButton
import org.mozilla.fenix.shopping.state.ReviewQualityCheckState
import org.mozilla.fenix.shopping.state.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent
import org.mozilla.fenix.theme.FirefoxTheme
/**

@ -29,7 +29,7 @@ import androidx.compose.ui.unit.dp
import mozilla.components.ui.colors.PhotonColors
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.shopping.state.ReviewQualityCheckState.Grade
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.Grade
import org.mozilla.fenix.theme.FirefoxTheme
private val height = 24.dp

@ -10,10 +10,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import mozilla.components.lib.state.ext.observeAsState
import org.mozilla.fenix.shopping.state.ReviewQualityCheckAction
import org.mozilla.fenix.shopping.state.ReviewQualityCheckState
import org.mozilla.fenix.shopping.state.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent
import org.mozilla.fenix.shopping.state.ReviewQualityCheckStore
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent
import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
/**
* Top-level UI for the Review Quality Check feature.

@ -2,7 +2,7 @@
* 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.state
package org.mozilla.fenix.shopping.store
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.test.runTest
@ -11,6 +11,8 @@ import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.shopping.middleware.ReviewQualityCheckPreferences
import org.mozilla.fenix.shopping.middleware.ReviewQualityCheckPreferencesMiddleware
class ReviewQualityCheckStoreTest {
@ -23,10 +25,12 @@ class ReviewQualityCheckStoreTest {
fun `GIVEN the user has not opted in the feature WHEN store is created THEN state should display not opted in UI`() =
runTest {
val tested = ReviewQualityCheckStore(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = false,
middleware = provideReviewQualityCheckMiddleware(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = false,
isProductRecommendationsEnabled = false,
),
),
scope = scope,
)
dispatcher.scheduler.advanceUntilIdle()
tested.waitUntilIdle()
@ -39,11 +43,12 @@ class ReviewQualityCheckStoreTest {
fun `GIVEN the user has not opted in the feature WHEN the user opts in THEN state should display opted in UI`() =
runTest {
val tested = ReviewQualityCheckStore(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = false,
isProductRecommendationsEnabled = false,
middleware = provideReviewQualityCheckMiddleware(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = false,
isProductRecommendationsEnabled = false,
),
),
scope = scope,
)
dispatcher.scheduler.advanceUntilIdle()
tested.waitUntilIdle()
@ -59,11 +64,12 @@ class ReviewQualityCheckStoreTest {
fun `GIVEN the user has opted in the feature WHEN the user opts out THEN state should display not opted in UI`() =
runTest {
val tested = ReviewQualityCheckStore(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = true,
isProductRecommendationsEnabled = true,
middleware = provideReviewQualityCheckMiddleware(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = true,
isProductRecommendationsEnabled = true,
),
),
scope = scope,
)
dispatcher.scheduler.advanceUntilIdle()
tested.waitUntilIdle()
@ -79,11 +85,12 @@ class ReviewQualityCheckStoreTest {
fun `GIVEN the user has opted in the feature and product recommendations are off WHEN the user turns on product recommendations THEN state should reflect that`() =
runTest {
val tested = ReviewQualityCheckStore(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = true,
isProductRecommendationsEnabled = false,
middleware = provideReviewQualityCheckMiddleware(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = true,
isProductRecommendationsEnabled = false,
),
),
scope = scope,
)
dispatcher.scheduler.advanceUntilIdle()
tested.waitUntilIdle()
@ -99,11 +106,12 @@ class ReviewQualityCheckStoreTest {
fun `GIVEN the user has opted in the feature and product recommendations are on WHEN the user turns off product recommendations THEN state should reflect that`() =
runTest {
val tested = ReviewQualityCheckStore(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = true,
isProductRecommendationsEnabled = true,
middleware = provideReviewQualityCheckMiddleware(
reviewQualityCheckPreferences = FakeReviewQualityCheckPreferences(
isEnabled = true,
isProductRecommendationsEnabled = true,
),
),
scope = scope,
)
dispatcher.scheduler.advanceUntilIdle()
tested.waitUntilIdle()
@ -114,6 +122,16 @@ class ReviewQualityCheckStoreTest {
val expected = ReviewQualityCheckState.OptedIn(productRecommendationsPreference = false)
assertEquals(expected, tested.state)
}
private fun provideReviewQualityCheckMiddleware(
reviewQualityCheckPreferences: ReviewQualityCheckPreferences,
): List<ReviewQualityCheckMiddleware> =
listOf(
ReviewQualityCheckPreferencesMiddleware(
reviewQualityCheckPreferences = reviewQualityCheckPreferences,
scope = this.scope,
),
)
}
private class FakeReviewQualityCheckPreferences(
Loading…
Cancel
Save