From c4d7d42141c364e0cbb8aaafa7855a080a47c472 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 22 Sep 2025 20:12:26 +0200 Subject: [PATCH 1/7] Add notification troubleshoot test about blocked users. --- .../preferences/impl/PreferencesFlowNode.kt | 4 + libraries/permissions/impl/build.gradle.kts | 1 + ...ficationTroubleshootCheckPermissionTest.kt | 6 +- ...tionTroubleshootCheckPermissionTestTest.kt | 3 +- libraries/push/impl/build.gradle.kts | 1 + .../impl/troubleshoot/IgnoredUsersTest.kt | 69 ++++++++++++++ .../impl/troubleshoot/PushLoopbackTest.kt | 6 +- .../impl/src/main/res/values/localazy.xml | 8 ++ .../impl/troubleshoot/IgnoredUsersTestTest.kt | 93 +++++++++++++++++++ .../impl/troubleshoot/PushLoopbackTestTest.kt | 3 +- .../pushproviders/firebase/build.gradle.kts | 1 + .../troubleshoot/FirebaseTokenTest.kt | 6 +- .../troubleshoot/FirebaseTokenTestTest.kt | 3 +- .../unifiedpush/build.gradle.kts | 1 + .../troubleshoot/UnifiedPushTest.kt | 6 +- .../troubleshoot/UnifiedPushTestTest.kt | 3 +- .../api/NotificationTroubleShootEntryPoint.kt | 1 + .../test/NotificationTroubleshootNavigator.kt | 12 +++ .../api/test/NotificationTroubleshootTest.kt | 5 +- .../test/NotificationTroubleshootTestState.kt | 6 +- .../impl/TroubleshootNotificationsNode.kt | 16 +++- .../TroubleshootNotificationsPresenter.kt | 15 ++- .../TroubleshootNotificationsStateProvider.kt | 19 +++- .../impl/TroubleshootNotificationsView.kt | 18 ++-- .../impl/TroubleshootTestSuite.kt | 11 ++- ...tNotificationTroubleShootEntryPointTest.kt | 3 +- .../impl/FakeNotificationTroubleshootTest.kt | 6 +- .../TroubleshootNotificationsPresenterTest.kt | 6 ++ libraries/troubleshoot/test/build.gradle.kts | 18 ++++ .../FakeNotificationTroubleshootNavigator.kt | 17 ++++ tools/localazy/config.json | 1 + 31 files changed, 338 insertions(+), 30 deletions(-) create mode 100644 libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTest.kt create mode 100644 libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt create mode 100644 libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootNavigator.kt create mode 100644 libraries/troubleshoot/test/build.gradle.kts create mode 100644 libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/FakeNotificationTroubleshootNavigator.kt diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt index 57643e3931..49e297af08 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/PreferencesFlowNode.kt @@ -208,6 +208,10 @@ class PreferencesFlowNode( navigateUp() } } + + override fun openIgnoredUsers() { + backstack.push(NavTarget.BlockedUsers) + } }) .build() } diff --git a/libraries/permissions/impl/build.gradle.kts b/libraries/permissions/impl/build.gradle.kts index f7811c649d..a4fafda599 100644 --- a/libraries/permissions/impl/build.gradle.kts +++ b/libraries/permissions/impl/build.gradle.kts @@ -43,5 +43,6 @@ dependencies { testCommonDependencies(libs) testImplementation(projects.libraries.matrix.test) testImplementation(projects.libraries.permissions.test) + testImplementation(projects.libraries.troubleshoot.test) testImplementation(projects.services.toolbox.test) } diff --git a/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt b/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt index 19cedab019..eeadb5598c 100644 --- a/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt +++ b/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt @@ -15,6 +15,7 @@ import dev.zacsweers.metro.Inject import io.element.android.libraries.permissions.api.PermissionStateProvider import io.element.android.libraries.permissions.impl.R import io.element.android.libraries.permissions.impl.action.PermissionActions +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState @@ -54,7 +55,10 @@ class NotificationTroubleshootCheckPermissionTest( override suspend fun reset() = delegate.reset() - override suspend fun quickFix(coroutineScope: CoroutineScope) { + override suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { // Do not bother about asking the permission inline, just lead the user to the settings permissionActions.openSettings() } diff --git a/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt b/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt index a530b8dbee..f6696265bc 100644 --- a/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt +++ b/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt @@ -13,6 +13,7 @@ import com.google.common.truth.Truth.assertThat import io.element.android.libraries.permissions.impl.action.FakePermissionActions import io.element.android.libraries.permissions.test.FakePermissionStateProvider import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator import io.element.android.services.toolbox.test.sdk.FakeBuildVersionSdkIntProvider import io.element.android.services.toolbox.test.strings.FakeStringProvider import kotlinx.coroutines.launch @@ -84,7 +85,7 @@ class NotificationTroubleshootCheckPermissionTestTest { assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) // Quick fix launch { - sut.quickFix(this) + sut.quickFix(this, FakeNotificationTroubleshootNavigator()) // Run the test again (IRL it will be done thanks to the resuming of the application) sut.run(this) } diff --git a/libraries/push/impl/build.gradle.kts b/libraries/push/impl/build.gradle.kts index 3e186d31da..fa0f65cb8f 100644 --- a/libraries/push/impl/build.gradle.kts +++ b/libraries/push/impl/build.gradle.kts @@ -72,6 +72,7 @@ dependencies { testImplementation(projects.libraries.push.test) testImplementation(projects.libraries.pushproviders.test) testImplementation(projects.libraries.pushstore.test) + testImplementation(projects.libraries.troubleshoot.test) testImplementation(projects.features.call.test) testImplementation(projects.features.lockscreen.test) testImplementation(projects.services.appnavstate.test) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTest.kt new file mode 100644 index 0000000000..93e855c94d --- /dev/null +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTest.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.libraries.push.impl.troubleshoot + +import dev.zacsweers.metro.ContributesIntoSet +import dev.zacsweers.metro.Inject +import io.element.android.libraries.di.SessionScope +import io.element.android.libraries.matrix.api.MatrixClient +import io.element.android.libraries.push.impl.R +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.services.toolbox.api.strings.StringProvider +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.StateFlow + +@ContributesIntoSet(SessionScope::class) +@Inject +class IgnoredUsersTest( + private val matrixClient: MatrixClient, + private val stringProvider: StringProvider, +) : NotificationTroubleshootTest { + override val order = 80 + private val delegate = NotificationTroubleshootTestDelegate( + defaultName = stringProvider.getString(R.string.troubleshoot_notifications_test_blocked_users_title), + defaultDescription = stringProvider.getString(R.string.troubleshoot_notifications_test_blocked_users_description), + fakeDelay = NotificationTroubleshootTestDelegate.SHORT_DELAY, + ) + override val state: StateFlow = delegate.state + + override suspend fun run(coroutineScope: CoroutineScope) { + delegate.start() + val ignorerUsers = matrixClient.ignoredUsersFlow.value + if (ignorerUsers.isEmpty()) { + delegate.updateState( + description = stringProvider.getString(R.string.troubleshoot_notifications_test_blocked_users_result_none), + status = NotificationTroubleshootTestState.Status.Success, + ) + } else { + delegate.updateState( + description = stringProvider.getQuantityString( + R.plurals.troubleshoot_notifications_test_blocked_users_result_some, + ignorerUsers.size, + ignorerUsers.size + ), + status = NotificationTroubleshootTestState.Status.Failure( + hasQuickFix = true, + isCritical = false, + quickFixButtonString = stringProvider.getString(R.string.troubleshoot_notifications_test_blocked_users_quick_fix), + ), + ) + } + } + + override suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { + navigator.openIgnoredUsers() + } + + override suspend fun reset() = delegate.reset() +} diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt index fede1a7099..3845b68b18 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt @@ -13,6 +13,7 @@ import dev.zacsweers.metro.Inject import io.element.android.libraries.push.api.PushService import io.element.android.libraries.push.api.gateway.PushGatewayFailure import io.element.android.libraries.push.impl.R +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState @@ -99,7 +100,10 @@ class PushLoopbackTest( ) } - override suspend fun quickFix(coroutineScope: CoroutineScope) { + override suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { delegate.start() pushService.getCurrentPushProvider()?.rotateToken() run(coroutineScope) diff --git a/libraries/push/impl/src/main/res/values/localazy.xml b/libraries/push/impl/src/main/res/values/localazy.xml index 069183a3a2..8e9da34b73 100644 --- a/libraries/push/impl/src/main/res/values/localazy.xml +++ b/libraries/push/impl/src/main/res/values/localazy.xml @@ -54,6 +54,14 @@ "Background synchronization" "Google Services" "No valid Google Play Services found. Notifications may not work properly." + "Checking blocked users" + "View blocked users" + "No users are blocked." + + "You blocked %1$d user. You will not receive notifications for this user." + "You blocked %1$d users. You will not receive notifications for these users." + + "Blocked users" "Get the name of the current provider." "No push providers selected." "Current push provider: %1$s." diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt new file mode 100644 index 0000000000..ed1cf93fce --- /dev/null +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt @@ -0,0 +1,93 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.libraries.push.impl.troubleshoot + +import app.cash.turbine.test +import com.google.common.truth.Truth.assertThat +import io.element.android.libraries.matrix.test.A_USER_ID +import io.element.android.libraries.matrix.test.A_USER_ID_2 +import io.element.android.libraries.matrix.test.FakeMatrixClient +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.services.toolbox.test.strings.FakeStringProvider +import io.element.android.tests.testutils.lambda.lambdaRecorder +import kotlinx.collections.immutable.persistentListOf +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class IgnoredUsersTestTest { + @Test + fun `test IgnoredUsersTest order`() = runTest { + val sut = IgnoredUsersTest( + matrixClient = FakeMatrixClient(), + stringProvider = FakeStringProvider(), + ) + assertThat(sut.order).isEqualTo(80) + } + + @Test + fun `test IgnoredUsersTest quick fix`() = runTest { + val sut = IgnoredUsersTest( + matrixClient = FakeMatrixClient(), + stringProvider = FakeStringProvider(), + ) + val openIgnoredUsersResult = lambdaRecorder {} + val navigator = object : NotificationTroubleshootNavigator { + override fun openIgnoredUsers() = openIgnoredUsersResult() + } + sut.quickFix( + coroutineScope = backgroundScope, + navigator = navigator, + ) + openIgnoredUsersResult.assertions().isCalledOnce() + } + + @Test + fun `test IgnoredUsersTest with no blocked users`() = runTest { + val sut = IgnoredUsersTest( + matrixClient = FakeMatrixClient( + ignoredUsersFlow = MutableStateFlow(persistentListOf()) + ), + stringProvider = FakeStringProvider(), + ) + backgroundScope.launch { + sut.run(this) + } + sut.state.test { + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) + val lastItem = awaitItem() + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Success) + } + } + + @Test + fun `test IgnoredUsersTest with blocked users`() = runTest { + val sut = IgnoredUsersTest( + matrixClient = FakeMatrixClient( + ignoredUsersFlow = MutableStateFlow(persistentListOf(A_USER_ID, A_USER_ID_2)) + ), + stringProvider = FakeStringProvider(), + ) + backgroundScope.launch { + sut.run(this) + } + sut.state.test { + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) + val lastItem = awaitItem() + val lastStatus = lastItem.status as NotificationTroubleshootTestState.Status.Failure + assertThat(lastStatus.hasQuickFix).isTrue() + assertThat(lastStatus.isCritical).isFalse() + assertThat(lastStatus.quickFixButtonString).isNotNull() + assertThat(lastItem.description).contains("2") + } + } +} diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt index e4fa26a28b..182ffd89a8 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt @@ -15,6 +15,7 @@ import io.element.android.libraries.push.api.gateway.PushGatewayFailure import io.element.android.libraries.push.test.FakePushService import io.element.android.libraries.pushproviders.test.FakePushProvider import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator import io.element.android.services.toolbox.test.strings.FakeStringProvider import io.element.android.services.toolbox.test.systemclock.FakeSystemClock import io.element.android.tests.testutils.lambda.lambdaRecorder @@ -97,7 +98,7 @@ class PushLoopbackTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) - sut.quickFix(this) + sut.quickFix(this, FakeNotificationTroubleshootNavigator()) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) rotateTokenLambda.assertions().isCalledOnce() diff --git a/libraries/pushproviders/firebase/build.gradle.kts b/libraries/pushproviders/firebase/build.gradle.kts index acb12ae150..05e60920e5 100644 --- a/libraries/pushproviders/firebase/build.gradle.kts +++ b/libraries/pushproviders/firebase/build.gradle.kts @@ -76,5 +76,6 @@ dependencies { testImplementation(projects.libraries.push.test) testImplementation(projects.libraries.pushstore.test) testImplementation(projects.libraries.sessionStorage.test) + testImplementation(projects.libraries.troubleshoot.test) testImplementation(projects.services.toolbox.test) } diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt index 2d6ec699da..ae70114971 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt @@ -14,6 +14,7 @@ import io.element.android.libraries.pushproviders.firebase.FirebaseConfig import io.element.android.libraries.pushproviders.firebase.FirebaseStore import io.element.android.libraries.pushproviders.firebase.FirebaseTroubleshooter import io.element.android.libraries.pushproviders.firebase.R +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState @@ -71,7 +72,10 @@ class FirebaseTokenTest( override suspend fun reset() = delegate.reset() - override suspend fun quickFix(coroutineScope: CoroutineScope) { + override suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { delegate.start() firebaseTroubleshooter.troubleshoot() run(coroutineScope) diff --git a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt index b66f094d76..b7a39feb9f 100644 --- a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt +++ b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt @@ -14,6 +14,7 @@ import io.element.android.libraries.pushproviders.firebase.FirebaseConfig import io.element.android.libraries.pushproviders.firebase.InMemoryFirebaseStore import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData +import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator import io.element.android.services.toolbox.test.strings.FakeStringProvider import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest @@ -62,7 +63,7 @@ class FirebaseTokenTestTest { val lastItem = awaitItem() assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) // Quick fix - sut.quickFix(this) + sut.quickFix(this, FakeNotificationTroubleshootNavigator()) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Success) } diff --git a/libraries/pushproviders/unifiedpush/build.gradle.kts b/libraries/pushproviders/unifiedpush/build.gradle.kts index c2ec6b3d1c..e416ccf8bf 100644 --- a/libraries/pushproviders/unifiedpush/build.gradle.kts +++ b/libraries/pushproviders/unifiedpush/build.gradle.kts @@ -51,6 +51,7 @@ dependencies { testImplementation(projects.libraries.push.test) testImplementation(projects.libraries.pushproviders.test) testImplementation(projects.libraries.pushstore.test) + testImplementation(projects.libraries.troubleshoot.test) testImplementation(projects.services.toolbox.test) testImplementation(projects.services.appnavstate.test) } diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt index 40f8115fd6..6791a901db 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt @@ -13,6 +13,7 @@ import dev.zacsweers.metro.Inject import io.element.android.libraries.pushproviders.unifiedpush.R import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushDistributorProvider +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState @@ -64,7 +65,10 @@ class UnifiedPushTest( override suspend fun reset() = delegate.reset() - override suspend fun quickFix(coroutineScope: CoroutineScope) { + override suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { openDistributorWebPageAction.execute() } } diff --git a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt index 7b9059a324..53d85c7fea 100644 --- a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt +++ b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt @@ -13,6 +13,7 @@ import io.element.android.libraries.pushproviders.api.Distributor import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData +import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator import io.element.android.services.toolbox.test.strings.FakeStringProvider import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest @@ -67,7 +68,7 @@ class UnifiedPushTestTest { assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) // Quick fix launch { - sut.quickFix(this) + sut.quickFix(this, FakeNotificationTroubleshootNavigator()) sut.run(this) } assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) diff --git a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/NotificationTroubleShootEntryPoint.kt b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/NotificationTroubleShootEntryPoint.kt index bc3b019ba3..bf0c6bb883 100644 --- a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/NotificationTroubleShootEntryPoint.kt +++ b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/NotificationTroubleShootEntryPoint.kt @@ -22,5 +22,6 @@ interface NotificationTroubleShootEntryPoint : FeatureEntryPoint { interface Callback : Plugin { fun onDone() + fun openIgnoredUsers() } } diff --git a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootNavigator.kt b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootNavigator.kt new file mode 100644 index 0000000000..0cce358072 --- /dev/null +++ b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootNavigator.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.libraries.troubleshoot.api.test + +interface NotificationTroubleshootNavigator { + fun openIgnoredUsers() +} diff --git a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTest.kt b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTest.kt index d20370729e..f729cd3300 100644 --- a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTest.kt +++ b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTest.kt @@ -16,7 +16,10 @@ interface NotificationTroubleshootTest { fun isRelevant(data: TestFilterData): Boolean = true suspend fun run(coroutineScope: CoroutineScope) suspend fun reset() - suspend fun quickFix(coroutineScope: CoroutineScope) { + suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { error("Quick fix not implemented, you need to override this method in your test") } } diff --git a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt index d845332df3..ffb6d9a26a 100644 --- a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt +++ b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt @@ -17,6 +17,10 @@ data class NotificationTroubleshootTestState( data object InProgress : Status data object WaitingForUser : Status data object Success : Status - data class Failure(val hasQuickFix: Boolean) : Status + data class Failure( + val hasQuickFix: Boolean, + val isCritical: Boolean = true, + val quickFixButtonString: String? = null, + ) : Status } } diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsNode.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsNode.kt index 1d113aee64..fcd9306171 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsNode.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsNode.kt @@ -19,6 +19,7 @@ import im.vector.app.features.analytics.plan.MobileScreen import io.element.android.annotations.ContributesNode import io.element.android.libraries.di.SessionScope import io.element.android.libraries.troubleshoot.api.NotificationTroubleShootEntryPoint +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.services.analytics.api.ScreenTracker @ContributesNode(SessionScope::class) @@ -26,15 +27,26 @@ import io.element.android.services.analytics.api.ScreenTracker class TroubleshootNotificationsNode( @Assisted buildContext: BuildContext, @Assisted plugins: List, - private val presenter: TroubleshootNotificationsPresenter, private val screenTracker: ScreenTracker, -) : Node(buildContext, plugins = plugins) { + factory: TroubleshootNotificationsPresenter.Factory, +) : Node(buildContext, plugins = plugins), + NotificationTroubleshootNavigator { + private val presenter = factory.create( + navigator = this, + ) + private fun onDone() { plugins().forEach { it.onDone() } } + override fun openIgnoredUsers() { + plugins().forEach { + it.openIgnoredUsers() + } + } + @Composable override fun View(modifier: Modifier) { screenTracker.TrackScreen(MobileScreen.ScreenName.NotificationTroubleshoot) diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenter.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenter.kt index 753949f71b..b1c3c2d9b9 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenter.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenter.kt @@ -12,14 +12,23 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope +import dev.zacsweers.metro.Assisted +import dev.zacsweers.metro.AssistedFactory import dev.zacsweers.metro.Inject import io.element.android.libraries.architecture.Presenter +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import kotlinx.coroutines.launch @Inject class TroubleshootNotificationsPresenter( + @Assisted private val navigator: NotificationTroubleshootNavigator, private val troubleshootTestSuite: TroubleshootTestSuite, ) : Presenter { + @AssistedFactory + fun interface Factory { + fun create(navigator: NotificationTroubleshootNavigator): TroubleshootNotificationsPresenter + } + @Composable override fun present(): TroubleshootNotificationsState { val coroutineScope = rememberCoroutineScope() @@ -34,7 +43,11 @@ class TroubleshootNotificationsPresenter( troubleshootTestSuite.runTestSuite(this) } is TroubleshootNotificationsEvents.QuickFix -> coroutineScope.launch { - troubleshootTestSuite.quickFix(event.testIndex, this) + troubleshootTestSuite.quickFix( + testIndex = event.testIndex, + coroutineScope = this, + navigator = navigator, + ) } TroubleshootNotificationsEvents.RetryFailedTests -> coroutineScope.launch { troubleshootTestSuite.retryFailedTest(this) diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsStateProvider.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsStateProvider.kt index 4ea9355a8c..8c2708ed9d 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsStateProvider.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsStateProvider.kt @@ -31,8 +31,12 @@ open class TroubleshootNotificationsStateProvider : PreviewParameterProvider Unit, ) { - if ((testState.status as? Status.Idle)?.visible == false) return + val status = testState.status + if ((status as? Status.Idle)?.visible == false) return ListItem( headlineContent = { Text(text = testState.name) }, supportingContent = { Text(text = testState.description) }, - trailingContent = when (testState.status) { + trailingContent = when (status) { is Status.Idle -> null Status.InProgress -> ListItemContent.Custom { CircularProgressIndicator( @@ -98,20 +99,19 @@ private fun ColumnScope.TroubleshootTestView( Icon( contentDescription = null, modifier = Modifier.size(24.dp), - imageVector = CompoundIcons.ErrorSolid(), - tint = ElementTheme.colors.textCriticalPrimary + imageVector = if (status.isCritical) CompoundIcons.ErrorSolid() else CompoundIcons.Warning(), + tint = ElementTheme.colors.iconCriticalPrimary, ) } } ) - if ((testState.status as? Status.Failure)?.hasQuickFix == true) { + if (status is Status.Failure && status.hasQuickFix) { ListItem( - headlineContent = { - }, + headlineContent = { }, trailingContent = ListItemContent.Custom { Button( - text = stringResource(id = R.string.troubleshoot_notifications_screen_quick_fix_action), - onClick = onQuickFixClick + text = status.quickFixButtonString ?: stringResource(id = R.string.troubleshoot_notifications_screen_quick_fix_action), + onClick = onQuickFixClick, ) } ) diff --git a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootTestSuite.kt b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootTestSuite.kt index d0fd005307..c26510fc92 100644 --- a/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootTestSuite.kt +++ b/libraries/troubleshoot/impl/src/main/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootTestSuite.kt @@ -11,6 +11,7 @@ import dev.zacsweers.metro.Inject import im.vector.app.features.analytics.plan.NotificationTroubleshoot import io.element.android.libraries.architecture.AsyncAction import io.element.android.libraries.push.api.GetCurrentPushProvider +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData @@ -90,8 +91,12 @@ class TroubleshootTestSuite( ) } - suspend fun quickFix(testIndex: Int, coroutineScope: CoroutineScope) { - tests[testIndex].quickFix(coroutineScope) + suspend fun quickFix( + testIndex: Int, + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { + tests[testIndex].quickFix(coroutineScope, navigator) } } @@ -104,7 +109,7 @@ fun List.computeMainState(): AsyncAction { if (any { it.status is NotificationTroubleshootTestState.Status.WaitingForUser }) { AsyncAction.ConfirmingNoParams - } else if (any { it.status is NotificationTroubleshootTestState.Status.Failure }) { + } else if (any { it.status.let { status -> status is NotificationTroubleshootTestState.Status.Failure && status.isCritical } }) { AsyncAction.Failure(Exception("Some tests failed")) } else { AsyncAction.Success(Unit) diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/DefaultNotificationTroubleShootEntryPointTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/DefaultNotificationTroubleShootEntryPointTest.kt index d9bf607531..e0d817a4ca 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/DefaultNotificationTroubleShootEntryPointTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/DefaultNotificationTroubleShootEntryPointTest.kt @@ -28,12 +28,13 @@ class DefaultNotificationTroubleShootEntryPointTest { TroubleshootNotificationsNode( buildContext = buildContext, plugins = plugins, - presenter = createTroubleshootNotificationsPresenter(), + factory = { createTroubleshootNotificationsPresenter() }, screenTracker = FakeScreenTracker(), ) } val callback = object : NotificationTroubleShootEntryPoint.Callback { override fun onDone() = lambdaError() + override fun openIgnoredUsers() = lambdaError() } val result = entryPoint.nodeBuilder(parentNode, BuildContext.root(null)) .callback(callback) diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/FakeNotificationTroubleshootTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/FakeNotificationTroubleshootTest.kt index bfd4025a2a..7fa2e93d85 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/FakeNotificationTroubleshootTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/FakeNotificationTroubleshootTest.kt @@ -7,6 +7,7 @@ package io.element.android.libraries.troubleshoot.impl +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import kotlinx.coroutines.CoroutineScope @@ -50,7 +51,10 @@ class FakeNotificationTroubleshootTest( } } - override suspend fun quickFix(coroutineScope: CoroutineScope) { + override suspend fun quickFix( + coroutineScope: CoroutineScope, + navigator: NotificationTroubleshootNavigator, + ) { updateState(NotificationTroubleshootTestState.Status.InProgress) quickFixAction()?.let { _state.emit(it) diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt index 211fa595b5..a3a32bca46 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt @@ -13,9 +13,11 @@ import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.architecture.AsyncAction import io.element.android.libraries.push.test.FakeGetCurrentPushProvider +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.services.analytics.test.FakeAnalyticsService +import io.element.android.tests.testutils.lambda.lambdaError import kotlinx.coroutines.test.runTest import org.junit.Test @@ -111,9 +113,13 @@ private fun createTroubleshootTestSuite( } internal fun createTroubleshootNotificationsPresenter( + navigator: NotificationTroubleshootNavigator = object : NotificationTroubleshootNavigator { + override fun openIgnoredUsers() = lambdaError() + }, troubleshootTestSuite: TroubleshootTestSuite = createTroubleshootTestSuite(), ): TroubleshootNotificationsPresenter { return TroubleshootNotificationsPresenter( + navigator = navigator, troubleshootTestSuite = troubleshootTestSuite, ) } diff --git a/libraries/troubleshoot/test/build.gradle.kts b/libraries/troubleshoot/test/build.gradle.kts new file mode 100644 index 0000000000..664c4e4d1d --- /dev/null +++ b/libraries/troubleshoot/test/build.gradle.kts @@ -0,0 +1,18 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ +plugins { + id("io.element.android-library") +} + +android { + namespace = "io.element.android.libraries.troubleshoot.test" +} + +dependencies { + implementation(projects.libraries.troubleshoot.api) + implementation(projects.tests.testutils) +} diff --git a/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/FakeNotificationTroubleshootNavigator.kt b/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/FakeNotificationTroubleshootNavigator.kt new file mode 100644 index 0000000000..63445e5a3e --- /dev/null +++ b/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/FakeNotificationTroubleshootNavigator.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.libraries.troubleshoot.test + +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator +import io.element.android.tests.testutils.lambda.lambdaError + +class FakeNotificationTroubleshootNavigator( + private val openIgnoredUsersResult: () -> Unit = { lambdaError() }, +) : NotificationTroubleshootNavigator { + override fun openIgnoredUsers() = openIgnoredUsersResult() +} diff --git a/tools/localazy/config.json b/tools/localazy/config.json index 0aac7e51af..4264b35229 100644 --- a/tools/localazy/config.json +++ b/tools/localazy/config.json @@ -123,6 +123,7 @@ "includeRegex" : [ "push_.*", "notification_.*", + "troubleshoot_notifications\\.test_blocked_users\\..*", "troubleshoot_notifications_test_current_push_provider.*", "troubleshoot_notifications_test_detect_push_provider.*", "troubleshoot_notifications_test_display_notification_.*", From 054e0564f81ada738fe2944804391903fce09df1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Sep 2025 09:13:45 +0200 Subject: [PATCH 2/7] Add default value for Failure.hasQuickFix --- ...otificationTroubleshootCheckPermissionTestTest.kt | 4 ++-- .../impl/troubleshoot/CurrentPushProviderTest.kt | 2 +- .../push/impl/troubleshoot/NotificationTest.kt | 4 ++-- .../push/impl/troubleshoot/PushLoopbackTest.kt | 8 ++++---- .../push/impl/troubleshoot/PushProvidersTest.kt | 2 +- .../impl/troubleshoot/CurrentPushProviderTestTest.kt | 2 +- .../push/impl/troubleshoot/PushLoopbackTestTest.kt | 12 ++++++------ .../push/impl/troubleshoot/PushProvidersTestTest.kt | 2 +- .../troubleshoot/FirebaseAvailabilityTest.kt | 2 +- .../firebase/troubleshoot/FirebaseTokenTest.kt | 2 +- .../troubleshoot/FirebaseAvailabilityTestTest.kt | 2 +- .../firebase/troubleshoot/FirebaseTokenTestTest.kt | 4 ++-- .../troubleshoot/UnifiedPushMatrixGatewayTest.kt | 6 +++--- .../unifiedpush/troubleshoot/UnifiedPushTest.kt | 2 +- .../troubleshoot/UnifiedPushMatrixGatewayTestTest.kt | 6 +++--- .../unifiedpush/troubleshoot/UnifiedPushTestTest.kt | 4 ++-- .../api/test/NotificationTroubleshootTestDelegate.kt | 2 +- .../api/test/NotificationTroubleshootTestState.kt | 2 +- 18 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt b/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt index f6696265bc..cbd7c2b8c3 100644 --- a/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt +++ b/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt @@ -82,7 +82,7 @@ class NotificationTroubleshootCheckPermissionTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) // Quick fix launch { sut.quickFix(this, FakeNotificationTroubleshootNavigator()) @@ -116,7 +116,7 @@ class NotificationTroubleshootCheckPermissionTestTest { sut.state.test { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) - assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt index 779375351b..5033274998 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt @@ -44,7 +44,7 @@ class CurrentPushProviderTest( } else { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_failure), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt index c29ff739d9..da390f85f2 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt @@ -54,7 +54,7 @@ class NotificationTest( } else { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_permission_failure), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } } @@ -81,7 +81,7 @@ class NotificationTest( notificationDisplayer.dismissDiagnosticNotification() delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_display_notification_failure), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } ) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt index 3845b68b18..5b9a9e2fd1 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt @@ -57,7 +57,7 @@ class PushLoopbackTest( val hasQuickFix = pushService.getCurrentPushProvider()?.canRotateToken() == true delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_1), - status = NotificationTroubleshootTestState.Status.Failure(hasQuickFix) + status = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = hasQuickFix) ) job.cancel() return @@ -65,7 +65,7 @@ class PushLoopbackTest( Timber.e(e, "Failed to test push") delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_2, e.message), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) job.cancel() return @@ -73,7 +73,7 @@ class PushLoopbackTest( if (!testPushResult) { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_3), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) job.cancel() return @@ -94,7 +94,7 @@ class PushLoopbackTest( job.cancel() delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_push_loop_back_failure_4), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } ) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt index d173404732..8e4d1db639 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt @@ -48,7 +48,7 @@ class PushProvidersTest( } else { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_detect_push_provider_failure), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt index f6485aa7d6..f45a89ff72 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt @@ -48,7 +48,7 @@ class CurrentPushProviderTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt index 182ffd89a8..e32537e748 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt @@ -40,7 +40,7 @@ class PushLoopbackTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) } } @@ -64,7 +64,7 @@ class PushLoopbackTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) } @@ -97,10 +97,10 @@ class PushLoopbackTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) sut.quickFix(this, FakeNotificationTroubleshootNavigator()) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) - assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) rotateTokenLambda.assertions().isCalledOnce() } } @@ -123,7 +123,7 @@ class PushLoopbackTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) } } @@ -147,7 +147,7 @@ class PushLoopbackTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) assertThat(lastItem.description).contains(A_FAILURE_REASON) } } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt index 8947b646a6..b768e68437 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt @@ -30,7 +30,7 @@ class PushProvidersTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) } diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt index 5e90dd84b5..c4ffe19db3 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt @@ -51,7 +51,7 @@ class FirebaseAvailabilityTest( } else { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_firebase_availability_failure), - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } } diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt index ae70114971..a886b5fb77 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt @@ -63,7 +63,7 @@ class FirebaseTokenTest( } else { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_firebase_token_failure), - status = NotificationTroubleshootTestState.Status.Failure(true) + status = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true) ) } } diff --git a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt index 86afded560..acb917b60f 100644 --- a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt +++ b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt @@ -49,7 +49,7 @@ class FirebaseAvailabilityTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) } diff --git a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt index b7a39feb9f..eb3ae403fb 100644 --- a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt +++ b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt @@ -61,7 +61,7 @@ class FirebaseTokenTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) // Quick fix sut.quickFix(this, FakeNotificationTroubleshootNavigator()) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) @@ -88,7 +88,7 @@ class FirebaseTokenTestTest { sut.state.test { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) - assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) } diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTest.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTest.kt index b60c1e5fcf..7a22e92222 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTest.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTest.kt @@ -48,7 +48,7 @@ class UnifiedPushMatrixGatewayTest( if (config == null) { delegate.updateState( description = "No current push provider", - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } else { val gatewayBaseUrl = config.url.removeSuffix("/_matrix/push/v1/notify") @@ -65,13 +65,13 @@ class UnifiedPushMatrixGatewayTest( } else { delegate.updateState( description = "${config.url} is not a Matrix gateway.", - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } } catch (throwable: Throwable) { delegate.updateState( description = "Fail to check the gateway ${config.url}: ${throwable.localizedMessage}", - status = NotificationTroubleshootTestState.Status.Failure(false) + status = NotificationTroubleshootTestState.Status.Failure() ) } } diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt index 6791a901db..bb2c88bcdd 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt @@ -58,7 +58,7 @@ class UnifiedPushTest( } else { delegate.updateState( description = stringProvider.getString(R.string.troubleshoot_notifications_test_unified_push_failure), - status = NotificationTroubleshootTestState.Status.Failure(true) + status = NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true) ) } } diff --git a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt index 95cf85af5c..9729e04eb1 100644 --- a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt +++ b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt @@ -55,7 +55,7 @@ class UnifiedPushMatrixGatewayTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) } } @@ -72,7 +72,7 @@ class UnifiedPushMatrixGatewayTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) // Reset the error sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) @@ -92,7 +92,7 @@ class UnifiedPushMatrixGatewayTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(false)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure()) } } diff --git a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt index 53d85c7fea..257be14f6c 100644 --- a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt +++ b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt @@ -65,7 +65,7 @@ class UnifiedPushTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) // Quick fix launch { sut.quickFix(this, FakeNotificationTroubleshootNavigator()) @@ -99,7 +99,7 @@ class UnifiedPushTestTest { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() - assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(true)) + assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) sut.reset() assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) } diff --git a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestDelegate.kt b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestDelegate.kt index 561ec60267..830ba74818 100644 --- a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestDelegate.kt +++ b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestDelegate.kt @@ -60,7 +60,7 @@ class NotificationTroubleshootTestDelegate( if (isSuccess) { NotificationTroubleshootTestState.Status.Success } else { - NotificationTroubleshootTestState.Status.Failure(hasQuickFix) + NotificationTroubleshootTestState.Status.Failure(hasQuickFix = hasQuickFix) } ) } diff --git a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt index ffb6d9a26a..4069d78cb3 100644 --- a/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt +++ b/libraries/troubleshoot/api/src/main/kotlin/io/element/android/libraries/troubleshoot/api/test/NotificationTroubleshootTestState.kt @@ -18,7 +18,7 @@ data class NotificationTroubleshootTestState( data object WaitingForUser : Status data object Success : Status data class Failure( - val hasQuickFix: Boolean, + val hasQuickFix: Boolean = false, val isCritical: Boolean = true, val quickFixButtonString: String? = null, ) : Status From 41ef36c1ae4de72891d94f813ae340edce799d19 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Sep 2025 09:26:13 +0200 Subject: [PATCH 3/7] Add missing tests on TroubleshootTestSuite --- .../TroubleshootNotificationsPresenterTest.kt | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt index a3a32bca46..8094dad15a 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt @@ -18,6 +18,7 @@ import io.element.android.libraries.troubleshoot.api.test.NotificationTroublesho import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.services.analytics.test.FakeAnalyticsService import io.element.android.tests.testutils.lambda.lambdaError +import io.element.android.tests.testutils.test import kotlinx.coroutines.test.runTest import org.junit.Test @@ -76,6 +77,80 @@ class TroubleshootNotificationsPresenterTest { } } + @Test + fun `present - critical failed test`() { + `present - check main state`( + tests = setOf( + FakeNotificationTroubleshootTest( + firstStatus = NotificationTroubleshootTestState.Status.Failure(isCritical = true) + ) + ), + expectedIsCritical = true, + expectedMainState = AsyncAction.Failure::class.java, + ) + } + + @Test + fun `present - success and critical failed test`() { + `present - check main state`( + tests = setOf( + FakeNotificationTroubleshootTest( + firstStatus = NotificationTroubleshootTestState.Status.Success + ), + FakeNotificationTroubleshootTest( + firstStatus = NotificationTroubleshootTestState.Status.Failure(isCritical = true) + ), + ), + expectedIsCritical = true, + expectedMainState = AsyncAction.Failure::class.java, + ) + } + + @Test + fun `present - non critical failed test`() { + `present - check main state`( + tests = setOf( + FakeNotificationTroubleshootTest( + firstStatus = NotificationTroubleshootTestState.Status.Failure(isCritical = false) + ) + ), + expectedIsCritical = false, + expectedMainState = AsyncAction.Success::class.java, + ) + } + + @Test + fun `present - waiting for user`() { + `present - check main state`( + tests = setOf( + FakeNotificationTroubleshootTest( + firstStatus = NotificationTroubleshootTestState.Status.WaitingForUser + ) + ), + expectedIsCritical = false, + expectedMainState = AsyncAction.ConfirmingNoParams::class.java, + ) + } + + private fun `present - check main state`( + tests: Set, + expectedIsCritical: Boolean, + expectedMainState: Class>, + ) = runTest { + val troubleshootTestSuite = createTroubleshootTestSuite( + tests = tests + ) + val presenter = createTroubleshootNotificationsPresenter( + troubleshootTestSuite = troubleshootTestSuite, + ) + presenter.test { + skipItems(1) + val initialState = awaitItem() + assertThat(initialState.hasFailedTests).isEqualTo(expectedIsCritical) + assertThat(initialState.testSuiteState.mainState).isInstanceOf(expectedMainState) + } + } + @Test fun `present - quick fix test`() = runTest { val troubleshootTestSuite = createTroubleshootTestSuite( From bfc770d46e40e3671afe26186e56d91203f4af6b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Sep 2025 09:28:01 +0200 Subject: [PATCH 4/7] Cleanup --- .../TroubleshootNotificationsPresenterTest.kt | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt index 8094dad15a..4d6b338db7 100644 --- a/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt +++ b/libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt @@ -7,9 +7,6 @@ package io.element.android.libraries.troubleshoot.impl -import app.cash.molecule.RecompositionMode -import app.cash.molecule.moleculeFlow -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.architecture.AsyncAction import io.element.android.libraries.push.test.FakeGetCurrentPushProvider @@ -26,9 +23,7 @@ class TroubleshootNotificationsPresenterTest { @Test fun `present - initial state`() = runTest { val presenter = createTroubleshootNotificationsPresenter() - moleculeFlow(RecompositionMode.Immediate) { - presenter.present() - }.test { + presenter.test { val initialState = awaitItem() assertThat(initialState.testSuiteState.tests).isEmpty() assertThat(initialState.testSuiteState.mainState).isEqualTo(AsyncAction.Uninitialized) @@ -43,9 +38,7 @@ class TroubleshootNotificationsPresenterTest { val presenter = createTroubleshootNotificationsPresenter( troubleshootTestSuite = troubleshootTestSuite, ) - moleculeFlow(RecompositionMode.Immediate) { - presenter.present() - }.test { + presenter.test { val initialState = awaitItem() initialState.eventSink(TroubleshootNotificationsEvents.StartTests) skipItems(1) @@ -66,9 +59,7 @@ class TroubleshootNotificationsPresenterTest { val presenter = createTroubleshootNotificationsPresenter( troubleshootTestSuite = troubleshootTestSuite, ) - moleculeFlow(RecompositionMode.Immediate) { - presenter.present() - }.test { + presenter.test { val initialState = awaitItem() initialState.eventSink(TroubleshootNotificationsEvents.RetryFailedTests) skipItems(1) @@ -163,9 +154,7 @@ class TroubleshootNotificationsPresenterTest { val presenter = createTroubleshootNotificationsPresenter( troubleshootTestSuite = troubleshootTestSuite, ) - moleculeFlow(RecompositionMode.Immediate) { - presenter.present() - }.test { + presenter.test { skipItems(1) val initialState = awaitItem() assertThat(initialState.testSuiteState.mainState).isInstanceOf(AsyncAction.Failure::class.java) From 194340b19c8c5cc9044c4428fba71a4db3dbf048 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Sep 2025 09:45:36 +0200 Subject: [PATCH 5/7] Introduce runAndTestState extension on NotificationTroubleshootTest --- build.gradle.kts | 2 ++ ...tionTroubleshootCheckPermissionTestTest.kt | 24 ++++---------- .../CurrentPushProviderTestTest.kt | 13 ++------ .../impl/troubleshoot/IgnoredUsersTestTest.kt | 13 ++------ .../impl/troubleshoot/NotificationTestTest.kt | 18 +++------- .../impl/troubleshoot/PushLoopbackTestTest.kt | 33 ++++--------------- .../troubleshoot/PushProvidersTestTest.kt | 13 ++------ .../FirebaseAvailabilityTestTest.kt | 13 ++------ .../troubleshoot/FirebaseTokenTestTest.kt | 18 +++------- .../UnifiedPushMatrixGatewayTestTest.kt | 23 +++---------- .../troubleshoot/UnifiedPushTestTest.kt | 19 +++-------- libraries/troubleshoot/test/build.gradle.kts | 3 ++ .../libraries/troubleshoot/test/Utils.kt | 25 ++++++++++++++ 13 files changed, 73 insertions(+), 144 deletions(-) create mode 100644 libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt diff --git a/build.gradle.kts b/build.gradle.kts index b4ebcf6268..7171d5b079 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -93,6 +93,8 @@ allprojects { // Fix compilation warning for annotations // See https://youtrack.jetbrains.com/issue/KT-73255/Change-defaulting-rule-for-annotations for more details freeCompilerArgs.add("-Xannotation-default-target=first-only") + // Opt-in to context receivers + freeCompilerArgs.add("-Xcontext-parameters") } } } diff --git a/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt b/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt index cbd7c2b8c3..41a7260ca2 100644 --- a/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt +++ b/libraries/permissions/impl/src/test/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTestTest.kt @@ -8,12 +8,12 @@ package io.element.android.libraries.permissions.impl.troubleshoot import android.os.Build -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.permissions.impl.action.FakePermissionActions import io.element.android.libraries.permissions.test.FakePermissionStateProvider import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.sdk.FakeBuildVersionSdkIntProvider import io.element.android.services.toolbox.test.strings.FakeStringProvider import kotlinx.coroutines.launch @@ -29,10 +29,7 @@ class NotificationTroubleshootCheckPermissionTestTest { permissionActions = FakePermissionActions(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -48,10 +45,7 @@ class NotificationTroubleshootCheckPermissionTestTest { permissionActions = FakePermissionActions(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -75,16 +69,13 @@ class NotificationTroubleshootCheckPermissionTestTest { permissionActions = actions, stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) // Quick fix - launch { + backgroundScope.launch { sut.quickFix(this, FakeNotificationTroubleshootNavigator()) // Run the test again (IRL it will be done thanks to the resuming of the application) sut.run(this) @@ -110,10 +101,7 @@ class NotificationTroubleshootCheckPermissionTestTest { permissionActions = actions, stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt index f45a89ff72..95bfced7de 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTestTest.kt @@ -7,12 +7,11 @@ package io.element.android.libraries.push.impl.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.push.test.FakeGetCurrentPushProvider import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -23,10 +22,7 @@ class CurrentPushProviderTestTest { getCurrentPushProvider = FakeGetCurrentPushProvider("foo"), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -41,10 +37,7 @@ class CurrentPushProviderTestTest { getCurrentPushProvider = FakeGetCurrentPushProvider(null), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt index ed1cf93fce..e38baa7321 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/IgnoredUsersTestTest.kt @@ -7,18 +7,17 @@ package io.element.android.libraries.push.impl.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.matrix.test.A_USER_ID import io.element.android.libraries.matrix.test.A_USER_ID_2 import io.element.android.libraries.matrix.test.FakeMatrixClient import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootNavigator import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider import io.element.android.tests.testutils.lambda.lambdaRecorder import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -57,10 +56,7 @@ class IgnoredUsersTestTest { ), stringProvider = FakeStringProvider(), ) - backgroundScope.launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -76,10 +72,7 @@ class IgnoredUsersTestTest { ), stringProvider = FakeStringProvider(), ) - backgroundScope.launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt index 2c0dbeff10..eecb3801fd 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTestTest.kt @@ -7,14 +7,13 @@ package io.element.android.libraries.push.impl.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDisplayer import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider import io.element.android.tests.testutils.lambda.lambdaRecorder -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -31,10 +30,7 @@ class NotificationTestTest { fun `test NotificationTest notification cannot be displayed`() = runTest { fakeNotificationDisplayer.displayDiagnosticNotificationResult = lambdaRecorder { _ -> false } val sut = createNotificationTest() - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isInstanceOf(NotificationTroubleshootTestState.Status.Failure::class.java) @@ -44,10 +40,7 @@ class NotificationTestTest { @Test fun `test NotificationTest user does not click on notification`() = runTest { val sut = createNotificationTest() - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.WaitingForUser) @@ -60,10 +53,7 @@ class NotificationTestTest { @Test fun `test NotificationTest user clicks on notification`() = runTest { val sut = createNotificationTest() - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.WaitingForUser) diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt index e32537e748..f06b6a9e1b 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTestTest.kt @@ -7,7 +7,6 @@ package io.element.android.libraries.push.impl.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.matrix.test.AN_EXCEPTION import io.element.android.libraries.matrix.test.A_FAILURE_REASON @@ -16,10 +15,10 @@ import io.element.android.libraries.push.test.FakePushService import io.element.android.libraries.pushproviders.test.FakePushProvider import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider import io.element.android.services.toolbox.test.systemclock.FakeSystemClock import io.element.android.tests.testutils.lambda.lambdaRecorder -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -33,10 +32,7 @@ class PushLoopbackTestTest { clock = FakeSystemClock(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -57,10 +53,7 @@ class PushLoopbackTestTest { clock = FakeSystemClock(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -90,10 +83,7 @@ class PushLoopbackTestTest { clock = FakeSystemClock(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -116,10 +106,7 @@ class PushLoopbackTestTest { clock = FakeSystemClock(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -140,10 +127,7 @@ class PushLoopbackTestTest { clock = FakeSystemClock(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -164,10 +148,7 @@ class PushLoopbackTestTest { clock = FakeSystemClock(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt index b768e68437..b274f0bdab 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTestTest.kt @@ -7,12 +7,11 @@ package io.element.android.libraries.push.impl.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.pushproviders.test.FakePushProvider import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -23,10 +22,7 @@ class PushProvidersTestTest { pushProviders = emptySet(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -45,10 +41,7 @@ class PushProvidersTestTest { ), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt index acb917b60f..ce617799f5 100644 --- a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt +++ b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTestTest.kt @@ -7,14 +7,13 @@ package io.element.android.libraries.pushproviders.firebase.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.pushproviders.firebase.FakeIsPlayServiceAvailable import io.element.android.libraries.pushproviders.firebase.FirebaseConfig import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -25,10 +24,7 @@ class FirebaseAvailabilityTestTest { isPlayServiceAvailable = FakeIsPlayServiceAvailable(true), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -42,10 +38,7 @@ class FirebaseAvailabilityTestTest { isPlayServiceAvailable = FakeIsPlayServiceAvailable(false), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt index eb3ae403fb..7e6981ef57 100644 --- a/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt +++ b/libraries/pushproviders/firebase/src/test/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTestTest.kt @@ -7,7 +7,6 @@ package io.element.android.libraries.pushproviders.firebase.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.pushproviders.firebase.FakeFirebaseTroubleshooter import io.element.android.libraries.pushproviders.firebase.FirebaseConfig @@ -15,8 +14,8 @@ import io.element.android.libraries.pushproviders.firebase.InMemoryFirebaseStore import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.Test @@ -28,10 +27,7 @@ class FirebaseTokenTestTest { firebaseTroubleshooter = FakeFirebaseTroubleshooter(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -54,10 +50,7 @@ class FirebaseTokenTestTest { ), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -82,10 +75,7 @@ class FirebaseTokenTestTest { ), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) diff --git a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt index 9729e04eb1..f4a0cf5da4 100644 --- a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt +++ b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushMatrixGatewayTestTest.kt @@ -7,7 +7,6 @@ package io.element.android.libraries.pushproviders.unifiedpush.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.pushproviders.api.CurrentUserPushConfig import io.element.android.libraries.pushproviders.test.aCurrentUserPushConfig @@ -18,8 +17,8 @@ import io.element.android.libraries.pushproviders.unifiedpush.matrixDiscoveryRes import io.element.android.libraries.pushproviders.unifiedpush.network.DiscoveryResponse import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.tests.testutils.testCoroutineDispatchers -import kotlinx.coroutines.launch import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import org.junit.Test @@ -31,10 +30,7 @@ class UnifiedPushMatrixGatewayTestTest { currentUserPushConfig = aCurrentUserPushConfig(), discoveryResponse = matrixDiscoveryResponse, ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -48,10 +44,7 @@ class UnifiedPushMatrixGatewayTestTest { currentUserPushConfig = null, discoveryResponse = matrixDiscoveryResponse, ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -65,10 +58,7 @@ class UnifiedPushMatrixGatewayTestTest { currentUserPushConfig = aCurrentUserPushConfig(), discoveryResponse = invalidDiscoveryResponse, ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -85,10 +75,7 @@ class UnifiedPushMatrixGatewayTestTest { currentUserPushConfig = aCurrentUserPushConfig(), discoveryResponse = { error("Network error") }, ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt index 257be14f6c..28ab0186da 100644 --- a/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt +++ b/libraries/pushproviders/unifiedpush/src/test/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTestTest.kt @@ -7,13 +7,13 @@ package io.element.android.libraries.pushproviders.unifiedpush.troubleshoot -import app.cash.turbine.test import com.google.common.truth.Truth.assertThat import io.element.android.libraries.pushproviders.api.Distributor import io.element.android.libraries.pushproviders.unifiedpush.UnifiedPushConfig import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState import io.element.android.libraries.troubleshoot.api.test.TestFilterData import io.element.android.libraries.troubleshoot.test.FakeNotificationTroubleshootNavigator +import io.element.android.libraries.troubleshoot.test.runAndTestState import io.element.android.services.toolbox.test.strings.FakeStringProvider import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest @@ -31,10 +31,7 @@ class UnifiedPushTestTest { openDistributorWebPageAction = FakeOpenDistributorWebPageAction(), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() @@ -58,16 +55,13 @@ class UnifiedPushTestTest { ), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure(hasQuickFix = true)) // Quick fix - launch { + backgroundScope.launch { sut.quickFix(this, FakeNotificationTroubleshootNavigator()) sut.run(this) } @@ -92,10 +86,7 @@ class UnifiedPushTestTest { ), stringProvider = FakeStringProvider(), ) - launch { - sut.run(this) - } - sut.state.test { + sut.runAndTestState { assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(false)) assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress) val lastItem = awaitItem() diff --git a/libraries/troubleshoot/test/build.gradle.kts b/libraries/troubleshoot/test/build.gradle.kts index 664c4e4d1d..8321ea5b4f 100644 --- a/libraries/troubleshoot/test/build.gradle.kts +++ b/libraries/troubleshoot/test/build.gradle.kts @@ -15,4 +15,7 @@ android { dependencies { implementation(projects.libraries.troubleshoot.api) implementation(projects.tests.testutils) + implementation(libs.coroutines.test) + implementation(libs.test.core) + implementation(libs.test.turbine) } diff --git a/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt b/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt new file mode 100644 index 0000000000..2a8ce30f47 --- /dev/null +++ b/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.libraries.troubleshoot.test + +import app.cash.turbine.TurbineTestContext +import app.cash.turbine.test +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest +import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.TestScope + +context(testScope: TestScope) +suspend fun NotificationTroubleshootTest.runAndTestState( + validate: suspend TurbineTestContext.() -> Unit, +) { + testScope.backgroundScope.launch { + run(this) + } + state.test(validate = validate) +} From 7c40d2b73ca20c8cec5154440b7e4b4739664bf0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Sep 2025 10:10:44 +0200 Subject: [PATCH 6/7] Detekt and ktlint are confused with Kotlin context... --- libraries/troubleshoot/test/build.gradle.kts | 10 ++++++++++ .../android/libraries/troubleshoot/test/Utils.kt | 2 ++ 2 files changed, 12 insertions(+) diff --git a/libraries/troubleshoot/test/build.gradle.kts b/libraries/troubleshoot/test/build.gradle.kts index 8321ea5b4f..830eb5d6b0 100644 --- a/libraries/troubleshoot/test/build.gradle.kts +++ b/libraries/troubleshoot/test/build.gradle.kts @@ -19,3 +19,13 @@ dependencies { implementation(libs.test.core) implementation(libs.test.turbine) } + +ktlint { + filter { + exclude { element -> + val path = element.file.path + // Exclude this file, that ktlint cannot parse. + path.contains("libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt") + } + } +} diff --git a/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt b/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt index 2a8ce30f47..77034da584 100644 --- a/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt +++ b/libraries/troubleshoot/test/src/main/kotlin/io/element/android/libraries/troubleshoot/test/Utils.kt @@ -5,6 +5,8 @@ * Please see LICENSE files in the repository root for full details. */ +@file:Suppress("UnusedImports") + package io.element.android.libraries.troubleshoot.test import app.cash.turbine.TurbineTestContext From 655ba3c24c929f49174ea08e54fbd2264593f5b4 Mon Sep 17 00:00:00 2001 From: ElementBot Date: Tue, 23 Sep 2025 08:38:58 +0000 Subject: [PATCH 7/7] Update screenshots --- ...oubleshoot.impl_TroubleshootNotificationsView_Day_2_en.png | 4 ++-- ...bleshoot.impl_TroubleshootNotificationsView_Night_2_en.png | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Day_2_en.png b/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Day_2_en.png index 22eaaced82..2442a17143 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Day_2_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Day_2_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:642e972ecba4cf6af7961066a67b556047d0ab3c35a4ce66e043ba185d93b528 -size 20101 +oid sha256:9051334b3879fe2a6fb56a3c573ecb49eca7700a94184d828e2c0329cbb82b4b +size 25070 diff --git a/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Night_2_en.png b/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Night_2_en.png index 5b2d1f6f65..40126799db 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Night_2_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.troubleshoot.impl_TroubleshootNotificationsView_Night_2_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:26e11efbeec28f03e9b8d0df822e886b9e420fc523286cc0aa69760f8d5b639c -size 19562 +oid sha256:50fb2b753bdad6a9df4ce2f55a552464e229c7b81be16e0d4f5c8e4e4b3d129b +size 24312