@@ -18,6 +18,8 @@ import io.element.android.features.rageshake.impl.crash.FakeCrashDataStore
18
18
import io.element.android.libraries.core.meta.BuildMeta
19
19
import io.element.android.libraries.matrix.test.core.aBuildMeta
20
20
import io.element.android.tests.testutils.WarmUpRule
21
+ import kotlinx.coroutines.flow.Flow
22
+ import kotlinx.coroutines.flow.MutableStateFlow
21
23
import kotlinx.coroutines.flow.flowOf
22
24
import kotlinx.coroutines.test.runTest
23
25
import org.junit.Rule
@@ -56,7 +58,7 @@ class CrashDetectionPresenterTest {
56
58
fun `present - initial state crash is ignored if the feature is not available` () = runTest {
57
59
val presenter = createPresenter(
58
60
FakeCrashDataStore (appHasCrashed = true ),
59
- isFeatureAvailable = false ,
61
+ isFeatureAvailableFlow = flowOf( false ) ,
60
62
)
61
63
moleculeFlow(RecompositionMode .Immediate ) {
62
64
presenter.present()
@@ -98,13 +100,42 @@ class CrashDetectionPresenterTest {
98
100
}
99
101
}
100
102
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
+
101
132
private fun createPresenter (
102
133
crashDataStore : FakeCrashDataStore = FakeCrashDataStore (),
103
134
buildMeta : BuildMeta = aBuildMeta(),
104
- isFeatureAvailable : Boolean = true,
135
+ isFeatureAvailableFlow : Flow < Boolean > = flowOf( true) ,
105
136
) = DefaultCrashDetectionPresenter (
106
137
buildMeta = buildMeta,
107
138
crashDataStore = crashDataStore,
108
- rageshakeFeatureAvailability = { flowOf(isFeatureAvailable) },
139
+ rageshakeFeatureAvailability = { isFeatureAvailableFlow },
109
140
)
110
141
}
0 commit comments