Create FakeAppErrorStateService
This commit is contained in:
parent
feb65aa987
commit
9ef0bf35da
2 changed files with 56 additions and 0 deletions
20
services/apperror/test/build.gradle.kts
Normal file
20
services/apperror/test/build.gradle.kts
Normal 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)
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue