Bug 1843508 - Part 1: Add review quality check feature telemetry events
parent
65f42ae719
commit
1ec1a4fd11
@ -0,0 +1,97 @@
|
||||
/* 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.middleware
|
||||
|
||||
import mozilla.components.lib.state.MiddlewareContext
|
||||
import org.mozilla.fenix.GleanMetrics.Shopping
|
||||
import org.mozilla.fenix.GleanMetrics.ShoppingSettings
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckMiddleware
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
|
||||
|
||||
/**
|
||||
* Middleware that captures telemetry events for the review quality check feature.
|
||||
*/
|
||||
class ReviewQualityCheckTelemetryMiddleware : ReviewQualityCheckMiddleware {
|
||||
|
||||
override fun invoke(
|
||||
context: MiddlewareContext<ReviewQualityCheckState, ReviewQualityCheckAction>,
|
||||
next: (ReviewQualityCheckAction) -> Unit,
|
||||
action: ReviewQualityCheckAction,
|
||||
) {
|
||||
next(action)
|
||||
|
||||
when (action) {
|
||||
is ReviewQualityCheckAction.TelemetryAction -> processAction(action)
|
||||
else -> {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun processAction(
|
||||
action: ReviewQualityCheckAction.TelemetryAction,
|
||||
) = when (action) {
|
||||
is ReviewQualityCheckAction.OptIn -> {
|
||||
Shopping.surfaceOptInAccepted.record()
|
||||
ShoppingSettings.userHasOnboarded.set(true)
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.OptOut -> {
|
||||
ShoppingSettings.componentOptedOut.set(true)
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.BottomSheetClosed -> Shopping.surfaceClosed.record()
|
||||
|
||||
is ReviewQualityCheckAction.BottomSheetDisplayed -> Shopping.surfaceDisplayed.record()
|
||||
|
||||
is ReviewQualityCheckAction.OpenExplainerLearnMoreLink -> {
|
||||
Shopping.surfaceReviewQualityExplainerUrlClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.OpenOnboardingLearnMoreLink -> {
|
||||
Shopping.surfaceLearnMoreClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.OpenOnboardingPrivacyPolicyLink -> {
|
||||
Shopping.surfaceShowPrivacyPolicyClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.OpenOnboardingTermsLink -> {
|
||||
Shopping.surfaceShowTermsClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.NotNowClicked -> {
|
||||
Shopping.surfaceNotNowClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.ShowMoreRecentReviewsClicked -> {
|
||||
Shopping.surfaceShowMoreRecentReviewsClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.ExpandSettingsClicked -> {
|
||||
Shopping.surfaceExpandSettings.record()
|
||||
}
|
||||
is ReviewQualityCheckAction.NoAnalysisDisplayed -> {
|
||||
Shopping.surfaceNoReviewReliabilityAvailable.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.AnalyzeProduct -> {
|
||||
Shopping.surfaceAnalyzeReviewsNoneAvailableClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.ReanalyzeProduct -> {
|
||||
Shopping.surfaceReanalyzeClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.ReportProductBackInStock -> {
|
||||
Shopping.surfaceReactivatedButtonClicked.record()
|
||||
}
|
||||
|
||||
is ReviewQualityCheckAction.OptOutCompleted -> {
|
||||
Shopping.surfaceOnboardingDisplayed.record()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
/* 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.middleware
|
||||
|
||||
import mozilla.components.service.glean.testing.GleanTestRule
|
||||
import mozilla.components.support.test.ext.joinBlocking
|
||||
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.GleanMetrics.Shopping
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
|
||||
import org.mozilla.fenix.shopping.store.ReviewQualityCheckStore
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class ReviewQualityCheckTelemetryMiddlewareTest {
|
||||
|
||||
@get:Rule
|
||||
val gleanTestRule = GleanTestRule(testContext)
|
||||
|
||||
private lateinit var store: ReviewQualityCheckStore
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
store = ReviewQualityCheckStore(
|
||||
middleware = listOf(
|
||||
ReviewQualityCheckTelemetryMiddleware(),
|
||||
),
|
||||
)
|
||||
store.waitUntilIdle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the user opts in the feature THEN the opt in event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.OptIn).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceOptInAccepted.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the bottom sheet is closed THEN the bottom sheet closed event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.BottomSheetClosed).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceClosed.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the bottom sheet is displayed THEN the bottom sheet displayed event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.BottomSheetDisplayed).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceDisplayed.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the learn more link from the explainer card is clicked THEN the explainer learn more event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.OpenExplainerLearnMoreLink).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceReviewQualityExplainerUrlClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the terms and conditions link from the onboarding card is clicked THEN the terms and conditions event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.OpenOnboardingTermsLink).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceShowTermsClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the privacy policy link from the onboarding card is clicked THEN the privacy policy event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.OpenOnboardingPrivacyPolicyLink).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceShowPrivacyPolicyClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the learn more link from the onboarding card is clicked THEN the onboarding learn more event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.OpenOnboardingLearnMoreLink).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceLearnMoreClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the not now button from the onboarding card is clicked THEN the not now event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.NotNowClicked).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceNotNowClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the expand button from the highlights card is clicked THEN the show more recent reviews event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.ShowMoreRecentReviewsClicked).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceShowMoreRecentReviewsClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the expand button from the settings card is clicked THEN the settings expand event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.ExpandSettingsClicked).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceExpandSettings.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN no analysis is present THEN the no analysis event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.NoAnalysisDisplayed).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceNoReviewReliabilityAvailable.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN analyze button is clicked THEN the analyze reviews event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.AnalyzeProduct).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceAnalyzeReviewsNoneAvailableClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN reanalyze button is clicked THEN the reanalyze event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.ReanalyzeProduct).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceReanalyzeClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN back in stock button is clicked THEN the reactivate event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.ReportProductBackInStock).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceReactivatedButtonClicked.testGetValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the user is opted out after initializing the feature after THEN the onboarding displayed event is recorded`() {
|
||||
store.dispatch(ReviewQualityCheckAction.OptOutCompleted(emptyList())).joinBlocking()
|
||||
store.waitUntilIdle()
|
||||
|
||||
assertNotNull(Shopping.surfaceOnboardingDisplayed.testGetValue())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue