From 41ef36c1ae4de72891d94f813ae340edce799d19 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Sep 2025 09:26:13 +0200 Subject: [PATCH] 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(