RageshakeDetectionEvents -> RageshakeDetectionEvent
This commit is contained in:
+7
-7
@@ -16,7 +16,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvents
|
||||
import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvent
|
||||
import io.element.android.features.rageshake.api.detection.RageshakeDetectionPresenter
|
||||
import io.element.android.features.rageshake.api.detection.RageshakeDetectionState
|
||||
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesEvents
|
||||
@@ -48,16 +48,16 @@ class DefaultRageshakeDetectionPresenter(
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
fun handleEvent(event: RageshakeDetectionEvents) {
|
||||
fun handleEvent(event: RageshakeDetectionEvent) {
|
||||
when (event) {
|
||||
RageshakeDetectionEvents.Disable -> {
|
||||
RageshakeDetectionEvent.Disable -> {
|
||||
preferencesState.eventSink(RageshakePreferencesEvents.SetIsEnabled(false))
|
||||
showDialog.value = false
|
||||
}
|
||||
RageshakeDetectionEvents.StartDetection -> isStarted.value = true
|
||||
RageshakeDetectionEvents.StopDetection -> isStarted.value = false
|
||||
is RageshakeDetectionEvents.ProcessScreenshot -> localCoroutineScope.processScreenshot(takeScreenshot, showDialog, event.imageResult)
|
||||
RageshakeDetectionEvents.Dismiss -> showDialog.value = false
|
||||
RageshakeDetectionEvent.StartDetection -> isStarted.value = true
|
||||
RageshakeDetectionEvent.StopDetection -> isStarted.value = false
|
||||
is RageshakeDetectionEvent.ProcessScreenshot -> localCoroutineScope.processScreenshot(takeScreenshot, showDialog, event.imageResult)
|
||||
RageshakeDetectionEvent.Dismiss -> showDialog.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -13,7 +13,7 @@ import app.cash.molecule.RecompositionMode
|
||||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvents
|
||||
import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvent
|
||||
import io.element.android.features.rageshake.api.screenshot.ImageResult
|
||||
import io.element.android.features.rageshake.impl.preferences.DefaultRageshakePreferencesPresenter
|
||||
import io.element.android.features.rageshake.impl.rageshake.FakeRageShake
|
||||
@@ -87,9 +87,9 @@ class RageshakeDetectionPresenterTest {
|
||||
}.test {
|
||||
skipItems(1)
|
||||
val initialState = awaitItem()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection)
|
||||
assertThat(awaitItem().isStarted).isTrue()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.StopDetection)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.StopDetection)
|
||||
assertThat(awaitItem().isStarted).isFalse()
|
||||
}
|
||||
}
|
||||
@@ -114,15 +114,15 @@ class RageshakeDetectionPresenterTest {
|
||||
skipItems(1)
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.isStarted).isFalse()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection)
|
||||
assertThat(awaitItem().isStarted).isTrue()
|
||||
rageshake.triggerPhoneRageshake()
|
||||
assertThat(awaitItem().takeScreenshot).isTrue()
|
||||
initialState.eventSink.invoke(
|
||||
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap))
|
||||
RageshakeDetectionEvent.ProcessScreenshot(ImageResult.Success(aBitmap))
|
||||
)
|
||||
assertThat(awaitItem().showDialog).isTrue()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.Dismiss)
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.showDialog).isFalse()
|
||||
assertThat(rageshakeDataStore.isEnabled().first()).isTrue()
|
||||
@@ -149,15 +149,15 @@ class RageshakeDetectionPresenterTest {
|
||||
skipItems(1)
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.isStarted).isFalse()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection)
|
||||
assertThat(awaitItem().isStarted).isTrue()
|
||||
rageshake.triggerPhoneRageshake()
|
||||
assertThat(awaitItem().takeScreenshot).isTrue()
|
||||
initialState.eventSink.invoke(
|
||||
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Error(AN_EXCEPTION))
|
||||
RageshakeDetectionEvent.ProcessScreenshot(ImageResult.Error(AN_EXCEPTION))
|
||||
)
|
||||
assertThat(awaitItem().showDialog).isTrue()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.Dismiss)
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.showDialog).isFalse()
|
||||
assertThat(rageshakeDataStore.isEnabled().first()).isTrue()
|
||||
@@ -184,15 +184,15 @@ class RageshakeDetectionPresenterTest {
|
||||
skipItems(1)
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.isStarted).isFalse()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection)
|
||||
assertThat(awaitItem().isStarted).isTrue()
|
||||
rageshake.triggerPhoneRageshake()
|
||||
assertThat(awaitItem().takeScreenshot).isTrue()
|
||||
initialState.eventSink.invoke(
|
||||
RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap))
|
||||
RageshakeDetectionEvent.ProcessScreenshot(ImageResult.Success(aBitmap))
|
||||
)
|
||||
assertThat(awaitItem().showDialog).isTrue()
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvents.Disable)
|
||||
initialState.eventSink.invoke(RageshakeDetectionEvent.Disable)
|
||||
skipItems(1)
|
||||
assertThat(awaitItem().showDialog).isFalse()
|
||||
assertThat(rageshakeDataStore.isEnabled().first()).isFalse()
|
||||
|
||||
Reference in New Issue
Block a user