summaryrefslogtreecommitdiff
path: root/android/app/src/test/java/org/terst/doot
diff options
context:
space:
mode:
Diffstat (limited to 'android/app/src/test/java/org/terst/doot')
-rw-r--r--android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt62
1 files changed, 62 insertions, 0 deletions
diff --git a/android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt b/android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt
index e3d76b1..550c533 100644
--- a/android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt
+++ b/android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt
@@ -1,10 +1,13 @@
package org.terst.doot.widget.ui
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.After
import org.junit.Test
import org.terst.doot.widget.data.WidgetItem
+import java.time.Instant
import java.util.TimeZone
class DootWidgetGridTest {
@@ -47,4 +50,63 @@ class DootWidgetGridTest {
val gridEnd = calcGridEnd(emptyList(), nowHour = 22)
assertEquals(23, gridEnd)
}
+
+ // isPastEvent: 2026-08-05 change pulling already-ended events out of the grid to
+ // stack above it as list rows, same treatment past tasks already got.
+
+ private fun event(endIso: String?) = WidgetItem(
+ id = "e", title = "Event", source = "calendar", type = "event",
+ start = "2026-07-12T09:00:00Z", end = endIso
+ )
+
+ private fun task(startIso: String) = WidgetItem(
+ id = "t", title = "Task", source = "doot", type = "task", start = startIso
+ )
+
+ @Test
+ fun `isPastEvent is true once end has passed`() {
+ val now = Instant.parse("2026-07-12T10:00:00Z")
+ assertTrue(isPastEvent(event(endIso = "2026-07-12T09:30:00Z"), now))
+ }
+
+ @Test
+ fun `isPastEvent is false while still ongoing`() {
+ val now = Instant.parse("2026-07-12T10:00:00Z")
+ assertFalse(isPastEvent(event(endIso = "2026-07-12T10:30:00Z"), now))
+ }
+
+ @Test
+ fun `isPastEvent is false with no end time -- never considered past`() {
+ val now = Instant.parse("2026-07-12T23:00:00Z")
+ assertFalse(isPastEvent(event(endIso = null), now))
+ }
+
+ @Test
+ fun `isPastEvent is always false for tasks -- SlotPacker already handles those`() {
+ val now = Instant.parse("2026-07-12T10:00:00Z")
+ assertFalse(isPastEvent(task(startIso = "2026-07-12T08:00:00Z"), now))
+ }
+
+ // moonPhaseEmoji: values verified against direct computation before writing these
+ // assertions (days-since-anchor / synodic-month arithmetic), not hand-computed.
+
+ @Test
+ fun `moonPhaseEmoji on the reference new moon date is new moon`() {
+ assertEquals("🌑", moonPhaseEmoji(java.time.LocalDate.of(2000, 1, 6)))
+ }
+
+ @Test
+ fun `moonPhaseEmoji about half a synodic month later is full moon`() {
+ assertEquals("🌕", moonPhaseEmoji(java.time.LocalDate.of(2000, 1, 21)))
+ }
+
+ @Test
+ fun `moonPhaseEmoji never indexes out of bounds across a full cycle`() {
+ val anchor = java.time.LocalDate.of(2000, 1, 6)
+ for (offset in 0..365) {
+ // Must not throw for any date in a full year -- the real assertion here is
+ // "doesn't crash," the emoji values themselves are checked in the two tests above.
+ moonPhaseEmoji(anchor.plusDays(offset.toLong()))
+ }
+ }
}