tests : refactor some classes
This commit is contained in:
@@ -95,6 +95,7 @@ import io.element.android.tests.testutils.testCoroutineDispatchers
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.test.TestScope
|
import kotlinx.coroutines.test.TestScope
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
@@ -219,7 +220,7 @@ class RoomListPresenterTest {
|
|||||||
val encryptionService = FakeEncryptionService().apply {
|
val encryptionService = FakeEncryptionService().apply {
|
||||||
emitRecoveryState(RecoveryState.INCOMPLETE)
|
emitRecoveryState(RecoveryState.INCOMPLETE)
|
||||||
}
|
}
|
||||||
val syncService = FakeSyncService(initialState = SyncState.Running)
|
val syncService = FakeSyncService(MutableStateFlow(SyncState.Running))
|
||||||
val presenter = createRoomListPresenter(
|
val presenter = createRoomListPresenter(
|
||||||
client = FakeMatrixClient(roomListService = roomListService, encryptionService = encryptionService, syncService = syncService),
|
client = FakeMatrixClient(roomListService = roomListService, encryptionService = encryptionService, syncService = syncService),
|
||||||
coroutineScope = scope,
|
coroutineScope = scope,
|
||||||
@@ -250,7 +251,7 @@ class RoomListPresenterTest {
|
|||||||
sessionVerificationService = FakeSessionVerificationService().apply {
|
sessionVerificationService = FakeSessionVerificationService().apply {
|
||||||
givenNeedsSessionVerification(false)
|
givenNeedsSessionVerification(false)
|
||||||
},
|
},
|
||||||
syncService = FakeSyncService(initialState = SyncState.Running)
|
syncService = FakeSyncService(MutableStateFlow(SyncState.Running))
|
||||||
)
|
)
|
||||||
val scope = CoroutineScope(context = coroutineContext + SupervisorJob())
|
val scope = CoroutineScope(context = coroutineContext + SupervisorJob())
|
||||||
val presenter = createRoomListPresenter(
|
val presenter = createRoomListPresenter(
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ class FakeMatrixRoom(
|
|||||||
private val saveComposerDraftLambda: (ComposerDraft) -> Result<Unit> = { _: ComposerDraft -> Result.success(Unit) },
|
private val saveComposerDraftLambda: (ComposerDraft) -> Result<Unit> = { _: ComposerDraft -> Result.success(Unit) },
|
||||||
private val loadComposerDraftLambda: () -> Result<ComposerDraft?> = { Result.success<ComposerDraft?>(null) },
|
private val loadComposerDraftLambda: () -> Result<ComposerDraft?> = { Result.success<ComposerDraft?>(null) },
|
||||||
private val clearComposerDraftLambda: () -> Result<Unit> = { Result.success(Unit) },
|
private val clearComposerDraftLambda: () -> Result<Unit> = { Result.success(Unit) },
|
||||||
|
private val subscribeToSyncLambda: () -> Unit = { lambdaError() },
|
||||||
) : MatrixRoom {
|
) : MatrixRoom {
|
||||||
private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1)
|
private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1)
|
||||||
override val roomInfoFlow: Flow<MatrixRoomInfo> = _roomInfoFlow
|
override val roomInfoFlow: Flow<MatrixRoomInfo> = _roomInfoFlow
|
||||||
@@ -181,7 +182,9 @@ class FakeMatrixRoom(
|
|||||||
timelineFocusedOnEventResult(eventId)
|
timelineFocusedOnEventResult(eventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun subscribeToSync() = Unit
|
override suspend fun subscribeToSync() {
|
||||||
|
subscribeToSyncLambda()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun powerLevels(): Result<MatrixRoomPowerLevels> {
|
override suspend fun powerLevels(): Result<MatrixRoomPowerLevels> {
|
||||||
return powerLevelsResult()
|
return powerLevelsResult()
|
||||||
|
|||||||
@@ -22,22 +22,16 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
class FakeSyncService(
|
class FakeSyncService(
|
||||||
initialState: SyncState = SyncState.Idle
|
syncStateFlow: MutableStateFlow<SyncState> = MutableStateFlow(SyncState.Idle)
|
||||||
) : SyncService {
|
) : SyncService {
|
||||||
private val syncStateFlow = MutableStateFlow(initialState)
|
var startSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
|
||||||
|
|
||||||
fun simulateError() {
|
|
||||||
syncStateFlow.value = SyncState.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun startSync(): Result<Unit> {
|
override suspend fun startSync(): Result<Unit> {
|
||||||
syncStateFlow.value = SyncState.Running
|
return startSyncLambda()
|
||||||
return Result.success(Unit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var stopSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
|
||||||
override suspend fun stopSync(): Result<Unit> {
|
override suspend fun stopSync(): Result<Unit> {
|
||||||
syncStateFlow.value = SyncState.Terminated
|
return stopSyncLambda()
|
||||||
return Result.success(Unit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val syncState: StateFlow<SyncState> = syncStateFlow
|
override val syncState: StateFlow<SyncState> = syncStateFlow
|
||||||
|
|||||||
@@ -82,4 +82,6 @@ dependencies {
|
|||||||
testImplementation(projects.services.appnavstate.test)
|
testImplementation(projects.services.appnavstate.test)
|
||||||
testImplementation(projects.services.toolbox.impl)
|
testImplementation(projects.services.toolbox.impl)
|
||||||
testImplementation(projects.services.toolbox.test)
|
testImplementation(projects.services.toolbox.test)
|
||||||
|
testImplementation(projects.libraries.featureflag.test)
|
||||||
|
testImplementation(libs.kotlinx.collections.immutable)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import io.element.android.services.appnavstate.test.A_ROOM_OWNER
|
|||||||
import io.element.android.services.appnavstate.test.A_SESSION_OWNER
|
import io.element.android.services.appnavstate.test.A_SESSION_OWNER
|
||||||
import io.element.android.services.appnavstate.test.A_SPACE_OWNER
|
import io.element.android.services.appnavstate.test.A_SPACE_OWNER
|
||||||
import io.element.android.services.appnavstate.test.A_THREAD_OWNER
|
import io.element.android.services.appnavstate.test.A_THREAD_OWNER
|
||||||
|
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
|
||||||
import io.element.android.tests.testutils.runCancellableScopeTest
|
import io.element.android.tests.testutils.runCancellableScopeTest
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.services.appnavstate.impl
|
package io.element.android.services.appnavstate.test
|
||||||
|
|
||||||
import io.element.android.services.appnavstate.api.AppForegroundStateService
|
import io.element.android.services.appnavstate.api.AppForegroundStateService
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
Reference in New Issue
Block a user