mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Create FakeAppErrorStateService
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
+36
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user