Create FakeAppErrorStateService

This commit is contained in:
Benoit Marty 2025-08-13 12:32:47 +02:00
parent bb5bff7987
commit f3d4b7c546
2 changed files with 56 additions and 0 deletions

View file

@ -0,0 +1,20 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
plugins {
id("io.element.android-library")
}
android {
namespace = "io.element.android.services.apperror.test"
}
dependencies {
implementation(libs.coroutines.core)
implementation(projects.services.apperror.api)
implementation(projects.tests.testutils)
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.services.apperror.test
import io.element.android.services.apperror.api.AppErrorState
import io.element.android.services.apperror.api.AppErrorStateService
import io.element.android.tests.testutils.lambda.lambdaError
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
class FakeAppErrorStateService(
initialState: AppErrorState = AppErrorState.NoError,
private val showErrorResult: (String, String) -> Unit = { _, _ -> lambdaError() },
private val showErrorResResult: (Int, Int) -> Unit = { _, _ -> lambdaError() }
) : AppErrorStateService {
private val mutableAppErrorStateFlow = MutableStateFlow(initialState)
override val appErrorStateFlow: StateFlow<AppErrorState> = mutableAppErrorStateFlow.asStateFlow()
override fun showError(title: String, body: String) {
showErrorResult(title, body)
}
override fun showError(titleRes: Int, bodyRes: Int) {
showErrorResResult(titleRes, bodyRes)
}
fun setAppErrorState(state: AppErrorState) {
mutableAppErrorStateFlow.value = state
}
}