From 6aa3169496e2c587cd3c48f3fb9952f84ff4661f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 27 Mar 2024 16:16:06 +0100 Subject: [PATCH] Track NotificationTroubleshoot --- .../troubleshoot/TroubleshootTestSuite.kt | 13 +++++++++++++ .../TroubleshootNotificationsPresenterTests.kt | 2 ++ 2 files changed, 15 insertions(+) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootTestSuite.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootTestSuite.kt index 4996d278de..41fad1c3d5 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootTestSuite.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootTestSuite.kt @@ -16,11 +16,13 @@ package io.element.android.features.preferences.impl.notifications.troubleshoot +import im.vector.app.features.analytics.plan.NotificationTroubleshoot import io.element.android.libraries.architecture.AsyncAction import io.element.android.libraries.core.notifications.NotificationTroubleshootTest import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState import io.element.android.libraries.core.notifications.TestFilterData import io.element.android.libraries.push.api.GetCurrentPushProvider +import io.element.android.services.analytics.api.AnalyticsService import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow @@ -32,6 +34,7 @@ import javax.inject.Inject class TroubleshootTestSuite @Inject constructor( private val notificationTroubleshootTests: Set<@JvmSuppressWildcards NotificationTroubleshootTest>, private val getCurrentPushProvider: GetCurrentPushProvider, + private val analyticsService: AnalyticsService, ) { lateinit var tests: List @@ -77,6 +80,16 @@ class TroubleshootTestSuite @Inject constructor( private fun emitState() { val states = tests.map { it.state.value } + val mainState = states.computeMainState() + when (mainState) { + is AsyncAction.Success -> { + analyticsService.capture(NotificationTroubleshoot(hasError = false)) + } + is AsyncAction.Failure -> { + analyticsService.capture(NotificationTroubleshoot(hasError = true)) + } + else -> Unit + } _state.tryEmit( TroubleshootTestSuiteState( mainState = states.computeMainState(), diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootNotificationsPresenterTests.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootNotificationsPresenterTests.kt index e6e712b1b8..686aac2e56 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootNotificationsPresenterTests.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/TroubleshootNotificationsPresenterTests.kt @@ -24,6 +24,7 @@ import io.element.android.libraries.architecture.AsyncAction import io.element.android.libraries.core.notifications.NotificationTroubleshootTest import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState import io.element.android.libraries.push.test.FakeGetCurrentPushProvider +import io.element.android.services.analytics.test.FakeAnalyticsService import kotlinx.coroutines.test.runTest import org.junit.Test @@ -113,6 +114,7 @@ class TroubleshootNotificationsPresenterTests { return TroubleshootTestSuite( notificationTroubleshootTests = tests, getCurrentPushProvider = FakeGetCurrentPushProvider(currentPushProvider), + analyticsService = FakeAnalyticsService(), ) }