mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
feat(widget): implement home screen widget and fix Google Sheets range synchronization
- Add SatieaAppWidgetProvider with last meal recap, daily summary, and 1-tap logging shortcuts - Implement reactive UDF quick-log action in MealViewModel and MainActivity - Safeguard widget updates against concurrency with debounced SupervisorJob scope - Migrate Google Sheets tab names automatically and encode range URLs per RFC 3986 - Add unit tests for widget UI model formatting and range encoding
This commit is contained in:
1 parent
3d1d0f43e7
commit
1d6e9a3752
17 files changed
+708
-23
No files matched your search
@@ -152,6 +152,7 @@ class GoogleSheetsDataFormatterTest {
|
||||
assertEquals("https://drive.google.com/file/1", rows[1][9])
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
fun `encodePathRange replaces plus signs with percent twenty according to RFC 3986`() {
|
||||
val range = "'Journal des repas'!A1"
|
||||
@@ -161,6 +162,9 @@ class GoogleSheetsDataFormatterTest {
|
||||
val foodRange = "'Mes plats et aliments'!A1:C"
|
||||
val foodEncoded = com.example.util.GoogleSheetsSyncService.encodePathRange(foodRange)
|
||||
assertEquals("%27Mes%20plats%20et%20aliments%27%21A1%3AC", foodEncoded)
|
||||
assertTrue(!encoded.contains("+"))
|
||||
assertTrue(!foodEncoded.contains("+"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.example
|
||||
|
||||
import com.example.data.model.FoodUnit
|
||||
import com.example.data.model.MealEntry
|
||||
import com.example.data.model.MealFoodItem
|
||||
import com.example.data.model.MealType
|
||||
import com.example.widget.SatieaAppWidgetProvider
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
|
||||
class SatieaWidgetModelTest {
|
||||
|
||||
private val testZone = ZoneId.of("Europe/Paris")
|
||||
|
||||
@Test
|
||||
fun `suggestMealTypeForHour returns right meal type for each time window`() {
|
||||
assertEquals(MealType.BREAKFAST, SatieaAppWidgetProvider.suggestMealTypeForHour(8))
|
||||
assertEquals(MealType.LUNCH, SatieaAppWidgetProvider.suggestMealTypeForHour(12))
|
||||
assertEquals(MealType.SNACK, SatieaAppWidgetProvider.suggestMealTypeForHour(16))
|
||||
assertEquals(MealType.DINNER, SatieaAppWidgetProvider.suggestMealTypeForHour(20))
|
||||
assertEquals(MealType.DINNER, SatieaAppWidgetProvider.suggestMealTypeForHour(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `buildWidgetUiModel with empty meal list shows onboarding state`() {
|
||||
val nowMillis = LocalDateTime.of(2026, 11, 9, 12, 45)
|
||||
.atZone(testZone).toInstant().toEpochMilli()
|
||||
|
||||
val model = SatieaAppWidgetProvider.buildWidgetUiModel(
|
||||
meals = emptyList(),
|
||||
nowMillis = nowMillis,
|
||||
zoneId = testZone
|
||||
)
|
||||
|
||||
assertEquals("Aujourd'hui : aucun repas • Prêt à noter", model.todaySubtitle)
|
||||
assertEquals("Aucun repas enregistré", model.lastMealTitle)
|
||||
assertEquals(MealType.LUNCH, model.suggestedMealType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `buildWidgetUiModel formats latest meal and daily optimal percentage`() {
|
||||
val nowMillis = LocalDateTime.of(2026, 11, 9, 14, 0)
|
||||
.atZone(testZone).toInstant().toEpochMilli()
|
||||
|
||||
val breakfastMillis = LocalDateTime.of(2026, 11, 9, 8, 15)
|
||||
.atZone(testZone).toInstant().toEpochMilli()
|
||||
val lunchMillis = LocalDateTime.of(2026, 11, 9, 12, 30)
|
||||
.atZone(testZone).toInstant().toEpochMilli()
|
||||
|
||||
val breakfast = MealEntry(
|
||||
id = "b1",
|
||||
mealType = MealType.BREAKFAST.name,
|
||||
mealTimestamp = breakfastMillis,
|
||||
hungerBefore = 4,
|
||||
satietyAfter = 7,
|
||||
foodItemsSerialized = listOf(MealFoodItem("Flocons d'avoine", 60.0, FoodUnit.G).serialize())
|
||||
)
|
||||
|
||||
val lunch = MealEntry(
|
||||
id = "l1",
|
||||
mealType = MealType.LUNCH.name,
|
||||
mealTimestamp = lunchMillis,
|
||||
hungerBefore = 3,
|
||||
satietyAfter = 7,
|
||||
foodItemsSerialized = listOf(
|
||||
MealFoodItem("Riz complet", 150.0, FoodUnit.G).serialize(),
|
||||
MealFoodItem("Saumon", 120.0, FoodUnit.G).serialize()
|
||||
)
|
||||
)
|
||||
|
||||
val model = SatieaAppWidgetProvider.buildWidgetUiModel(
|
||||
meals = listOf(breakfast, lunch),
|
||||
nowMillis = nowMillis,
|
||||
zoneId = testZone
|
||||
)
|
||||
|
||||
assertEquals("Aujourd'hui : 2 repas • Zone optimale 100 %", model.todaySubtitle)
|
||||
assertEquals("🥗 Déjeuner • Aujourd'hui à 12:30", model.lastMealTitle)
|
||||
assertTrue(model.lastMealFoods.contains("Riz complet"))
|
||||
assertTrue(model.lastMealFoods.contains("Saumon"))
|
||||
assertEquals("Faim 3/10 → Satiété 7/10 • Zone optimale ✨", model.lastMealSatietyBadge)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user