Skip to content

Commit 1d82ad3

Browse files
committed
Add missing tests on TroubleshootTestSuite
1 parent a83fc2a commit 1d82ad3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

libraries/troubleshoot/impl/src/test/kotlin/io/element/android/libraries/troubleshoot/impl/TroubleshootNotificationsPresenterTest.kt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import io.element.android.libraries.troubleshoot.api.test.NotificationTroublesho
1818
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
1919
import io.element.android.services.analytics.test.FakeAnalyticsService
2020
import io.element.android.tests.testutils.lambda.lambdaError
21+
import io.element.android.tests.testutils.test
2122
import kotlinx.coroutines.test.runTest
2223
import org.junit.Test
2324

@@ -76,6 +77,80 @@ class TroubleshootNotificationsPresenterTest {
7677
}
7778
}
7879

80+
@Test
81+
fun `present - critical failed test`() {
82+
`present - check main state`(
83+
tests = setOf(
84+
FakeNotificationTroubleshootTest(
85+
firstStatus = NotificationTroubleshootTestState.Status.Failure(isCritical = true)
86+
)
87+
),
88+
expectedIsCritical = true,
89+
expectedMainState = AsyncAction.Failure::class.java,
90+
)
91+
}
92+
93+
@Test
94+
fun `present - success and critical failed test`() {
95+
`present - check main state`(
96+
tests = setOf(
97+
FakeNotificationTroubleshootTest(
98+
firstStatus = NotificationTroubleshootTestState.Status.Success
99+
),
100+
FakeNotificationTroubleshootTest(
101+
firstStatus = NotificationTroubleshootTestState.Status.Failure(isCritical = true)
102+
),
103+
),
104+
expectedIsCritical = true,
105+
expectedMainState = AsyncAction.Failure::class.java,
106+
)
107+
}
108+
109+
@Test
110+
fun `present - non critical failed test`() {
111+
`present - check main state`(
112+
tests = setOf(
113+
FakeNotificationTroubleshootTest(
114+
firstStatus = NotificationTroubleshootTestState.Status.Failure(isCritical = false)
115+
)
116+
),
117+
expectedIsCritical = false,
118+
expectedMainState = AsyncAction.Success::class.java,
119+
)
120+
}
121+
122+
@Test
123+
fun `present - waiting for user`() {
124+
`present - check main state`(
125+
tests = setOf(
126+
FakeNotificationTroubleshootTest(
127+
firstStatus = NotificationTroubleshootTestState.Status.WaitingForUser
128+
)
129+
),
130+
expectedIsCritical = false,
131+
expectedMainState = AsyncAction.ConfirmingNoParams::class.java,
132+
)
133+
}
134+
135+
private fun `present - check main state`(
136+
tests: Set<NotificationTroubleshootTest>,
137+
expectedIsCritical: Boolean,
138+
expectedMainState: Class<out AsyncAction<*>>,
139+
) = runTest {
140+
val troubleshootTestSuite = createTroubleshootTestSuite(
141+
tests = tests
142+
)
143+
val presenter = createTroubleshootNotificationsPresenter(
144+
troubleshootTestSuite = troubleshootTestSuite,
145+
)
146+
presenter.test {
147+
skipItems(1)
148+
val initialState = awaitItem()
149+
assertThat(initialState.hasFailedTests).isEqualTo(expectedIsCritical)
150+
assertThat(initialState.testSuiteState.mainState).isInstanceOf(expectedMainState)
151+
}
152+
}
153+
79154
@Test
80155
fun `present - quick fix test`() = runTest {
81156
val troubleshootTestSuite = createTroubleshootTestSuite(

0 commit comments

Comments
 (0)