mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-16 03:06:11 -04:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user