Add missing test on CrashDetectionPresenter
This commit is contained in:
parent
78bd174d10
commit
50809d2adb
2 changed files with 35 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ class FakeCrashDataStore(
|
||||||
|
|
||||||
override fun setCrashData(crashData: String) {
|
override fun setCrashData(crashData: String) {
|
||||||
crashDataFlow.value = crashData
|
crashDataFlow.value = crashData
|
||||||
|
appHasCrashedFlow.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resetAppHasCrashed() {
|
override suspend fun resetAppHasCrashed() {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ import io.element.android.features.rageshake.impl.crash.FakeCrashDataStore
|
||||||
import io.element.android.libraries.core.meta.BuildMeta
|
import io.element.android.libraries.core.meta.BuildMeta
|
||||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||||
import io.element.android.tests.testutils.WarmUpRule
|
import io.element.android.tests.testutils.WarmUpRule
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
|
|
@ -56,7 +58,7 @@ class CrashDetectionPresenterTest {
|
||||||
fun `present - initial state crash is ignored if the feature is not available`() = runTest {
|
fun `present - initial state crash is ignored if the feature is not available`() = runTest {
|
||||||
val presenter = createPresenter(
|
val presenter = createPresenter(
|
||||||
FakeCrashDataStore(appHasCrashed = true),
|
FakeCrashDataStore(appHasCrashed = true),
|
||||||
isFeatureAvailable = false,
|
isFeatureAvailableFlow = flowOf(false),
|
||||||
)
|
)
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
|
|
@ -98,13 +100,42 @@ class CrashDetectionPresenterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - crashDetected is false if the feature is not available`() = runTest {
|
||||||
|
val isFeatureAvailableFlow = MutableStateFlow(false)
|
||||||
|
val crashDataStore = FakeCrashDataStore(appHasCrashed = false)
|
||||||
|
val presenter = createPresenter(
|
||||||
|
crashDataStore = crashDataStore,
|
||||||
|
isFeatureAvailableFlow = isFeatureAvailableFlow,
|
||||||
|
)
|
||||||
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
|
presenter.present()
|
||||||
|
}.test {
|
||||||
|
val initialState = awaitItem()
|
||||||
|
assertThat(initialState.crashDetected).isFalse()
|
||||||
|
crashDataStore.setCrashData("Some crash data")
|
||||||
|
// No new state
|
||||||
|
crashDataStore.resetAppHasCrashed()
|
||||||
|
// No new state
|
||||||
|
isFeatureAvailableFlow.value = true
|
||||||
|
crashDataStore.setCrashData("Some crash data")
|
||||||
|
assertThat(awaitItem().crashDetected).isTrue()
|
||||||
|
crashDataStore.resetAppHasCrashed()
|
||||||
|
assertThat(awaitItem().crashDetected).isFalse()
|
||||||
|
crashDataStore.setCrashData("Some crash data")
|
||||||
|
assertThat(awaitItem().crashDetected).isTrue()
|
||||||
|
isFeatureAvailableFlow.value = false
|
||||||
|
assertThat(awaitItem().crashDetected).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createPresenter(
|
private fun createPresenter(
|
||||||
crashDataStore: FakeCrashDataStore = FakeCrashDataStore(),
|
crashDataStore: FakeCrashDataStore = FakeCrashDataStore(),
|
||||||
buildMeta: BuildMeta = aBuildMeta(),
|
buildMeta: BuildMeta = aBuildMeta(),
|
||||||
isFeatureAvailable: Boolean = true,
|
isFeatureAvailableFlow: Flow<Boolean> = flowOf(true),
|
||||||
) = DefaultCrashDetectionPresenter(
|
) = DefaultCrashDetectionPresenter(
|
||||||
buildMeta = buildMeta,
|
buildMeta = buildMeta,
|
||||||
crashDataStore = crashDataStore,
|
crashDataStore = crashDataStore,
|
||||||
rageshakeFeatureAvailability = { flowOf(isFeatureAvailable) },
|
rageshakeFeatureAvailability = { isFeatureAvailableFlow },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue