Unblock develop

This commit is contained in:
Benoit Marty 2023-06-13 11:10:29 +02:00
parent 1734b3ec60
commit 3c250b2a0d
4 changed files with 18 additions and 22 deletions

View file

@ -330,7 +330,7 @@ class MessagesPresenterTest {
networkMonitor = FakeNetworkMonitor(), networkMonitor = FakeNetworkMonitor(),
snackbarDispatcher = SnackbarDispatcher(), snackbarDispatcher = SnackbarDispatcher(),
messageSummaryFormatter = FakeMessageSummaryFormatter(), messageSummaryFormatter = FakeMessageSummaryFormatter(),
dispatchers = testCoroutineDispatchers(testScheduler), dispatchers = testCoroutineDispatchers(),
) )
} }
} }

View file

@ -23,7 +23,6 @@ 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
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import io.element.android.features.messages.impl.media.local.MediaInfo
import io.element.android.features.messages.impl.media.local.aFileInfo import io.element.android.features.messages.impl.media.local.aFileInfo
import io.element.android.features.messages.impl.media.viewer.MediaViewerEvents import io.element.android.features.messages.impl.media.viewer.MediaViewerEvents
import io.element.android.features.messages.impl.media.viewer.MediaViewerNode import io.element.android.features.messages.impl.media.viewer.MediaViewerNode
@ -49,8 +48,8 @@ class MediaViewerPresenterTest {
@Test @Test
fun `present - download media success scenario`() = runTest { fun `present - download media success scenario`() = runTest {
val coroutineDispatchers = testCoroutineDispatchers(testScheduler, useUnconfinedTestDispatcher = false) val coroutineDispatchers = testCoroutineDispatchers(useUnconfinedTestDispatcher = false)
val mediaLoader = FakeMediaLoader(coroutineDispatchers) val mediaLoader = FakeMediaLoader()
val mediaActions = FakeLocalMediaActions(coroutineDispatchers) val mediaActions = FakeLocalMediaActions(coroutineDispatchers)
val presenter = aMediaViewerPresenter(mediaLoader, mediaActions) val presenter = aMediaViewerPresenter(mediaLoader, mediaActions)
moleculeFlow(RecompositionClock.Immediate) { moleculeFlow(RecompositionClock.Immediate) {
@ -70,8 +69,8 @@ class MediaViewerPresenterTest {
@Test @Test
fun `present - check all actions `() = runTest { fun `present - check all actions `() = runTest {
val coroutineDispatchers = testCoroutineDispatchers(testScheduler, useUnconfinedTestDispatcher = false) val coroutineDispatchers = testCoroutineDispatchers(useUnconfinedTestDispatcher = false)
val mediaLoader = FakeMediaLoader(coroutineDispatchers) val mediaLoader = FakeMediaLoader()
val mediaActions = FakeLocalMediaActions(coroutineDispatchers) val mediaActions = FakeLocalMediaActions(coroutineDispatchers)
val presenter = aMediaViewerPresenter(mediaLoader, mediaActions) val presenter = aMediaViewerPresenter(mediaLoader, mediaActions)
moleculeFlow(RecompositionClock.Immediate) { moleculeFlow(RecompositionClock.Immediate) {
@ -119,8 +118,8 @@ class MediaViewerPresenterTest {
@Test @Test
fun `present - download media failure then retry with success scenario`() = runTest { fun `present - download media failure then retry with success scenario`() = runTest {
val coroutineDispatchers = testCoroutineDispatchers(testScheduler, useUnconfinedTestDispatcher = false) val coroutineDispatchers = testCoroutineDispatchers(useUnconfinedTestDispatcher = false)
val mediaLoader = FakeMediaLoader(coroutineDispatchers) val mediaLoader = FakeMediaLoader()
val mediaActions = FakeLocalMediaActions(coroutineDispatchers) val mediaActions = FakeLocalMediaActions(coroutineDispatchers)
val presenter = aMediaViewerPresenter(mediaLoader, mediaActions) val presenter = aMediaViewerPresenter(mediaLoader, mediaActions)
moleculeFlow(RecompositionClock.Immediate) { moleculeFlow(RecompositionClock.Immediate) {

View file

@ -37,18 +37,15 @@ import io.element.android.libraries.matrix.test.pushers.FakePushersService
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
import io.element.android.libraries.matrix.test.room.FakeRoomSummaryDataSource import io.element.android.libraries.matrix.test.room.FakeRoomSummaryDataSource
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
import io.element.android.tests.testutils.testCoroutineDispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.test.StandardTestDispatcher
class FakeMatrixClient( class FakeMatrixClient(
override val sessionId: SessionId = A_SESSION_ID, override val sessionId: SessionId = A_SESSION_ID,
private val coroutineDispatchers: CoroutineDispatchers = testCoroutineDispatchers(),
private val userDisplayName: Result<String> = Result.success(A_USER_NAME), private val userDisplayName: Result<String> = Result.success(A_USER_NAME),
private val userAvatarURLString: Result<String> = Result.success(AN_AVATAR_URL), private val userAvatarURLString: Result<String> = Result.success(AN_AVATAR_URL),
override val roomSummaryDataSource: RoomSummaryDataSource = FakeRoomSummaryDataSource(), override val roomSummaryDataSource: RoomSummaryDataSource = FakeRoomSummaryDataSource(),
override val invitesDataSource: RoomSummaryDataSource = FakeRoomSummaryDataSource(), override val invitesDataSource: RoomSummaryDataSource = FakeRoomSummaryDataSource(),
override val mediaLoader: MatrixMediaLoader = FakeMediaLoader(coroutineDispatchers), override val mediaLoader: MatrixMediaLoader = FakeMediaLoader(),
private val sessionVerificationService: FakeSessionVerificationService = FakeSessionVerificationService(), private val sessionVerificationService: FakeSessionVerificationService = FakeSessionVerificationService(),
private val pushersService: FakePushersService = FakePushersService(), private val pushersService: FakePushersService = FakePushersService(),
private val notificationService: FakeNotificationService = FakeNotificationService(), private val notificationService: FakeNotificationService = FakeNotificationService(),

View file

@ -16,37 +16,37 @@
package io.element.android.libraries.matrix.test.media package io.element.android.libraries.matrix.test.media
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
import io.element.android.libraries.matrix.api.media.MediaFile import io.element.android.libraries.matrix.api.media.MediaFile
import io.element.android.libraries.matrix.api.media.MediaSource import io.element.android.libraries.matrix.api.media.MediaSource
import io.element.android.libraries.matrix.test.FAKE_DELAY_IN_MS import io.element.android.libraries.matrix.test.FAKE_DELAY_IN_MS
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import kotlin.coroutines.coroutineContext
class FakeMediaLoader(private val coroutineDispatchers: CoroutineDispatchers) : MatrixMediaLoader { class FakeMediaLoader : MatrixMediaLoader {
var shouldFail = false var shouldFail = false
override suspend fun loadMediaContent(source: MediaSource): Result<ByteArray> = withContext(coroutineDispatchers.io){ override suspend fun loadMediaContent(source: MediaSource): Result<ByteArray> {
if (shouldFail) { delay(FAKE_DELAY_IN_MS)
return if (shouldFail) {
Result.failure(RuntimeException()) Result.failure(RuntimeException())
} else { } else {
Result.success(ByteArray(0)) Result.success(ByteArray(0))
} }
} }
override suspend fun loadMediaThumbnail(source: MediaSource, width: Long, height: Long): Result<ByteArray> = withContext(coroutineDispatchers.io){ override suspend fun loadMediaThumbnail(source: MediaSource, width: Long, height: Long): Result<ByteArray> {
if (shouldFail) { delay(FAKE_DELAY_IN_MS)
return if (shouldFail) {
Result.failure(RuntimeException()) Result.failure(RuntimeException())
} else { } else {
Result.success(ByteArray(0)) Result.success(ByteArray(0))
} }
} }
override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?, body: String?): Result<MediaFile> = withContext(coroutineDispatchers.io){ override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?, body: String?): Result<MediaFile> {
if (shouldFail) { delay(FAKE_DELAY_IN_MS)
return if (shouldFail) {
Result.failure(RuntimeException()) Result.failure(RuntimeException())
} else { } else {
Result.success(FakeMediaFile("")) Result.success(FakeMediaFile(""))