Browse Source

More tests for `RageshakeDetectionPresenterTest`

kittykat-patch-1
Benoit Marty 2 years ago committed by Benoit Marty
parent
commit
059d8ec6ce
  1. 1
      features/rageshake/build.gradle.kts
  2. 43
      features/rageshake/src/test/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionPresenterTest.kt
  3. 2
      gradle/libs.versions.toml

1
features/rageshake/build.gradle.kts

@ -52,6 +52,7 @@ dependencies { @@ -52,6 +52,7 @@ dependencies {
testImplementation(libs.test.truth)
testImplementation(libs.test.turbine)
testImplementation(projects.libraries.matrixtest)
testImplementation(libs.test.mockk)
androidTestImplementation(libs.test.junitext)
}

43
features/rageshake/src/test/kotlin/io/element/android/features/rageshake/detection/RageshakeDetectionPresenterTest.kt

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
package io.element.android.features.rageshake.detection
import android.graphics.Bitmap
import app.cash.molecule.RecompositionClock
import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
@ -27,6 +28,7 @@ import io.element.android.features.rageshake.preferences.FakeRageShake @@ -27,6 +28,7 @@ import io.element.android.features.rageshake.preferences.FakeRageShake
import io.element.android.features.rageshake.preferences.FakeRageshakeDataStore
import io.element.android.features.rageshake.preferences.RageshakePreferencesPresenter
import io.element.android.features.rageshake.screenshot.ImageResult
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
@ -83,7 +85,41 @@ class RageshakeDetectionPresenterTest { @@ -83,7 +85,41 @@ class RageshakeDetectionPresenterTest {
}
@Test
fun `present - screenshot then dismiss`() = runTest {
fun `present - screenshot with success then dismiss`() = runTest {
val screenshotHolder = FakeScreenshotHolder(screenshotUri = null)
val rageshake = FakeRageShake(isAvailableValue = true)
val rageshakeDataStore = FakeRageshakeDataStore(isEnabled = true)
val presenter = RageshakeDetectionPresenter(
screenshotHolder = screenshotHolder,
rageShake = rageshake,
preferencesPresenter = RageshakePreferencesPresenter(
rageshake = rageshake,
rageshakeDataStore = rageshakeDataStore,
)
)
moleculeFlow(RecompositionClock.Immediate) {
presenter.present()
}.test {
skipItems(1)
val initialState = awaitItem()
assertThat(initialState.isStarted).isFalse()
initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection)
assertThat(awaitItem().isStarted).isTrue()
rageshake.triggerPhoneRageshake()
assertThat(awaitItem().takeScreenshot).isTrue()
initialState.eventSink.invoke(
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap()))
)
assertThat(awaitItem().showDialog).isTrue()
initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss)
val finalState = awaitItem()
assertThat(finalState.showDialog).isFalse()
assertThat(rageshakeDataStore.isEnabled().first()).isTrue()
}
}
@Test
fun `present - screenshot with error then dismiss`() = runTest {
val screenshotHolder = FakeScreenshotHolder(screenshotUri = null)
val rageshake = FakeRageShake(isAvailableValue = true)
val rageshakeDataStore = FakeRageshakeDataStore(isEnabled = true)
@ -140,7 +176,7 @@ class RageshakeDetectionPresenterTest { @@ -140,7 +176,7 @@ class RageshakeDetectionPresenterTest {
rageshake.triggerPhoneRageshake()
assertThat(awaitItem().takeScreenshot).isTrue()
initialState.eventSink.invoke(
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Error(Exception("Error")))
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap()))
)
assertThat(awaitItem().showDialog).isTrue()
initialState.eventSink.invoke(RageshakeDetectionEvents.Disable)
@ -150,3 +186,6 @@ class RageshakeDetectionPresenterTest { @@ -150,3 +186,6 @@ class RageshakeDetectionPresenterTest {
}
}
}
private fun aBitmap(): Bitmap = mockk()

2
gradle/libs.versions.toml

@ -97,7 +97,7 @@ test_junit = "junit:junit:4.13.2" @@ -97,7 +97,7 @@ test_junit = "junit:junit:4.13.2"
test_runner = "androidx.test:runner:1.4.0"
test_uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0"
test_junitext = "androidx.test.ext:junit:1.1.3"
test_mockk = "io.mockk:mockk:1.13.2"
test_mockk = "io.mockk:mockk:1.13.4"
test_barista = "com.adevinta.android:barista:4.2.0"
test_hamcrest = "org.hamcrest:hamcrest:2.2"
test_orchestrator = "androidx.test:orchestrator:1.4.1"

Loading…
Cancel
Save