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.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
@@ -219,7 +220,7 @@ class RoomListPresenterTest {
|
||||
val encryptionService = FakeEncryptionService().apply {
|
||||
emitRecoveryState(RecoveryState.INCOMPLETE)
|
||||
}
|
||||
val syncService = FakeSyncService(initialState = SyncState.Running)
|
||||
val syncService = FakeSyncService(MutableStateFlow(SyncState.Running))
|
||||
val presenter = createRoomListPresenter(
|
||||
client = FakeMatrixClient(roomListService = roomListService, encryptionService = encryptionService, syncService = syncService),
|
||||
coroutineScope = scope,
|
||||
@@ -250,7 +251,7 @@ class RoomListPresenterTest {
|
||||
sessionVerificationService = FakeSessionVerificationService().apply {
|
||||
givenNeedsSessionVerification(false)
|
||||
},
|
||||
syncService = FakeSyncService(initialState = SyncState.Running)
|
||||
syncService = FakeSyncService(MutableStateFlow(SyncState.Running))
|
||||
)
|
||||
val scope = CoroutineScope(context = coroutineContext + SupervisorJob())
|
||||
val presenter = createRoomListPresenter(
|
||||
|
||||
@@ -139,6 +139,7 @@ class FakeMatrixRoom(
|
||||
private val saveComposerDraftLambda: (ComposerDraft) -> Result<Unit> = { _: ComposerDraft -> Result.success(Unit) },
|
||||
private val loadComposerDraftLambda: () -> Result<ComposerDraft?> = { Result.success<ComposerDraft?>(null) },
|
||||
private val clearComposerDraftLambda: () -> Result<Unit> = { Result.success(Unit) },
|
||||
private val subscribeToSyncLambda: () -> Unit = { lambdaError() },
|
||||
) : MatrixRoom {
|
||||
private val _roomInfoFlow: MutableSharedFlow<MatrixRoomInfo> = MutableSharedFlow(replay = 1)
|
||||
override val roomInfoFlow: Flow<MatrixRoomInfo> = _roomInfoFlow
|
||||
@@ -181,7 +182,9 @@ class FakeMatrixRoom(
|
||||
timelineFocusedOnEventResult(eventId)
|
||||
}
|
||||
|
||||
override suspend fun subscribeToSync() = Unit
|
||||
override suspend fun subscribeToSync() {
|
||||
subscribeToSyncLambda()
|
||||
}
|
||||
|
||||
override suspend fun powerLevels(): Result<MatrixRoomPowerLevels> {
|
||||
return powerLevelsResult()
|
||||
|
||||
@@ -22,22 +22,16 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
class FakeSyncService(
|
||||
initialState: SyncState = SyncState.Idle
|
||||
syncStateFlow: MutableStateFlow<SyncState> = MutableStateFlow(SyncState.Idle)
|
||||
) : SyncService {
|
||||
private val syncStateFlow = MutableStateFlow(initialState)
|
||||
|
||||
fun simulateError() {
|
||||
syncStateFlow.value = SyncState.Error
|
||||
}
|
||||
|
||||
var startSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
|
||||
override suspend fun startSync(): Result<Unit> {
|
||||
syncStateFlow.value = SyncState.Running
|
||||
return Result.success(Unit)
|
||||
return startSyncLambda()
|
||||
}
|
||||
|
||||
var stopSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
|
||||
override suspend fun stopSync(): Result<Unit> {
|
||||
syncStateFlow.value = SyncState.Terminated
|
||||
return Result.success(Unit)
|
||||
return stopSyncLambda()
|
||||
}
|
||||
|
||||
override val syncState: StateFlow<SyncState> = syncStateFlow
|
||||
|
||||
@@ -82,4 +82,6 @@ dependencies {
|
||||
testImplementation(projects.services.appnavstate.test)
|
||||
testImplementation(projects.services.toolbox.impl)
|
||||
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_SPACE_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 kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 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 kotlinx.coroutines.flow.MutableStateFlow
|
||||
Reference in New Issue
Block a user