|
|
@ -31,10 +31,21 @@ import io.element.android.libraries.matrix.test.AN_EXCEPTION |
|
|
|
import io.mockk.mockk |
|
|
|
import io.mockk.mockk |
|
|
|
import kotlinx.coroutines.flow.first |
|
|
|
import kotlinx.coroutines.flow.first |
|
|
|
import kotlinx.coroutines.test.runTest |
|
|
|
import kotlinx.coroutines.test.runTest |
|
|
|
|
|
|
|
import org.junit.BeforeClass |
|
|
|
import org.junit.Test |
|
|
|
import org.junit.Test |
|
|
|
import kotlin.time.Duration.Companion.seconds |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RageshakeDetectionPresenterTest { |
|
|
|
class RageshakeDetectionPresenterTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
private lateinit var aBitmap: Bitmap |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass |
|
|
|
|
|
|
|
@JvmStatic |
|
|
|
|
|
|
|
fun initBitmap() { |
|
|
|
|
|
|
|
aBitmap = mockk() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun `present - initial state`() = runTest { |
|
|
|
fun `present - initial state`() = runTest { |
|
|
|
val screenshotHolder = FakeScreenshotHolder(screenshotUri = null) |
|
|
|
val screenshotHolder = FakeScreenshotHolder(screenshotUri = null) |
|
|
@ -85,7 +96,7 @@ class RageshakeDetectionPresenterTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun `present - screenshot with success then dismiss`() = runTest(timeout = 30.seconds) { |
|
|
|
fun `present - screenshot with success 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) |
|
|
@ -108,7 +119,7 @@ class RageshakeDetectionPresenterTest { |
|
|
|
rageshake.triggerPhoneRageshake() |
|
|
|
rageshake.triggerPhoneRageshake() |
|
|
|
assertThat(awaitItem().takeScreenshot).isTrue() |
|
|
|
assertThat(awaitItem().takeScreenshot).isTrue() |
|
|
|
initialState.eventSink.invoke( |
|
|
|
initialState.eventSink.invoke( |
|
|
|
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap())) |
|
|
|
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap)) |
|
|
|
) |
|
|
|
) |
|
|
|
assertThat(awaitItem().showDialog).isTrue() |
|
|
|
assertThat(awaitItem().showDialog).isTrue() |
|
|
|
initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss) |
|
|
|
initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss) |
|
|
@ -153,7 +164,7 @@ class RageshakeDetectionPresenterTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun `present - screenshot then disable`() = runTest(timeout = 1.seconds) { |
|
|
|
fun `present - screenshot then disable`() = 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) |
|
|
@ -176,7 +187,7 @@ class RageshakeDetectionPresenterTest { |
|
|
|
rageshake.triggerPhoneRageshake() |
|
|
|
rageshake.triggerPhoneRageshake() |
|
|
|
assertThat(awaitItem().takeScreenshot).isTrue() |
|
|
|
assertThat(awaitItem().takeScreenshot).isTrue() |
|
|
|
initialState.eventSink.invoke( |
|
|
|
initialState.eventSink.invoke( |
|
|
|
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap())) |
|
|
|
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap)) |
|
|
|
) |
|
|
|
) |
|
|
|
assertThat(awaitItem().showDialog).isTrue() |
|
|
|
assertThat(awaitItem().showDialog).isTrue() |
|
|
|
initialState.eventSink.invoke(RageshakeDetectionEvents.Disable) |
|
|
|
initialState.eventSink.invoke(RageshakeDetectionEvents.Disable) |
|
|
@ -187,5 +198,3 @@ class RageshakeDetectionPresenterTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun aBitmap(): Bitmap = mockk() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|