From 6fc04aa3162d3d0eb9b869574ddadc032d6d3754 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 13 Jul 2026 09:47:41 +0000 Subject: fix(widget): stop tomorrow's events from stretching today's grid bounds calcGridStart/calcGridEnd only looked at hour-of-day, so a tomorrow event's early or late hour could inflate today's grid range with empty rows, pushing the non-scrolling TomorrowSection below the widget's visible area. Filter to today-only events before computing bounds. --- .../org/terst/doot/widget/ui/DootWidgetGridTest.kt | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt (limited to 'android/app/src/test/java/org/terst') 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 new file mode 100644 index 0000000..b3d8384 --- /dev/null +++ b/android/app/src/test/java/org/terst/doot/widget/ui/DootWidgetGridTest.kt @@ -0,0 +1,34 @@ +package org.terst.doot.widget.ui + +import org.junit.Assert.assertEquals +import org.junit.Test +import org.terst.doot.widget.data.WidgetItem + +class DootWidgetGridTest { + + private fun tomorrowEvent(startIso: String, endIso: String): WidgetItem = WidgetItem( + id = "tmrw", title = "Tomorrow Event", source = "calendar", type = "event", + start = startIso, end = endIso + ) + + @Test + fun `calcGridStart on an unfiltered mixed list is skewed by tomorrow's event hour`() { + // Documents why WidgetRoot MUST pre-filter to today-only events before calling + // this function: it has no date awareness, only hour-of-day. "now" is 22:00 + // today (2026-07-12); the only item is tomorrow's (2026-07-13) 10:00 event. + val mixedList = listOf(tomorrowEvent("2026-07-13T10:00:00Z", "2026-07-13T14:30:00Z")) + assertEquals(9, calcGridStart(mixedList, nowHour = 22)) + } + + @Test + fun `calcGridStart on the correctly today-filtered (empty) list falls back to nowHour`() { + val gridStart = calcGridStart(emptyList(), nowHour = 22) + assertEquals(21, gridStart) + } + + @Test + fun `calcGridEnd falls back to nowHour plus eight when no today events, capped at 23`() { + val gridEnd = calcGridEnd(emptyList(), nowHour = 22) + assertEquals(23, gridEnd) + } +} -- cgit v1.2.3