Store density, button style and reduce motion in floret-kit's appearance prefs (#118, #157)

This commit is contained in:
makiolaj committed 2026-11-27 12:16:34 +01:00
1 parent 8a1e16c5f9
commit a94ad7560a
10 files changed
+129 -1

No files matched your search

@@ -0,0 +1,88 @@
package de.jeanlucmakiola.agendula.data.prefs
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.mutablePreferencesOf
import androidx.datastore.preferences.core.stringPreferencesKey
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.data.tasks.ProviderEnvironment
import de.jeanlucmakiola.agendula.data.tasks.ProviderResolver
import de.jeanlucmakiola.floret.prefs.ActionStyle
import de.jeanlucmakiola.floret.prefs.LayoutDensity
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
/** Density, button style and reduce motion: their defaults, and that a choice sticks. */
class AppearanceSettingsTest {
private class MemoryDataStore(initial: Preferences = emptyPreferences()) : DataStore<Preferences> {
override val data = MutableStateFlow(initial)
override suspend fun updateData(transform: suspend (t: Preferences) -> Preferences) =
transform(data.value).also { data.value = it }
}
private object NoProviders : ProviderEnvironment {
override fun packageDeclaring(authority: String): String? = null
override fun isGranted(permission: String) = false
override fun appLabel(packageName: String): String? = null
}
private fun prefs(dataStore: DataStore<Preferences> = MemoryDataStore()) =
SettingsPrefs(dataStore, ProviderResolver(NoProviders))
@Test
fun `a fresh install is comfortable, icons only, with motion on`() = runBlocking<Unit> {
val settings = prefs().settings.first()
assertThat(Triple(settings.density, settings.actionStyle, settings.reduceMotion))
.isEqualTo(Triple(LayoutDensity.COMFORTABLE, ActionStyle.ICONS, false))
}
@Test
fun `an existing install gets icons only too`() = runBlocking<Unit> {
val upgraded = MemoryDataStore(
mutablePreferencesOf(
stringPreferencesKey("theme_mode") to "DARK",
booleanPreferencesKey("dynamic_color") to false,
),
)
assertThat(prefs(upgraded).settings.first().actionStyle).isEqualTo(ActionStyle.ICONS)
}
@Test
fun `the choices are kept`() = runBlocking<Unit> {
val prefs = prefs()
prefs.setDensity(LayoutDensity.COMPACT)
prefs.setActionStyle(ActionStyle.SHAPES)
prefs.setReduceMotion(true)
val settings = prefs.settings.first()
assertThat(Triple(settings.density, settings.actionStyle, settings.reduceMotion))
.isEqualTo(Triple(LayoutDensity.COMPACT, ActionStyle.SHAPES, true))
}
@Test
fun `the choices are stored under the keys floret-kit shares`() = runBlocking<Unit> {
val dataStore = MemoryDataStore()
val prefs = prefs(dataStore)
prefs.setDensity(LayoutDensity.COMPACT)
prefs.setActionStyle(ActionStyle.SHAPES)
prefs.setReduceMotion(true)
val stored = dataStore.data.value
assertThat(
listOf(
stored[stringPreferencesKey("layout_density")],
stored[stringPreferencesKey("action_style")],
stored[booleanPreferencesKey("reduce_motion")],
),
).containsExactly("COMPACT", "SHAPES", true).inOrder()
}
}