|
|
|
@ -21,6 +21,7 @@ import io.element.android.features.messages.impl.messagecomposer.aReplyMode
@@ -21,6 +21,7 @@ import io.element.android.features.messages.impl.messagecomposer.aReplyMode
|
|
|
|
|
import io.element.android.features.messages.impl.voicemessages.VoiceMessageException |
|
|
|
|
import io.element.android.features.messages.test.FakeMessageComposerContext |
|
|
|
|
import io.element.android.libraries.matrix.api.core.ProgressCallback |
|
|
|
|
import io.element.android.libraries.matrix.api.media.AudioInfo |
|
|
|
|
import io.element.android.libraries.matrix.test.media.FakeMediaUploadHandler |
|
|
|
|
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom |
|
|
|
|
import io.element.android.libraries.mediaplayer.test.FakeMediaPlayer |
|
|
|
@ -46,6 +47,7 @@ import kotlinx.coroutines.test.TestScope
@@ -46,6 +47,7 @@ import kotlinx.coroutines.test.TestScope
|
|
|
|
|
import kotlinx.coroutines.test.runTest |
|
|
|
|
import org.junit.Rule |
|
|
|
|
import org.junit.Test |
|
|
|
|
import java.io.File |
|
|
|
|
import kotlin.time.Duration |
|
|
|
|
import kotlin.time.Duration.Companion.seconds |
|
|
|
|
|
|
|
|
@ -57,9 +59,12 @@ class VoiceMessageComposerPresenterTest {
@@ -57,9 +59,12 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
recordingDuration = RECORDING_DURATION |
|
|
|
|
) |
|
|
|
|
private val analyticsService = FakeAnalyticsService() |
|
|
|
|
private val sendMediaResult = lambdaRecorder<ProgressCallback?, Result<FakeMediaUploadHandler>> { Result.success(FakeMediaUploadHandler()) } |
|
|
|
|
private val sendVoiceMessageResult = |
|
|
|
|
lambdaRecorder<File, AudioInfo, List<Float>, ProgressCallback?, Result<FakeMediaUploadHandler>> { _, _, _, _ -> |
|
|
|
|
Result.success(FakeMediaUploadHandler()) |
|
|
|
|
} |
|
|
|
|
private val matrixRoom = FakeMatrixRoom( |
|
|
|
|
sendMediaResult = sendMediaResult |
|
|
|
|
sendVoiceMessageResult = sendVoiceMessageResult |
|
|
|
|
) |
|
|
|
|
private val mediaPreProcessor = FakeMediaPreProcessor().apply { givenAudioResult() } |
|
|
|
|
private val mediaSender = MediaSender(mediaPreProcessor, matrixRoom, InMemorySessionPreferencesStore()) |
|
|
|
@ -292,7 +297,7 @@ class VoiceMessageComposerPresenterTest {
@@ -292,7 +297,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
|
|
|
|
|
val finalState = awaitItem() |
|
|
|
|
assertThat(finalState.voiceMessageState).isEqualTo(VoiceMessageState.Idle) |
|
|
|
|
sendMediaResult.assertions().isCalledOnce() |
|
|
|
|
sendVoiceMessageResult.assertions().isCalledOnce() |
|
|
|
|
voiceRecorder.assertCalls(started = 1, stopped = 1, deleted = 1) |
|
|
|
|
|
|
|
|
|
testPauseAndDestroy(finalState) |
|
|
|
@ -343,7 +348,7 @@ class VoiceMessageComposerPresenterTest {
@@ -343,7 +348,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
|
|
|
|
|
val finalState = awaitItem() |
|
|
|
|
assertThat(finalState.voiceMessageState).isEqualTo(VoiceMessageState.Idle) |
|
|
|
|
sendMediaResult.assertions().isCalledOnce() |
|
|
|
|
sendVoiceMessageResult.assertions().isCalledOnce() |
|
|
|
|
voiceRecorder.assertCalls(started = 1, stopped = 1, deleted = 1) |
|
|
|
|
|
|
|
|
|
testPauseAndDestroy(finalState) |
|
|
|
@ -366,7 +371,7 @@ class VoiceMessageComposerPresenterTest {
@@ -366,7 +371,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
|
|
|
|
|
val finalState = awaitItem() |
|
|
|
|
assertThat(finalState.voiceMessageState).isEqualTo(VoiceMessageState.Idle) |
|
|
|
|
sendMediaResult.assertions().isCalledOnce() |
|
|
|
|
sendVoiceMessageResult.assertions().isCalledOnce() |
|
|
|
|
voiceRecorder.assertCalls(started = 1, stopped = 1, deleted = 1) |
|
|
|
|
|
|
|
|
|
testPauseAndDestroy(finalState) |
|
|
|
@ -390,7 +395,7 @@ class VoiceMessageComposerPresenterTest {
@@ -390,7 +395,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
|
|
|
|
|
val finalState = awaitItem() |
|
|
|
|
assertThat(finalState.voiceMessageState).isEqualTo(aPreviewState(isSending = true)) |
|
|
|
|
sendMediaResult.assertions().isNeverCalled() |
|
|
|
|
sendVoiceMessageResult.assertions().isNeverCalled() |
|
|
|
|
assertThat(analyticsService.trackedErrors).hasSize(0) |
|
|
|
|
voiceRecorder.assertCalls(started = 1, stopped = 1, deleted = 0) |
|
|
|
|
|
|
|
|
@ -415,13 +420,13 @@ class VoiceMessageComposerPresenterTest {
@@ -415,13 +420,13 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
|
|
|
|
|
ensureAllEventsConsumed() |
|
|
|
|
assertThat(previewState.voiceMessageState).isEqualTo(aPreviewState()) |
|
|
|
|
sendMediaResult.assertions().isNeverCalled() |
|
|
|
|
sendVoiceMessageResult.assertions().isNeverCalled() |
|
|
|
|
|
|
|
|
|
mediaPreProcessor.givenAudioResult() |
|
|
|
|
previewState.eventSink(VoiceMessageComposerEvents.SendVoiceMessage) |
|
|
|
|
val finalState = awaitItem() |
|
|
|
|
assertThat(finalState.voiceMessageState).isEqualTo(VoiceMessageState.Idle) |
|
|
|
|
sendMediaResult.assertions().isCalledOnce() |
|
|
|
|
sendVoiceMessageResult.assertions().isCalledOnce() |
|
|
|
|
voiceRecorder.assertCalls(started = 1, stopped = 1, deleted = 1) |
|
|
|
|
|
|
|
|
|
testPauseAndDestroy(finalState) |
|
|
|
@ -458,7 +463,7 @@ class VoiceMessageComposerPresenterTest {
@@ -458,7 +463,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
assertThat(showSendFailureDialog).isFalse() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sendMediaResult.assertions().isNeverCalled() |
|
|
|
|
sendVoiceMessageResult.assertions().isNeverCalled() |
|
|
|
|
testPauseAndDestroy(finalState) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -474,7 +479,7 @@ class VoiceMessageComposerPresenterTest {
@@ -474,7 +479,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
initialState.eventSink(VoiceMessageComposerEvents.SendVoiceMessage) |
|
|
|
|
|
|
|
|
|
assertThat(initialState.voiceMessageState).isEqualTo(VoiceMessageState.Idle) |
|
|
|
|
sendMediaResult.assertions().isNeverCalled() |
|
|
|
|
sendVoiceMessageResult.assertions().isNeverCalled() |
|
|
|
|
assertThat(analyticsService.trackedErrors).hasSize(1) |
|
|
|
|
voiceRecorder.assertCalls(started = 0) |
|
|
|
|
|
|
|
|
@ -493,7 +498,7 @@ class VoiceMessageComposerPresenterTest {
@@ -493,7 +498,7 @@ class VoiceMessageComposerPresenterTest {
|
|
|
|
|
val initialState = awaitItem() |
|
|
|
|
initialState.eventSink(VoiceMessageComposerEvents.RecorderEvent(VoiceMessageRecorderEvent.Start)) |
|
|
|
|
|
|
|
|
|
sendMediaResult.assertions().isNeverCalled() |
|
|
|
|
sendVoiceMessageResult.assertions().isNeverCalled() |
|
|
|
|
assertThat(analyticsService.trackedErrors).containsExactly( |
|
|
|
|
VoiceMessageException.PermissionMissing(message = "Expected permission to record but none", cause = exception) |
|
|
|
|
) |
|
|
|
|