Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Android Widgets: guards for the new Mochi Big, and the README

Claude5c4ffcc4be3f
diff --git a/android/README.md b/android/README.md
index 8761c7af..0e55cb15 100644
--- a/android/README.md
+++ b/android/README.md
@@ -62,7 +62,7 @@ The desktop side is in `windows/src-tauri/src/phone_link`; the protocol is `docs
- *Agents summary* (3x2, the first Widget, same receiver as before): its text and counts are unchanged, now on the shared card with a small Mochi in the state of your most urgent agent, a headline with a badge for what waits for you and up to three short lines with a state dot each. A tap anywhere opens the app; it has no buttons.
- *Mochi at a glance* (Solo, 2x2): Mochi in the state of your most urgent agent, its name and a state word.
- *All your agents* (List, 4x3): one row of at least 48dp per agent (Mochi's face, name, state word, dot), up to five, with a badge for what waits for you; with no agent, a centred empty state ("Waiting for your computer" / "No agents running").
- - *Mochi, big* (4x4): a large Mochi with a speech bubble such as "Claude Code is working" (a name and a state, never a command or a file), the status line and rounded buttons under it: Home, Chat, Settings, Recent, the top agent and Pair again (tinted orange while something waits). Smaller, one row of four, then none.
+ - *Mochi, big* (4x4): no speech bubble any more. On the left Mochi with his glow and badge, then the agent's name and state word; on the right your plan usage (Claude and Codex, each with a big percentage and a thin bar that is green, orange above 75% and red above 90%), or "Plan usage is off" (a tap opens Settings) or "Not connected". Under them rounded buttons: two rows of three (Home, Chat, Settings, Recent, Top agent, Pair again; tinted orange while something waits), one row of four when medium, none when small.
- *One-line status* (Status Pill, 4x1): one slim line with a dot, the agent's name and its state word, and four round buttons that open Home, Chat, Settings and Recent decisions. Narrower, the state word goes first, then the name; the text never runs under the buttons.
- *Approvals waiting* (Waiting Alert, 2x2): calm when nothing waits, a bright orange "N waiting" when something does. A tap opens the app and the sheet rises by itself.
- *Plan usage* (Usage Ring, 2x2): a ring for your Claude or Codex plan usage; "Turn on plan usage in the app" when it is off.
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt
index 491f2104..10ac6ee1 100644
--- a/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetButtonsTest.kt
@@ -127,53 +127,141 @@ class WidgetButtonsTest {
// ── Mochi Big ───────────────────────────────────────────────────────────────────────────────────
- @Test fun mochiBigHasSixTilesAndEachOpensOneThing() {
- val layout = read(res + "layout/widget_big.xml")
- val ids = Regex("""@\+id/(big_tile_\w+)""").findAll(layout).map { it.groupValues[1] }.toList()
- assertEquals(listOf("big_tile_home", "big_tile_chat", "big_tile_settings", "big_tile_recent", "big_tile_session", "big_tile_pair"), ids)
- // Icon above a 12sp label, on a rounded tile.
- assertEquals(6, Regex("""@drawable/widget_tile_bg"""").findAll(layout).count())
- assertEquals(6, Regex("""android:textSize="@dimen/widget_text_secondary"[^>]*/>""").findAll(layout.substringAfter("big_buttons").substringBefore("big_badge")).count())
+ private val bigLayout get() = read(res + "layout/widget_big.xml")
+ private val bigSource get() = read(main + "app/MochiBigWidget.kt")
+ private fun byId(root: org.w3c.dom.Element, id: String) = root.descendants().first { it.getAttribute("android:id") == "@+id/$id" }
+
+ @Test fun theSpeechBubbleIsGoneFromEverywhere() {
+ val files = listOf(
+ res + "layout/widget_big.xml", res + "layout/widget_preview_big.xml", main + "app/MochiBigWidget.kt", main + "core/WidgetData.kt",
+ res + "values/strings.xml", res + "values/colors.xml", res + "values-notnight/colors.xml", "../i18n/app-strings.json",
+ )
+ for (f in files) assertFalse("$f still says bubble", read(f).contains("bubble", ignoreCase = true))
+ assertFalse(File(res + "drawable/widget_bubble.xml").exists())
+ assertFalse(File(res + "drawable/widget_bubble_tail.xml").exists())
+ assertFalse(strings.keys.any { it.contains("bubble") })
+ for (id in listOf("big_bubble")) assertFalse(id, bigLayout.contains(id) || bigSource.contains(id))
+ assertFalse(bigSource.contains(".bubble"))
+ // And so are its sentences ("Claude Code is waiting for you").
+ assertFalse(strings.values.any { it.contains("is waiting for you") || it.startsWith("Claude Code is ") })
+ }
+
+ @Test fun theTopIsMochiOnTheLeftAndThePlanUsageOnTheRight() {
+ val root = element(bigLayout)
+ val top = byId(root, "big_top")
+ assertEquals("horizontal", top.getAttribute("android:orientation"))
+ val sides = top.children()
+ assertEquals(listOf("@+id/big_left", "@+id/big_right"), sides.map { it.getAttribute("android:id") })
+ assertEquals("Mochi's side is about 45% of the width", listOf("45", "55"), sides.map { it.getAttribute("android:layout_weight") })
+ val left = byId(root, "big_left").descendants().mapNotNull { it.getAttribute("android:id").takeIf { id -> id.isNotEmpty() } }
+ assertEquals(listOf("@+id/big_mochi", "@+id/big_row", "@+id/big_dot", "@+id/big_name", "@+id/big_state"), left)
+ assertEquals("the badge stays in the top-right corner", "top|end", byId(root, "big_badge").getAttribute("android:layout_gravity"))
+ }
+
+ @Test fun thePercentageAndTheBarExist() {
+ val root = element(bigLayout)
+ for (k in listOf("a", "b")) {
+ val label = byId(root, "big_usage_${k}_label")
+ val pct = byId(root, "big_usage_${k}_pct")
+ val bar = byId(root, "big_usage_${k}_bar")
+ assertEquals("12sp label", "@dimen/widget_text_secondary", label.getAttribute("android:textSize"))
+ assertEquals("28sp bold percentage", "@dimen/widget_text_big", pct.getAttribute("android:textSize"))
+ assertEquals("bold", pct.getAttribute("android:textStyle"))
+ assertEquals("ImageView", bar.tagName)
+ assertEquals("6dp", bar.getAttribute("android:layout_height"))
+ }
+ assertEquals(28.0, dimens.getValue("widget_text_big"), 0.0)
assertEquals(12.0, dimens.getValue("widget_text_secondary"), 0.0)
- val src = read(main + "app/MochiBigWidget.kt")
- val tiles = Regex("""Tile\(R\.id\.(big_tile_\w+), (LaunchScreen\.\w+|null)\)""").findAll(src).map { it.groupValues[1] to it.groupValues[2] }.toList()
+ // The code puts the percentage and a bar bitmap in each row, and Claude and Codex are the two rows.
+ assertTrue(bigSource.contains("""v.setTextViewText(pct, "${'$'}{row.pct}%")"""))
+ assertTrue(bigSource.contains("BarBitmap.of(row,"))
+ assertTrue(bigSource.contains("R.id.big_usage_a_bar") && bigSource.contains("R.id.big_usage_b_bar"))
+ assertTrue(File(main + "app/BarBitmap.kt").readText().contains("row.barTone"))
+ }
+
+ @Test fun thePlanUsageIsOffAndNotConnectedStatesExist() {
+ assertEquals("Plan usage is off", strings["widget_big_usage_off"])
+ assertEquals("Turn it on in the app", strings["widget_big_usage_off_line"])
+ assertEquals("Not connected", strings["widget_big_not_connected"])
+ val root = element(bigLayout)
+ assertTrue("one block for both calm messages", byId(root, "big_off").children().map { it.getAttribute("android:id") } == listOf("@+id/big_off_title", "@+id/big_off_line"))
+ for (st in listOf("UsageSide.ROWS", "UsageSide.OFF", "UsageSide.NOT_CONNECTED")) assertTrue(st, bigSource.contains(st))
+ assertTrue(bigSource.contains("R.string.widget_big_usage_off") && bigSource.contains("R.string.widget_big_usage_off_line") && bigSource.contains("R.string.widget_big_not_connected"))
+ // "Plan usage is off" opens Settings through the whitelist; "Not connected" and the rows open the app.
+ assertTrue(bigSource.contains("WidgetHub.openScreen(context, WidgetHub.CODE_BIG_USAGE_SETTINGS, LaunchScreen.SETTINGS)"))
+ assertTrue(bigSource.contains("WidgetHub.openApp(context, WidgetHub.CODE_BIG_USAGE_APP)"))
+ // The layout starts on the calm message, so an unpainted Widget is never an empty area.
+ assertTrue(byId(root, "big_off").getAttribute("android:visibility").isEmpty())
+ for (k in listOf("a", "b")) assertEquals("gone", byId(root, "big_usage_$k").getAttribute("android:visibility"))
+ }
+
+ @Test fun mochiBigHasTwoArrangementsOfTheSixButtons() {
+ val root = element(bigLayout)
+ val row = byId(root, "big_buttons_m").children().map { it.getAttribute("android:id") }
+ assertEquals("one row of four", listOf("@+id/big_m_home", "@+id/big_m_chat", "@+id/big_m_settings", "@+id/big_m_recent"), row)
+ val grid = byId(root, "big_buttons_l").children()
+ assertEquals("two rows", 2, grid.size)
assertEquals(
listOf(
- "big_tile_home" to "LaunchScreen.HOME", "big_tile_chat" to "LaunchScreen.CHAT", "big_tile_settings" to "LaunchScreen.SETTINGS",
- "big_tile_recent" to "LaunchScreen.RECENT", "big_tile_session" to "null", "big_tile_pair" to "LaunchScreen.PAIR",
+ listOf("@+id/big_l_home", "@+id/big_l_chat", "@+id/big_l_settings"),
+ listOf("@+id/big_l_recent", "@+id/big_l_session", "@+id/big_l_pair"),
),
- tiles,
+ grid.map { r -> r.children().map { it.getAttribute("android:id") } },
)
- // The top agent goes through the session slot; everything else through the screen slot; each tile has its own code.
+ // Every tile: an icon over a 12sp label, on the rounded tile.
+ val tiles = root.descendants().filter { it.getAttribute("android:id").startsWith("@+id/big_m_") || it.getAttribute("android:id").startsWith("@+id/big_l_") }
+ assertEquals(10, tiles.size)
+ for (t in tiles) {
+ assertEquals(t.getAttribute("android:id"), "@drawable/widget_tile_bg", t.getAttribute("android:background"))
+ assertEquals(listOf("ImageView", "TextView"), t.children().map { it.tagName })
+ assertEquals("@dimen/widget_text_secondary", t.children()[1].getAttribute("android:textSize"))
+ }
+ assertEquals(12.0, dimens.getValue("widget_text_secondary"), 0.0)
+ assertEquals("rounded 16dp", 16.0, dimens.getValue("widget_tile_radius"), 0.0)
+ }
+
+ @Test fun eachButtonOpensOneThingAndBothArrangementsAgree() {
+ val src = bigSource
+ assertTrue(src.contains("LaunchScreen.HOME, LaunchScreen.CHAT, LaunchScreen.SETTINGS, LaunchScreen.RECENT, null, LaunchScreen.PAIR"))
+ assertTrue(src.contains("listOf(R.id.big_m_home, R.id.big_m_chat, R.id.big_m_settings, R.id.big_m_recent)"))
+ assertTrue(src.contains("listOf(R.id.big_l_home, R.id.big_l_chat, R.id.big_l_settings, R.id.big_l_recent, R.id.big_l_session, R.id.big_l_pair)"))
+ // The same button has the same code in the row and in the grid; each of the six has its own.
+ assertTrue(src.contains("for (tiles in listOf(ROW_TILES, GRID_TILES))"))
+ assertTrue(src.contains("WidgetHub.CODE_BIG_BUTTON + i"))
+ // The top agent goes through the session slot, everything else through the screen slot.
assertTrue(src.contains("WidgetHub.openSession(context, WidgetHub.CODE_BIG_BUTTON + i, top.pillId)"))
- assertTrue(src.contains("WidgetHub.openScreen(context, WidgetHub.CODE_BIG_BUTTON + i, t.screen)"))
+ assertTrue(src.contains("WidgetHub.openScreen(context, WidgetHub.CODE_BIG_BUTTON + i, screen)"))
assertTrue(src.contains("R.drawable.widget_tile_bg_attention"))
}
@Test fun theBigOnesButtonsGoFromTwoRowsToOneRowToNone() {
- val layout = read(res + "layout/widget_big.xml")
- assertEquals("a row of four then a row of two", 2, Regex("""@\+id/big_buttons_[ab]""").findAll(layout).count())
- assertEquals(4, Regex("""@\+id/big_tile_(home|chat|settings|recent)"""").findAll(layout).count())
- val src = read(main + "app/MochiBigWidget.kt")
+ val src = bigSource
assertTrue(src.contains("R.id.big_buttons, if (small) View.GONE else View.VISIBLE"))
- assertTrue(src.contains("R.id.big_buttons_b, if (large) View.VISIBLE else View.GONE"))
+ assertTrue(src.contains("R.id.big_buttons_m, if (large) View.GONE else View.VISIBLE"))
+ assertTrue(src.contains("R.id.big_buttons_l, if (large) View.VISIBLE else View.GONE"))
+ // Small: Mochi and the first row of usage only.
+ assertTrue(src.contains("rows.getOrNull(1)?.takeIf { !small }"))
}
- @Test fun mochiKeepsAtLeastFortyPercentOfTheBigCardWheneverButtonsShow() {
- val src = read(main + "app/MochiBigWidget.kt")
- val medium = Regex("""MEDIUM_AT = SizeF\(0f, (\d+)f""").find(src)!!.groupValues[1].toDouble()
- val large = Regex("""LARGE_AT = SizeF\(0f, (\d+)f""").find(src)!!.groupValues[1].toDouble()
- val tile = dimens.getValue("widget_tile_height")
- // dp: padding 12 + 12, the bubble in two lines (8 + 2 x 20 + 8 = 56) and its tail 10, the status line 20, then the buttons.
- val fixed = 24 + 56 + 10 + 20
- val rowA = 8 + tile
- val rowB = 6 + tile
- assertTrue("one row from $medium dp: Mochi ${medium - fixed - rowA}", (medium - fixed - rowA) / medium >= 0.40)
- assertTrue("two rows from $large dp: Mochi ${large - fixed - rowA - rowB}", (large - fixed - rowA - rowB) / large >= 0.40)
- // And with no buttons there is more room still.
+ @Test fun mochiKeepsAtLeastFortyPercentOfTheTopAreaWheneverButtonsShow() {
+ val medium = Regex("""MEDIUM_AT = SizeF\(0f, (\d+)f""").find(bigSource)!!.groupValues[1].toDouble()
+ val large = Regex("""LARGE_AT = SizeF\(0f, (\d+)f""").find(bigSource)!!.groupValues[1].toDouble()
val minHeight = Regex("""android:minHeight="(\d+)dp"""").find(read(res + "xml/coucou_big_widget_info.xml"))!!.groupValues[1].toDouble()
- assertTrue((minHeight - fixed) / minHeight >= 0.40)
- assertTrue("the steps are in order", medium < large && minHeight < medium)
+ val tile = dimens.getValue("widget_tile_height")
+ val padding = 24.0
+ // The top area is what the buttons leave; under Mochi sit the name row and the state word (about 20 + 16).
+ val status = 36.0
+ val small = minHeight - padding
+ val withRow = medium - padding - (8 + tile)
+ val withGrid = large - padding - (8 + tile + 6 + tile)
+ for ((what, top) in listOf("small" to small, "one row" to withRow, "two rows" to withGrid)) {
+ assertTrue("$what: the top area is ${top.toInt()}dp", top >= 100)
+ assertTrue("$what: Mochi has ${(top - status).toInt()} of ${top.toInt()}dp", (top - status) / top >= 0.40)
+ }
+ // The two usage rows (label 15, percentage 35, bar 6, gaps) fit beside him at every size where both show.
+ val twoRows = 2 * (15 + 35 + 2 + 6) + 8
+ assertTrue("two usage rows need ${twoRows.toInt()}dp of ${withRow.toInt()}", twoRows <= withRow)
+ assertTrue("the steps are in order", minHeight < medium && medium < large)
}
// ── Nothing here can approve, deny or send ──────────────────────────────────────────────────────
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt
index 8b0e7e7c..e5e4f9d6 100644
--- a/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetPreviewTest.kt
@@ -134,7 +134,11 @@ class WidgetPreviewTest {
assertEquals("Waiting for you", list.first())
assertEquals(listOf("Waiting for you", "1", "Claude Code", "Waiting for your approval", "Codex", "Working", "Gemini CLI", "Finished"), list)
assertEquals(3, Regex("""android:minHeight="@dimen/widget_row_min"""").findAll(preview("list")).count())
- assertTrue(text("big").containsAll(listOf("Claude Code is waiting for you", "Claude Code", "Waiting", "Home", "Chat", "Settings", "Recent", "Top agent", "Pair again")))
+ // Mochi Big: Mochi, the agent and its state on the left; Claude 68% and Codex 41% on the right; the six tiles.
+ assertEquals(
+ listOf("Claude Code", "Working", "Claude · 5 h", "68%", "Codex · week", "41%", "Home", "Chat", "Settings", "Recent", "Top agent", "Pair again"),
+ text("big"),
+ )
assertEquals(listOf("2 agents working", "Claude Code", "Working", "Codex", "Thinking", "Gemini CLI", "Idle"), text("glance"))
assertEquals(listOf("Claude", "Working"), text("pill"))
// The pill shows its four buttons: home, chat, settings and recent, in that order.
@@ -147,7 +151,10 @@ class WidgetPreviewTest {
assertTrue(preview("solo").contains("widget_tone_attention") && preview("solo").contains("preview_mochi_waiting"))
assertTrue(preview("pill").contains("widget_tone_working"))
assertTrue(preview("alert").contains("widget_card_attention"))
- assertTrue(preview("big").contains("preview_mochi_waiting") && preview("big").contains("widget_tile_bg_attention"))
+ assertTrue(preview("big").contains("preview_mochi_working") && preview("big").contains("widget_tint_working"))
+ assertEquals("six tiles", 6, Regex("""@drawable/widget_tile_bg"""").findAll(preview("big")).count())
+ assertEquals("two thin bars", 2, Regex("""@drawable/preview_bar_done"""").findAll(preview("big")).count())
+ assertFalse("no speech bubble", preview("big").contains("bubble", ignoreCase = true))
assertTrue(preview("glance").contains("preview_mochi_working") && preview("glance").contains("widget_tint_working"))
assertTrue(preview("mood").contains("preview_mochi_done") && preview("today").contains("preview_mochi_done"))
assertTrue(preview("list").let { it.contains("preview_face_waiting") && it.contains("preview_face_working") && it.contains("preview_face_done") })
@@ -272,4 +279,14 @@ class WidgetPreviewTest {
assertTrue("$name line needs ${line.toInt()}dp of $room", line <= room)
}
}
+
+ @Test fun theMochiBigPreviewFitsItsTwoSidesAtTheWidthOfA4x4() {
+ // A 4x4 about 300dp wide: padding 12 + 12, so 276; Mochi's side is 45% of it, the usage side 55% less its 8dp margin.
+ val left = 0.45 * (300 - 24)
+ val right = 0.55 * (300 - 24) - 8
+ val name = 10 + 6 + width(sample("widget_sample_claude"), 16.0, true)
+ assertTrue("dot and name need ${name.toInt()}dp of ${left.toInt()}", name <= left)
+ for (k in listOf("widget_sample_ring_label", "widget_sample_codex_week")) assertTrue(k, width(sample(k), 12.0, false) <= right)
+ for (k in listOf("widget_sample_pct_a", "widget_sample_pct_b")) assertTrue(k, width(sample(k), 28.0, true) <= right)
+ }
}
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt
index 2f0b23aa..c1d80274 100644
--- a/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetSurfacesTest.kt
@@ -22,7 +22,7 @@ class WidgetSurfacesTest {
)
private val sources = (
widgets.map { "app/${it.first}.kt" } +
- listOf("app/WidgetHub.kt", "app/MochiBitmap.kt", "app/RingBitmap.kt", "app/TodayStore.kt", "core/WidgetData.kt", "core/TodayCounter.kt", "core/LaunchScreen.kt")
+ listOf("app/WidgetHub.kt", "app/MochiBitmap.kt", "app/RingBitmap.kt", "app/BarBitmap.kt", "app/TodayStore.kt", "core/WidgetData.kt", "core/TodayCounter.kt", "core/LaunchScreen.kt")
).associateWith { read(main + it) }
@Test fun theWidgetsAreRegisteredAndNeverWakeOnATimer() {
@@ -73,7 +73,7 @@ class WidgetSurfacesTest {
@Test fun everyRowAndEveryWidgetHasItsOwnRequestCode() {
val hub = sources.getValue("app/WidgetHub.kt")
val codes = Regex("""const val CODE_\w+ = (0x[0-9A-Fa-f]+)""").findAll(hub).map { it.groupValues[1] }.toList()
- assertEquals(12, codes.size)
+ assertEquals(14, codes.size)
assertEquals(codes.size, codes.toSet().size)
// The rows use CODE_LIST_ROW + index: the ranges must not run into the next code.
val values = codes.map { it.removePrefix("0x").toInt(16) }.sorted()
diff --git a/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt b/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt
new file mode 100644
index 00000000..99c1d5bd
--- /dev/null
+++ b/android/app/src/test/kotlin/com/coucou/android/WidgetUsageSideTest.kt
@@ -0,0 +1,134 @@
+package com.coucou.android
+
+import com.coucou.android.core.Glance
+import com.coucou.android.core.GlanceBuilder
+import com.coucou.android.core.UsageRing
+import com.coucou.android.core.UsageSide
+import com.coucou.android.core.WidgetData
+import com.coucou.android.core.WidgetSample
+import com.coucou.android.core.WidgetTone
+import com.coucou.android.link.LinkState
+import com.coucou.android.link.PlanUsage
+import com.coucou.android.link.PlanWindow
+import com.coucou.android.link.UsageSnapshot
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+/** The plan-usage side of Mochi Big, in pure Kotlin: which rows, which colour, and which of the three things it shows. */
+class WidgetUsageSideTest {
+ private val now = 1_000_000L
+ private val later = now + 3_600_000
+ private fun five(p: Int, reset: Long = later) = PlanWindow(p, reset)
+
+ private fun glance(link: LinkState = LinkState.CONNECTED): Glance = GlanceBuilder.build(true, link, "PC", emptyList(), 0) { "x" }
+ private fun build(u: UsageSnapshot?, link: LinkState = LinkState.CONNECTED) = WidgetData.build(glance(link), emptyList(), { "x" }, u, today = 0, nowMs = now)
+
+ // ── The colour: green, then orange above 75%, then red above 90% ────────────────────────────────
+
+ @Test fun theThresholdsAre75And90() {
+ assertEquals(75, WidgetData.BAR_ORANGE_ABOVE)
+ assertEquals(90, WidgetData.BAR_RED_ABOVE)
+ }
+
+ @Test fun greenUpToSeventyFiveThenOrangeThenRed() {
+ for (p in listOf(-5, 0, 1, 50, 74, 75)) assertEquals("$p%", WidgetTone.DONE, WidgetData.barTone(p))
+ for (p in listOf(76, 80, 89, 90)) assertEquals("$p%", WidgetTone.ATTENTION, WidgetData.barTone(p))
+ for (p in listOf(91, 95, 100, 140)) assertEquals("$p%", WidgetTone.TROUBLE, WidgetData.barTone(p))
+ }
+
+ @Test fun theBarOfARowUsesIt() {
+ assertEquals(WidgetTone.DONE, UsageRing("Claude", "5 h", 75).barTone)
+ assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 76).barTone)
+ assertEquals(WidgetTone.TROUBLE, UsageRing("Codex", "week", 91).barTone)
+ // The Usage Ring widget keeps its own rule (Home's 50% and 80%); only Mochi Big's bar changes.
+ assertEquals(WidgetTone.ATTENTION, UsageRing("Claude", "5 h", 60).tone)
+ assertEquals(WidgetTone.DONE, UsageRing("Claude", "5 h", 60).barTone)
+ }
+
+ // ── The rows ────────────────────────────────────────────────────────────────────────────────────
+
+ @Test fun claudeThenCodexEachWithItsMainWindow() {
+ val u = UsageSnapshot(PlanUsage(five(68), PlanWindow(10, later)), PlanUsage(null, PlanWindow(41, later)))
+ assertEquals(listOf(UsageRing("Claude", "5 h", 68), UsageRing("Codex", "week", 41)), WidgetData.usageRows(u, now))
+ assertEquals("Claude · 5 h", WidgetData.usageRows(u, now)[0].label)
+ assertEquals("Codex · week", WidgetData.usageRows(u, now)[1].label)
+ }
+
+ @Test fun eachPlanUsesItsFiveHoursBeforeItsWeek() {
+ val u = UsageSnapshot(PlanUsage(null, PlanWindow(30, later)), PlanUsage(five(55), PlanWindow(70, later)))
+ assertEquals(listOf(UsageRing("Claude", "week", 30), UsageRing("Codex", "5 h", 55)), WidgetData.usageRows(u, now))
+ }
+
+ @Test fun onePlanOneRow() {
+ assertEquals(listOf(UsageRing("Claude", "5 h", 20)), WidgetData.usageRows(UsageSnapshot(PlanUsage(five(20), null), null), now))
+ assertEquals(listOf(UsageRing("Codex", "5 h", 20)), WidgetData.usageRows(UsageSnapshot(null, PlanUsage(five(20), null)), now))
+ }
+
+ @Test fun neverMoreThanTwoRows() {
+ val u = UsageSnapshot(PlanUsage(five(1), PlanWindow(2, later)), PlanUsage(five(3), PlanWindow(4, later)))
+ assertEquals(2, WidgetData.usageRows(u, now).size)
+ }
+
+ @Test fun nothingSentMeansNoRow() {
+ assertTrue(WidgetData.usageRows(null, now).isEmpty())
+ assertTrue(WidgetData.usageRows(UsageSnapshot(null, null), now).isEmpty())
+ assertTrue(WidgetData.usageRows(UsageSnapshot(PlanUsage(null, null), PlanUsage(null, null)), now).isEmpty())
+ }
+
+ @Test fun aWindowThatHasResetCountsAsZero() {
+ val u = UsageSnapshot(PlanUsage(five(80, reset = now - 1), null), null)
+ assertEquals(0, WidgetData.usageRows(u, now).single().pct)
+ }
+
+ // ── The three things the right side shows ───────────────────────────────────────────────────────
+
+ @Test fun notConnectedBeatsEverything() {
+ val u = UsageSnapshot(PlanUsage(five(50), null), null)
+ val c = build(u, LinkState.DISCONNECTED)
+ assertEquals(UsageSide.NOT_CONNECTED, c.usageSide)
+ assertTrue("nothing stale is shown", c.usageRows.isEmpty())
+ assertEquals(UsageSide.NOT_CONNECTED, build(null, LinkState.CONNECTING).usageSide)
+ }
+
+ @Test fun connectedWithNoUsageSaysItIsOff() {
+ assertEquals(UsageSide.OFF, build(null).usageSide)
+ assertEquals(UsageSide.OFF, build(UsageSnapshot(null, null)).usageSide)
+ assertEquals(UsageSide.OFF, build(UsageSnapshot(PlanUsage(null, null), null)).usageSide)
+ }
+
+ @Test fun connectedWithUsageShowsTheRows() {
+ val c = build(UsageSnapshot(PlanUsage(five(68), null), PlanUsage(null, PlanWindow(41, later))))
+ assertEquals(UsageSide.ROWS, c.usageSide)
+ assertEquals(listOf(68, 41), c.usageRows.map { it.pct })
+ }
+
+ @Test fun everyStateHasASide() {
+ // Whatever the content, the right side is one of the three: never nothing.
+ for (link in LinkState.values()) for (u in listOf(null, UsageSnapshot(null, null), UsageSnapshot(PlanUsage(five(10), null), null))) {
+ assertTrue(build(u, link).usageSide in UsageSide.values())
+ }
+ }
+
+ @Test fun aChangeOfPercentageIsAChangeOfContent() {
+ val a = build(UsageSnapshot(PlanUsage(five(68), null), null))
+ assertFalse(a == build(UsageSnapshot(PlanUsage(five(69), null), null)))
+ assertEquals(a, build(UsageSnapshot(PlanUsage(five(68), null), null)))
+ }
+
+ // ── The samples ─────────────────────────────────────────────────────────────────────────────────
+
+ @Test fun theSamplesShowEachSide() {
+ val working = WidgetData.sample(WidgetSample.WORKING, now)
+ assertEquals(UsageSide.ROWS, working.usageSide)
+ assertEquals(listOf("Claude · 5 h" to 42, "Codex · week" to 41), working.usageRows.map { it.label to it.pct })
+ assertEquals(listOf(WidgetTone.DONE, WidgetTone.DONE), working.usageRows.map { it.barTone })
+ val waiting = WidgetData.sample(WidgetSample.WAITING, now)
+ assertEquals(listOf(WidgetTone.ATTENTION, WidgetTone.TROUBLE), waiting.usageRows.map { it.barTone })
+ assertEquals(UsageSide.ROWS, WidgetData.sample(WidgetSample.DONE, now).usageSide)
+ assertEquals(1, WidgetData.sample(WidgetSample.DONE, now).usageRows.size)
+ assertEquals(UsageSide.OFF, WidgetData.sample(WidgetSample.EMPTY, now).usageSide)
+ assertEquals(UsageSide.NOT_CONNECTED, WidgetData.sample(WidgetSample.DISCONNECTED, now).usageSide)
+ }
+}