Bug 1847922 - Update ReviewQualityCheckState for NoAnalysisPresent and AnalysisPresent cases

fenix/118.0
rahulsainani 10 months ago committed by mergify[bot]
parent b004af3611
commit d57d5b6972

@ -6,6 +6,7 @@ package org.mozilla.fenix.shopping.store
import mozilla.components.lib.state.State
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.HighlightType
import java.util.SortedMap
private const val NUMBER_OF_HIGHLIGHTS_FOR_COMPACT_MODE = 2
@ -51,12 +52,8 @@ sealed interface ReviewQualityCheckState : State {
/**
* Denotes no analysis is present for the product the user is browsing.
*
* @property productUrl The url of the product the user is browsing.
*/
data class NoAnalysisPresent(
val productUrl: String,
) : ProductReviewState
object NoAnalysisPresent : ProductReviewState
/**
* Denotes the state where analysis of the product is fetched and present.
@ -72,13 +69,20 @@ sealed interface ReviewQualityCheckState : State {
*/
data class AnalysisPresent(
val productId: String,
val reviewGrade: Grade,
val reviewGrade: Grade?,
val needsAnalysis: Boolean,
val adjustedRating: Float,
val adjustedRating: Float?,
val productUrl: String,
val highlights: Map<HighlightType, List<String>>?,
val highlights: SortedMap<HighlightType, List<String>>?,
val recommendedProductState: RecommendedProductState = RecommendedProductState.Initial,
) : ProductReviewState
) : ProductReviewState {
init {
require(!(highlights == null && reviewGrade == null && adjustedRating == null)) {
"AnalysisPresent state should only be created when at least one of " +
"reviewGrade, adjustedRating or highlights is not null"
}
}
}
}
}
@ -158,7 +162,7 @@ private val fakeAnalysis = ReviewQualityCheckState.OptedIn.ProductReviewState.An
needsAnalysis = false,
adjustedRating = 3.6f,
productUrl = "123",
highlights = mapOf(
highlights = sortedMapOf(
HighlightType.QUALITY to listOf(
"High quality",
"Excellent craftsmanship",

@ -65,15 +65,19 @@ fun ProductAnalysis(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
ReviewGradeCard(
reviewGrade = productAnalysis.reviewGrade,
modifier = Modifier.fillMaxWidth(),
)
if (productAnalysis.reviewGrade != null) {
ReviewGradeCard(
reviewGrade = productAnalysis.reviewGrade,
modifier = Modifier.fillMaxWidth(),
)
}
AdjustedProductRatingCard(
rating = productAnalysis.adjustedRating,
modifier = Modifier.fillMaxWidth(),
)
if (productAnalysis.adjustedRating != null) {
AdjustedProductRatingCard(
rating = productAnalysis.adjustedRating,
modifier = Modifier.fillMaxWidth(),
)
}
if (productAnalysis.highlights != null) {
HighlightsCard(
@ -356,7 +360,7 @@ private fun ProductAnalysisPreview() {
needsAnalysis = false,
adjustedRating = 3.6f,
productUrl = "123",
highlights = mapOf(
highlights = sortedMapOf(
HighlightType.QUALITY to listOf(
"High quality",
"Excellent craftsmanship",

@ -5,7 +5,9 @@
package org.mozilla.fenix.shopping.store
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState.OptedIn.ProductReviewState.AnalysisPresent
class ReviewQualityCheckStateTest {
@ -65,4 +67,60 @@ class ReviewQualityCheckStateTest {
assertEquals(expected, highlights.forCompactMode())
}
@Test
fun `WHEN AnalysisPresent is created with grade, rating and highlights as null THEN exception is thrown`() {
assertThrows(IllegalArgumentException::class.java) {
AnalysisPresent(
productId = "",
reviewGrade = null,
needsAnalysis = false,
adjustedRating = null,
productUrl = "",
highlights = null,
)
}
}
@Test
fun `WHEN AnalysisPresent is created with at least one of grade, rating and highlights as not null THEN no exception is thrown`() {
val ratingPresent = kotlin.runCatching {
AnalysisPresent(
productId = "1",
reviewGrade = null,
needsAnalysis = false,
adjustedRating = 1.2f,
productUrl = "",
highlights = null,
)
}
val gradePresent = kotlin.runCatching {
AnalysisPresent(
productId = "2",
reviewGrade = ReviewQualityCheckState.Grade.A,
needsAnalysis = false,
adjustedRating = null,
productUrl = "",
highlights = null,
)
}
val highlightsPresent = kotlin.runCatching {
AnalysisPresent(
productId = "2",
reviewGrade = null,
needsAnalysis = false,
adjustedRating = null,
productUrl = "",
highlights = sortedMapOf(
ReviewQualityCheckState.HighlightType.QUALITY to listOf(""),
),
)
}
assert(ratingPresent.isSuccess)
assert(gradePresent.isSuccess)
assert(highlightsPresent.isSuccess)
}
}

Loading…
Cancel
Save