Track NotificationTroubleshoot

This commit is contained in:
Benoit Marty 2024-03-27 16:16:06 +01:00 committed by Benoit Marty
parent ef48c2b5a3
commit 8da435b514
2 changed files with 15 additions and 0 deletions

View file

@ -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<NotificationTroubleshootTest>
@ -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(),

View file

@ -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(),
)
}