Skip to content

Commit 67e27ab

Browse files
committed
Add missing test on CrashDetectionPresenter
1 parent bac59f6 commit 67e27ab

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/crash/FakeCrashDataStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class FakeCrashDataStore(
2121

2222
override fun setCrashData(crashData: String) {
2323
crashDataFlow.value = crashData
24+
appHasCrashedFlow.value = true
2425
}
2526

2627
override suspend fun resetAppHasCrashed() {

features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/crash/ui/CrashDetectionPresenterTest.kt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import io.element.android.features.rageshake.impl.crash.FakeCrashDataStore
1818
import io.element.android.libraries.core.meta.BuildMeta
1919
import io.element.android.libraries.matrix.test.core.aBuildMeta
2020
import io.element.android.tests.testutils.WarmUpRule
21+
import kotlinx.coroutines.flow.Flow
22+
import kotlinx.coroutines.flow.MutableStateFlow
2123
import kotlinx.coroutines.flow.flowOf
2224
import kotlinx.coroutines.test.runTest
2325
import org.junit.Rule
@@ -56,7 +58,7 @@ class CrashDetectionPresenterTest {
5658
fun `present - initial state crash is ignored if the feature is not available`() = runTest {
5759
val presenter = createPresenter(
5860
FakeCrashDataStore(appHasCrashed = true),
59-
isFeatureAvailable = false,
61+
isFeatureAvailableFlow = flowOf(false),
6062
)
6163
moleculeFlow(RecompositionMode.Immediate) {
6264
presenter.present()
@@ -98,13 +100,42 @@ class CrashDetectionPresenterTest {
98100
}
99101
}
100102

103+
@Test
104+
fun `present - crashDetected is false if the feature is not available`() = runTest {
105+
val isFeatureAvailableFlow = MutableStateFlow(false)
106+
val crashDataStore = FakeCrashDataStore(appHasCrashed = false)
107+
val presenter = createPresenter(
108+
crashDataStore = crashDataStore,
109+
isFeatureAvailableFlow = isFeatureAvailableFlow,
110+
)
111+
moleculeFlow(RecompositionMode.Immediate) {
112+
presenter.present()
113+
}.test {
114+
val initialState = awaitItem()
115+
assertThat(initialState.crashDetected).isFalse()
116+
crashDataStore.setCrashData("Some crash data")
117+
// No new state
118+
crashDataStore.resetAppHasCrashed()
119+
// No new state
120+
isFeatureAvailableFlow.value = true
121+
crashDataStore.setCrashData("Some crash data")
122+
assertThat(awaitItem().crashDetected).isTrue()
123+
crashDataStore.resetAppHasCrashed()
124+
assertThat(awaitItem().crashDetected).isFalse()
125+
crashDataStore.setCrashData("Some crash data")
126+
assertThat(awaitItem().crashDetected).isTrue()
127+
isFeatureAvailableFlow.value = false
128+
assertThat(awaitItem().crashDetected).isFalse()
129+
}
130+
}
131+
101132
private fun createPresenter(
102133
crashDataStore: FakeCrashDataStore = FakeCrashDataStore(),
103134
buildMeta: BuildMeta = aBuildMeta(),
104-
isFeatureAvailable: Boolean = true,
135+
isFeatureAvailableFlow: Flow<Boolean> = flowOf(true),
105136
) = DefaultCrashDetectionPresenter(
106137
buildMeta = buildMeta,
107138
crashDataStore = crashDataStore,
108-
rageshakeFeatureAvailability = { flowOf(isFeatureAvailable) },
139+
rageshakeFeatureAvailability = { isFeatureAvailableFlow },
109140
)
110141
}

0 commit comments

Comments
 (0)