Show elapsed-time cursor on usage bars
This commit is contained in:
1 parent
84f978f16d
commit
cd0229bed6
3 files changed
+116
-30
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.example.aiapp
|
||||
|
||||
import java.time.OffsetDateTime
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -61,6 +62,52 @@ class SessionUsageTest {
|
||||
assertEquals(null, shortestUsageWindow(listOf(window("unknown", null))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the time cursor follows elapsed time through the window`() {
|
||||
val now = OffsetDateTime.parse("2026-09-17T12:00:00Z")
|
||||
|
||||
assertEquals(
|
||||
0.4f,
|
||||
usageWindowElapsedFraction(
|
||||
window("5-hour window", 300, "2026-09-17T15:00:00Z"),
|
||||
now,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the time cursor clamps at the window ends`() {
|
||||
val now = OffsetDateTime.parse("2026-09-17T12:00:00Z")
|
||||
|
||||
assertEquals(
|
||||
0f,
|
||||
usageWindowElapsedFraction(
|
||||
window("5-hour window", 300, "2026-09-17T18:00:00Z"),
|
||||
now,
|
||||
),
|
||||
)
|
||||
assertEquals(
|
||||
1f,
|
||||
usageWindowElapsedFraction(
|
||||
window("5-hour window", 300, "2026-09-17T11:00:00Z"),
|
||||
now,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the time cursor is absent without a usable duration and reset time`() {
|
||||
val now = OffsetDateTime.parse("2026-09-17T12:00:00Z")
|
||||
|
||||
assertEquals(null, usageWindowElapsedFraction(window("unknown", null), now))
|
||||
assertEquals(null, usageWindowElapsedFraction(window("not running", 300), now))
|
||||
assertEquals(
|
||||
null,
|
||||
usageWindowElapsedFraction(window("unreadable", 300, "not a timestamp"), now),
|
||||
)
|
||||
assertEquals(null, usageWindowElapsedFraction(window("zero", 0), now))
|
||||
}
|
||||
|
||||
private fun snapshot(
|
||||
machine: String,
|
||||
provider: String,
|
||||
@@ -78,13 +125,13 @@ class SessionUsageTest {
|
||||
windows = emptyList(),
|
||||
)
|
||||
|
||||
private fun window(label: String, durationMinutes: Long?) =
|
||||
private fun window(label: String, durationMinutes: Long?, resetsAt: String? = null) =
|
||||
UsageWindow(
|
||||
kind = "test",
|
||||
label = label,
|
||||
percent = 12.0,
|
||||
durationMinutes = durationMinutes,
|
||||
resetsAt = null,
|
||||
resetsAt = resetsAt,
|
||||
active = false,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user