Add missing tests on TroubleshootTestSuite

This commit is contained in:
Benoit Marty
2025-09-23 09:26:13 +02:00
parent 054e0564f8
commit 41ef36c1ae

View File

@@ -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<NotificationTroubleshootTest>,
expectedIsCritical: Boolean,
expectedMainState: Class<out AsyncAction<*>>,
) = 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(