More tests for RageshakeDetectionPresenterTest
This commit is contained in:
parent
23f206f7f2
commit
5292fc9fbc
3 changed files with 43 additions and 3 deletions
|
|
@ -52,6 +52,7 @@ dependencies {
|
||||||
testImplementation(libs.test.truth)
|
testImplementation(libs.test.truth)
|
||||||
testImplementation(libs.test.turbine)
|
testImplementation(libs.test.turbine)
|
||||||
testImplementation(projects.libraries.matrixtest)
|
testImplementation(projects.libraries.matrixtest)
|
||||||
|
testImplementation(libs.test.mockk)
|
||||||
|
|
||||||
androidTestImplementation(libs.test.junitext)
|
androidTestImplementation(libs.test.junitext)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
package io.element.android.features.rageshake.detection
|
package io.element.android.features.rageshake.detection
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
import app.cash.molecule.RecompositionClock
|
import app.cash.molecule.RecompositionClock
|
||||||
import app.cash.molecule.moleculeFlow
|
import app.cash.molecule.moleculeFlow
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
|
|
@ -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.FakeRageshakeDataStore
|
||||||
import io.element.android.features.rageshake.preferences.RageshakePreferencesPresenter
|
import io.element.android.features.rageshake.preferences.RageshakePreferencesPresenter
|
||||||
import io.element.android.features.rageshake.screenshot.ImageResult
|
import io.element.android.features.rageshake.screenshot.ImageResult
|
||||||
|
import io.mockk.mockk
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
|
@ -83,7 +85,41 @@ class RageshakeDetectionPresenterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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 screenshotHolder = FakeScreenshotHolder(screenshotUri = null)
|
||||||
val rageshake = FakeRageShake(isAvailableValue = true)
|
val rageshake = FakeRageShake(isAvailableValue = true)
|
||||||
val rageshakeDataStore = FakeRageshakeDataStore(isEnabled = true)
|
val rageshakeDataStore = FakeRageshakeDataStore(isEnabled = true)
|
||||||
|
|
@ -140,7 +176,7 @@ class RageshakeDetectionPresenterTest {
|
||||||
rageshake.triggerPhoneRageshake()
|
rageshake.triggerPhoneRageshake()
|
||||||
assertThat(awaitItem().takeScreenshot).isTrue()
|
assertThat(awaitItem().takeScreenshot).isTrue()
|
||||||
initialState.eventSink.invoke(
|
initialState.eventSink.invoke(
|
||||||
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Error(Exception("Error")))
|
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap()))
|
||||||
)
|
)
|
||||||
assertThat(awaitItem().showDialog).isTrue()
|
assertThat(awaitItem().showDialog).isTrue()
|
||||||
initialState.eventSink.invoke(RageshakeDetectionEvents.Disable)
|
initialState.eventSink.invoke(RageshakeDetectionEvents.Disable)
|
||||||
|
|
@ -150,3 +186,6 @@ class RageshakeDetectionPresenterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun aBitmap(): Bitmap = mockk()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ test_junit = "junit:junit:4.13.2"
|
||||||
test_runner = "androidx.test:runner:1.4.0"
|
test_runner = "androidx.test:runner:1.4.0"
|
||||||
test_uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0"
|
test_uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0"
|
||||||
test_junitext = "androidx.test.ext:junit:1.1.3"
|
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_barista = "com.adevinta.android:barista:4.2.0"
|
||||||
test_hamcrest = "org.hamcrest:hamcrest:2.2"
|
test_hamcrest = "org.hamcrest:hamcrest:2.2"
|
||||||
test_orchestrator = "androidx.test:orchestrator:1.4.1"
|
test_orchestrator = "androidx.test:orchestrator:1.4.1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue