test(reaction): Add ViewModel and reaction logic unit tests

Extract pure decision functions from AutoConnect and PopUpReaction for testability, following the existing PlayPause pattern. Add FakeDataStoreValue test helper.

Fix reversed Duration.between args in PopUpReaction connection monitor that caused the false-positive age filter to never trigger.
This commit is contained in:
darken
2026-03-07 14:19:17 +00:00
committed by Matthias Urhahn
parent da6a6f6ff2
commit 450a187b65
7 changed files with 1199 additions and 65 deletions
@@ -0,0 +1,29 @@
package testhelpers.datastore
import eu.darken.capod.common.datastore.DataStoreValue
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.flow.MutableStateFlow
class FakeDataStoreValue<T>(initial: T) {
private val _flow = MutableStateFlow(initial)
val mock: DataStoreValue<T> = mockk<DataStoreValue<T>>().also { m ->
every { m.flow } returns _flow
coEvery { m.update(any()) } coAnswers {
@Suppress("UNCHECKED_CAST")
val transform = firstArg<(T) -> T>()
val old = _flow.value
val new = transform(old)
_flow.value = new
DataStoreValue.Updated(old, new)
}
}
var value: T
get() = _flow.value
set(v) {
_flow.value = v
}
}