Release v2.22.0 (#355)
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 8s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Successful in 14m16s
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Failing after 1m26s

Views: navigation, transitions and split-view behaviour.

See CHANGELOG.md for the full list.

Co-authored-by: Jean-Luc Makiola <business@jeanlucmakiola.de>
Reviewed-on: https://codeberg.org/jlmakiola/calendula/pulls/355
This commit is contained in:
Jean-Luc Makiolaandmakiolaj committed 2026-10-01 16:21:11 +02:00
1 parent bfc05795f0
commit 5f07adef2f
228 files changed
+6158 -3055

No files matched your search

@@ -1075,16 +1075,29 @@ class EventWriteMapperTest {
}
@Test
fun `occurrence exception carries the palette key`() {
fun `occurrence exception leaves the palette key out`() {
// The provider crashes on an exception insert carrying a colour key
// (Codeberg #338); the data source sets it with an update afterwards.
val values = buildOccurrenceExceptionValues(
form = form().copy(colorKey = "2", color = 0xFFE67C00.toInt()),
originalInstanceMillis = 0L,
zone = berlin,
)
assertThat(values).containsEntry(CalendarContract.Events.EVENT_COLOR_KEY, "2")
assertThat(values).doesNotContainKey(CalendarContract.Events.EVENT_COLOR_KEY)
assertThat(values).doesNotContainKey(CalendarContract.Events.EVENT_COLOR)
}
@Test
fun `occurrence exception with a custom colour writes it directly`() {
val values = buildOccurrenceExceptionValues(
form = form().copy(color = 0xFFE67C00.toInt()),
originalInstanceMillis = 0L,
zone = berlin,
)
assertThat(values).containsEntry(CalendarContract.Events.EVENT_COLOR, 0xFFE67C00.toInt())
assertThat(values).containsEntry(CalendarContract.Events.EVENT_COLOR_KEY, null)
}
@Test
fun `occurrence exception with no colour clears both columns`() {
val values = buildOccurrenceExceptionValues(
@@ -14,6 +14,7 @@ import de.jeanlucmakiola.calendula.ui.agenda.AgendaRange
import de.jeanlucmakiola.calendula.ui.common.CalendarView
import de.jeanlucmakiola.calendula.ui.common.IMPLEMENTED_VIEWS
import de.jeanlucmakiola.calendula.ui.common.QuickSwitchConfig
import de.jeanlucmakiola.calendula.ui.common.TimelineHours
import de.jeanlucmakiola.calendula.ui.common.TimelineScale
import de.jeanlucmakiola.calendula.ui.month.MonthViewStyle
import kotlinx.coroutines.flow.first
@@ -125,6 +126,24 @@ class SettingsPrefsTest {
assertThat(prefs.timelineScale.first()).isEqualTo(TimelineScale.Comfortable)
}
@Test
fun `visible hours default off and round-trip`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(newDataStore(tempDir))
assertThat(prefs.timelineHours.first()).isEqualTo(TimelineHours(enabled = false, 7, 22))
prefs.setTimelineHours(TimelineHours(enabled = true, 6, 20))
assertThat(prefs.timelineHours.first()).isEqualTo(TimelineHours(enabled = true, 6, 20))
// Switching off keeps the chosen hours for next time.
prefs.setTimelineHours(TimelineHours(enabled = false, 6, 20))
assertThat(prefs.timelineHours.first()).isEqualTo(TimelineHours(enabled = false, 6, 20))
}
@Test
fun `visible hours are stored valid`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(newDataStore(tempDir))
prefs.setTimelineHours(TimelineHours(enabled = true, 23, 22))
assertThat(prefs.timelineHours.first()).isEqualTo(TimelineHours(enabled = true, 20, 22))
}
@Test
fun `week numbers default off and round-trips`(@TempDir tempDir: Path) = runTest {
val prefs = SettingsPrefs(newDataStore(tempDir))
@@ -235,7 +254,8 @@ class SettingsPrefsTest {
prefs.setQuickSwitchConfig(config)
val loaded = prefs.quickSwitchConfig.first()
assertThat(loaded.order).containsExactly(
CalendarView.Agenda, CalendarView.Month, CalendarView.Week, CalendarView.Day,
CalendarView.Agenda, CalendarView.Month, CalendarView.Week,
CalendarView.MultiDay, CalendarView.Day,
).inOrder()
assertThat(loaded.enabled).containsExactly(CalendarView.Agenda, CalendarView.Month)
assertThat(loaded.cycle).containsExactly(CalendarView.Agenda, CalendarView.Month).inOrder()
@@ -252,13 +272,14 @@ class SettingsPrefsTest {
m
}
val config = prefs.quickSwitchConfig.first()
// Stored order first (Day, Week), then the omitted views in default order.
// Stored order first, with the new view after Week.
assertThat(config.order).containsExactly(
CalendarView.Day, CalendarView.Week, CalendarView.Month, CalendarView.Agenda,
CalendarView.Day, CalendarView.Week, CalendarView.MultiDay,
CalendarView.Month, CalendarView.Agenda,
).inOrder()
// Day was explicitly disabled; the appended Month & Agenda default enabled.
// Day was explicitly disabled; the missing views default enabled.
assertThat(config.enabled).containsExactly(
CalendarView.Week, CalendarView.Month, CalendarView.Agenda,
CalendarView.Week, CalendarView.MultiDay, CalendarView.Month, CalendarView.Agenda,
)
}
@@ -272,9 +293,12 @@ class SettingsPrefsTest {
val newOrder = listOf(CalendarView.Agenda, CalendarView.Month, CalendarView.Week, CalendarView.Day)
prefs.updateQuickSwitch { it.copy(order = newOrder) }
val config = prefs.quickSwitchConfig.first()
assertThat(config.order).containsExactlyElementsIn(newOrder).inOrder()
assertThat(config.enabled).containsExactly(
assertThat(config.order).containsExactly(
CalendarView.Agenda, CalendarView.Month, CalendarView.Week,
CalendarView.MultiDay, CalendarView.Day,
).inOrder()
assertThat(config.enabled).containsExactly(
CalendarView.Agenda, CalendarView.Month, CalendarView.Week, CalendarView.MultiDay,
)
}
@@ -286,7 +310,8 @@ class SettingsPrefsTest {
listOf(CalendarView.Agenda, CalendarView.Day, CalendarView.Week, CalendarView.Month),
)
assertThat(prefs.drawerViewOrder.first()).containsExactly(
CalendarView.Agenda, CalendarView.Day, CalendarView.Week, CalendarView.Month,
CalendarView.Agenda, CalendarView.Day, CalendarView.Week,
CalendarView.MultiDay, CalendarView.Month,
).inOrder()
}
@@ -300,7 +325,8 @@ class SettingsPrefsTest {
m
}
assertThat(prefs.drawerViewOrder.first()).containsExactly(
CalendarView.Agenda, CalendarView.Week, CalendarView.Month, CalendarView.Day,
CalendarView.Agenda, CalendarView.Week, CalendarView.MultiDay,
CalendarView.Month, CalendarView.Day,
).inOrder()
}
@@ -38,6 +38,7 @@ class ReminderTimeTextTest {
is24Hour = is24Hour,
today = today ?: java.time.Instant.ofEpochMilli(beginMillis).atZone(zone).toLocalDate(),
firstDayOfWeek = firstDayOfWeek,
todayLabel = "Today",
tomorrowLabel = "Tomorrow",
yesterdayLabel = "Yesterday",
)
@@ -130,38 +131,74 @@ class ReminderTimeTextTest {
}
@Test
fun `all-day single day shows one date, read in UTC`() {
fun `all-day single day today reads as today, read in UTC`() {
val text = text(
beginMillis = utcMidnight(LocalDate.of(2026, 6, 11)),
endMillis = utcMidnight(LocalDate.of(2026, 6, 12)),
isAllDay = true,
// Zone must not matter for all-day events: UTC midnight is
// 02:00 in Berlin — naive local reading would shift the day.
// the previous evening in Los Angeles — naive local reading would shift the day.
zone = ZoneId.of("America/Los_Angeles"),
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("11.06.2026")
assertThat(text).isEqualTo("Today")
}
@Test
fun `all-day event tomorrow still shows the exact date, no relative prefix`() {
fun `all-day event tomorrow reads as tomorrow`() {
val text = text(
beginMillis = utcMidnight(LocalDate.of(2026, 6, 12)),
endMillis = utcMidnight(LocalDate.of(2026, 6, 13)),
isAllDay = true,
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("12.06.2026")
assertThat(text).isEqualTo("Tomorrow")
}
@Test
fun `all-day multi-day shows the last covered day, not the exclusive end`() {
fun `all-day event later this week reads as the short weekday`() {
// 2026-06-11 is a Thursday; Saturday the 13th shares its week.
val text = text(
beginMillis = utcMidnight(LocalDate.of(2026, 6, 11)),
endMillis = utcMidnight(LocalDate.of(2026, 6, 13)),
beginMillis = utcMidnight(LocalDate.of(2026, 6, 13)),
endMillis = utcMidnight(LocalDate.of(2026, 6, 14)),
isAllDay = true,
locale = Locale.US,
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("Sat")
}
@Test
fun `all-day event next week falls back to the exact date`() {
val text = text(
beginMillis = utcMidnight(LocalDate.of(2026, 6, 16)),
endMillis = utcMidnight(LocalDate.of(2026, 6, 17)),
isAllDay = true,
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("11.06.2026 – 12.06.2026")
assertThat(text).isEqualTo("16.06.2026")
}
@Test
fun `all-day multi-day reads relative start and the last covered day`() {
val text = text(
beginMillis = utcMidnight(LocalDate.of(2026, 6, 12)),
endMillis = utcMidnight(LocalDate.of(2026, 6, 14)),
isAllDay = true,
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("Tomorrow – 13.06.2026")
}
@Test
fun `all-day multi-day further out keeps both dates`() {
val text = text(
beginMillis = utcMidnight(LocalDate.of(2026, 7, 1)),
endMillis = utcMidnight(LocalDate.of(2026, 7, 3)),
isAllDay = true,
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("01.07.2026 – 02.07.2026")
}
@Test
@@ -173,6 +210,6 @@ class ReminderTimeTextTest {
isAllDay = true,
today = LocalDate.of(2026, 6, 11),
)
assertThat(text).isEqualTo("11.06.2026")
assertThat(text).isEqualTo("Today")
}
}
@@ -156,4 +156,5 @@ class EventToneTest {
assertThat(eventTone(0xFFFFF6C0.toInt(), dark = false, harmonise = false).onContainer)
.isEqualTo(0xFF000000.toInt())
}
}
@@ -0,0 +1,40 @@
package de.jeanlucmakiola.calendula.ui.agenda
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.calendula.domain.EventInstance
import kotlinx.datetime.LocalDate
import kotlin.time.Instant
import org.junit.jupiter.api.Test
/** The day each agenda list item belongs to, for the focus it hands back (#184). */
class AgendaItemDatesTest {
private val monday = LocalDate(2026, 9, 28)
private val tuesday = LocalDate(2026, 9, 29)
private fun event(id: Long) = EventInstance(
instanceId = id,
eventId = id,
calendarId = 1L,
title = "Event",
start = Instant.fromEpochMilliseconds(0),
end = Instant.fromEpochMilliseconds(0),
isAllDay = false,
color = 0xFF000000.toInt(),
location = null,
)
@Test
fun `each day counts its header, events and gap`() {
val days = listOf(AgendaDay(monday, listOf(event(1), event(2))), AgendaDay(tuesday, listOf(event(3))))
assertThat(agendaItemDates(days)).containsExactly(
monday, monday, monday, monday,
tuesday, tuesday, tuesday,
).inOrder()
}
@Test
fun `an empty day counts its placeholder`() {
assertThat(agendaItemDates(listOf(AgendaDay(monday, emptyList())))).hasSize(3)
}
}
@@ -77,6 +77,16 @@ class GroupAgendaDaysTest {
.containsExactly(LocalDate(2026, 7, 2))
}
@Test
fun `multi-day events precede single all-day and timed events`() {
val multi = event(1, "Multi", at(2026, 7, 1), at(2026, 7, 4), isAllDay = true)
val single = event(2, "Single", at(2026, 7, 2), at(2026, 7, 3), isAllDay = true)
val timed = event(3, "Timed", at(2026, 7, 2, 8), at(2026, 7, 2, 9))
val second = days(listOf(timed, single, multi)).first { it.date == LocalDate(2026, 7, 2) }
assertThat(second.events.map { it.title })
.containsExactly("Multi", "Single", "Timed").inOrder()
}
@Test
fun `an event ending exactly at midnight does not reach the next day`() {
val e = event(1, "late", at(2026, 7, 1, 22, 0), at(2026, 7, 2, 0, 0))
@@ -0,0 +1,48 @@
package de.jeanlucmakiola.calendula.ui.common
import androidx.compose.ui.unit.dp
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
class BlockTimeRangeTest {
/** Fits whatever is at most [chars] characters wide. */
private fun upTo(chars: Int): (String) -> Boolean = { it.length <= chars }
@Test
fun `a range that fits stays on one line`() {
assertThat(blockTimeRange("6:00 PM", "7:00 PM", upTo(20)))
.isEqualTo("6:00\u00A0PM–7:00\u00A0PM")
}
@Test
fun `a narrow column hangs the dash off the start time`() {
assertThat(blockTimeRange("6:00 PM", "7:00 PM", upTo(8)))
.isEqualTo("6:00\u00A0PM–\n7:00\u00A0PM")
}
@Test
fun `the dash leads the end time when only that side has room`() {
assertThat(blockTimeRange("10:00 PM", "7:00 PM", upTo(8)))
.isEqualTo("10:00\u00A0PM\n–7:00\u00A0PM")
}
@Test
fun `with room for neither dash the times just stack`() {
assertThat(blockTimeRange("6:00 PM", "7:00 PM", upTo(7)))
.isEqualTo("6:00\u00A0PM\n7:00\u00A0PM")
}
@Test
fun `a time too wide for the column keeps its space to wrap at`() {
assertThat(blockTimeRange("6:00 PM", "7:00 PM", upTo(5)))
.isEqualTo("6:00 PM–\u200B7:00 PM")
}
@Test
fun `the label takes every whole line the spare height holds`() {
assertThat(timeLinesWithin(spare = 0.dp, timeLine = 13.dp)).isEqualTo(1)
assertThat(timeLinesWithin(spare = 13.dp, timeLine = 13.dp)).isEqualTo(2)
assertThat(timeLinesWithin(spare = 40.dp, timeLine = 13.dp)).isEqualTo(4)
}
}
@@ -0,0 +1,147 @@
package de.jeanlucmakiola.calendula.ui.common
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.calendula.domain.EventInstance
import de.jeanlucmakiola.calendula.ui.week.TimedBlock
import kotlin.time.Instant
import org.junit.jupiter.api.Test
/** Which events a column's edge bars point at, and where a tap scrolls (#188). */
class OutOfViewEdgesTest {
private fun block(id: Long, startMin: Int, endMin: Int) = TimedBlock(
event = EventInstance(
instanceId = id,
eventId = id,
calendarId = 1L,
title = "Event $id",
start = Instant.fromEpochMilliseconds(0),
end = Instant.fromEpochMilliseconds(0),
isAllDay = false,
color = 0xFF112233.toInt(),
location = null,
),
startMin = startMin,
endMin = endMin,
lane = 0,
laneCount = 1,
)
private val early = block(1, 7 * 60, 8 * 60)
private val breakfast = block(2, 8 * 60, 9 * 60)
private val lunch = block(3, 12 * 60, 13 * 60)
private val dinner = block(4, 19 * 60, 20 * 60)
private val late = block(5, 21 * 60, 22 * 60)
// Viewport 10:00–17:00.
private fun outOf(vararg blocks: TimedBlock) =
outOfViewEvents(blocks.toList(), topMin = 600f, bottomMin = 1020f)
@Test
fun `the nearest hidden event on each side is picked`() {
val events = outOf(early, breakfast, lunch, dinner, late)
assertThat(events.above).isEqualTo(breakfast)
assertThat(events.below).isEqualTo(dinner)
}
@Test
fun `an event in view points nowhere`() {
assertThat(outOf(lunch)).isEqualTo(OutOfViewEvents.None)
}
@Test
fun `an event cut by the edge is not out of view`() {
val straddling = block(6, 9 * 60, 11 * 60)
assertThat(outOf(straddling).above).isNull()
}
@Test
fun `an event disappears from the edge as soon as a sliver enters view`() {
val sliver = block(6, 9 * 60, 10 * 60 + 5)
assertThat(outOf(sliver).above).isNull()
val tip = block(7, 17 * 60 - 5, 18 * 60)
assertThat(outOf(tip).below).isNull()
val justAbove = block(8, 9 * 60, 10 * 60)
val justBelow = block(9, 17 * 60, 18 * 60)
assertThat(outOf(justAbove).above).isEqualTo(justAbove)
assertThat(outOf(justBelow).below).isEqualTo(justBelow)
}
@Test
fun `the bar fades before its event reaches the viewport`() {
assertThat(edgeBarAlpha(gapPx = 24f, fadeLeadPx = 24f)).isEqualTo(1f)
assertThat(edgeBarAlpha(gapPx = 12f, fadeLeadPx = 24f)).isEqualTo(0.5f)
assertThat(edgeBarAlpha(gapPx = 0f, fadeLeadPx = 24f)).isEqualTo(0f)
assertThat(edgeBarAlpha(gapPx = -1f, fadeLeadPx = 24f)).isEqualTo(0f)
}
@Test
fun `a column scrolled to its top points at nothing above it`() {
val first = block(6, 0, 30)
val events = outOfViewEvents(listOf(first), topMin = 0f, bottomMin = 420f)
assertThat(events.above).isNull()
}
@Test
fun `a short event is judged by the height it renders at`() {
// Five minutes ending at 09:58 still draws 26 minutes tall, past 10:00.
val blip = block(6, 9 * 60 + 53, 9 * 60 + 58)
assertThat(outOf(blip).above).isNull()
}
@Test
fun `an event above scrolls to its start less the margin`() {
val target = revealScrollTarget(breakfast, ViewportEdge.Top, hourPx = 100f, viewportPx = 700, marginPx = 20f, maxScroll = 1700)
assertThat(target).isEqualTo(780)
}
@Test
fun `an event below that fits lands whole at the bottom`() {
val target = revealScrollTarget(dinner, ViewportEdge.Bottom, hourPx = 100f, viewportPx = 700, marginPx = 20f, maxScroll = 1700)
// Its end, 2000, plus the margin, sits at the viewport's bottom.
assertThat(target).isEqualTo(1320)
}
@Test
fun `an event below taller than the viewport lands with its start at the top`() {
val long = block(6, 12 * 60, 22 * 60)
val target = revealScrollTarget(long, ViewportEdge.Bottom, hourPx = 100f, viewportPx = 700, marginPx = 20f, maxScroll = 1700)
assertThat(target).isEqualTo(1180)
}
@Test
fun `the target stays within the scroll range`() {
val first = block(6, 0, 30)
assertThat(
revealScrollTarget(first, ViewportEdge.Top, hourPx = 100f, viewportPx = 700, marginPx = 20f, maxScroll = 1700),
).isEqualTo(0)
val last = block(7, 23 * 60, 24 * 60)
assertThat(
revealScrollTarget(last, ViewportEdge.Bottom, hourPx = 100f, viewportPx = 700, marginPx = 20f, maxScroll = 1700),
).isEqualTo(1700)
}
// Viewport 1000..1700 px with both bars showing, 40 px of reach.
private fun tapped(y: Float, events: OutOfViewEvents = OutOfViewEvents(breakfast, dinner)) =
tappedEdge(events, y, viewportTop = 1000f, viewportPx = 700, reachPx = 40f)
@Test
fun `a tap near an edge with a bar hits that bar`() {
assertThat(tapped(1010f)).isEqualTo(ViewportEdge.Top)
assertThat(tapped(1040f)).isEqualTo(ViewportEdge.Top)
assertThat(tapped(1690f)).isEqualTo(ViewportEdge.Bottom)
}
@Test
fun `a tap past the bar's reach is left to the column`() {
assertThat(tapped(1041f)).isNull()
assertThat(tapped(1350f)).isNull()
assertThat(tapped(1659f)).isNull()
}
@Test
fun `a tap near an edge without a bar is left to the column`() {
assertThat(tapped(1010f, OutOfViewEvents(null, dinner))).isNull()
assertThat(tapped(1690f, OutOfViewEvents(breakfast, null))).isNull()
}
}
@@ -0,0 +1,53 @@
package de.jeanlucmakiola.calendula.ui.common
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.math.abs
@OptIn(ExperimentalCoroutinesApi::class)
class PageStateCacheTest {
@Test
fun `the same key shares one state`() = runTest {
val cache = PageStateCache<Int, Int>(backgroundScope, 0, { a, b -> abs(a - b) <= 1 }) { flow { emit(it) } }
assertThat(cache.get(5)).isSameInstanceAs(cache.get(5))
}
@Test
fun `a dropped entry stops loading`() = runTest(UnconfinedTestDispatcher()) {
var running = 0
val cache = PageStateCache<Int, Int>(backgroundScope, 0, { a, b -> abs(a - b) <= 1 }) { key ->
flow {
running++
try {
emit(key)
awaitCancellation()
} finally {
running--
}
}
}
backgroundScope.launch { cache.get(0).collect {} }
assertThat(running).isEqualTo(1)
// Far enough away that 0 is let go, even though it is still collected.
cache.get(10)
assertThat(running).isEqualTo(0)
assertThat(cache.size).isEqualTo(1)
}
@Test
fun `nearby entries are kept`() = runTest {
val cache = PageStateCache<Int, Int>(backgroundScope, 0, { a, b -> abs(a - b) <= 2 }) { flow { emit(it) } }
cache.get(4)
cache.get(5)
cache.get(6)
assertThat(cache.size).isEqualTo(3)
}
}
@@ -0,0 +1,115 @@
package de.jeanlucmakiola.calendula.ui.common
import androidx.compose.ui.unit.dp
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
class TimelineHoursTest {
private val viewport = 600.dp
@Test
fun `the chosen range exactly fills the viewport`() {
// 07–22 is 15 hours: 600dp / 15 = 40dp an hour.
assertThat(TimelineScale.FitHours(7, 22).hourHeight(viewport)).isEqualTo(40.dp)
}
@Test
fun `the whole day fits like FitDay`() {
assertThat(TimelineScale.FitHours(0, 24).hourHeight(viewport))
.isEqualTo(TimelineScale.FitDay.hourHeight(viewport))
}
@Test
fun `a short range on a tall screen stops at the pinch ceiling`() {
assertThat(TimelineScale.FitHours(9, 11).hourHeight(2000.dp)).isEqualTo(MAX_PINCH_HOUR_HEIGHT)
}
@Test
fun `ranges are held to the day and the minimum span`() {
assertThat(TimelineHours.of(true, -3, 30)).isEqualTo(TimelineHours(true, 0, 24))
assertThat(TimelineHours.of(true, 23, 22)).isEqualTo(TimelineHours(true, 20, 22))
assertThat(TimelineHours.of(true, 5, 1)).isEqualTo(TimelineHours(true, 0, 2))
}
@Test
fun `the pickers only offer valid pairings`() {
assertThat(TimelineHours.startOptions(22)).isEqualTo((0..20).toList())
assertThat(TimelineHours.endOptions(7)).isEqualTo((9..24).toList())
}
@Test
fun `opening scrolls to the start hour once the layout is at the fitted height`() {
// 40px an hour over a 600px viewport: 960px of content, 360px of scroll.
assertThat(startHourScroll(maxValue = 360, viewportPx = 600, startHour = 7, hourPx = 40f))
.isEqualTo(280)
}
@Test
fun `a layout still at the previous scale is waited out`() {
// Still 56px an hour: 1344 - 600 = 744 of scroll.
assertThat(startHourScroll(maxValue = 744, viewportPx = 600, startHour = 7, hourPx = 40f))
.isNull()
// Not laid out at all yet.
assertThat(startHourScroll(maxValue = Int.MAX_VALUE, viewportPx = 0, startHour = 7, hourPx = 40f))
.isNull()
}
@Test
fun `the whole day needs no scroll`() {
assertThat(startHourScroll(maxValue = 0, viewportPx = 600, startHour = 0, hourPx = 25f))
.isEqualTo(0)
}
@Test
fun `a fitted range round-trips through storage`() {
val scale = TimelineScale.FitHours(6, 20)
assertThat(parseTimelineScale(scale.storageValue())).isEqualTo(scale)
assertThat(parseTimelineScale("hours:x-2")).isEqualTo(TimelineScale.Regular)
}
@Test
fun `opening with visible hours on replaces a pinched scale`() {
val persisted = mutableListOf<TimelineScale>()
val zoom = TimelineZoom(TimelineScale.custom(90.dp)) { persisted += it }
zoom.adoptHours(TimelineHours(true, 7, 22))
assertThat(zoom.open()).isEqualTo(7)
assertThat(zoom.scale).isEqualTo(TimelineScale.FitHours(7, 22))
// A pinch overrides it for the visit but is not saved over the preference.
zoom.beginPinch()
zoom.pinchTo(100.dp)
zoom.endPinch()
assertThat(zoom.scale).isEqualTo(TimelineScale.custom(100.dp))
assertThat(persisted).isEmpty()
// Opening again fits the range again.
zoom.open()
assertThat(zoom.scale).isEqualTo(TimelineScale.FitHours(7, 22))
}
@Test
fun `a late stored scale does not undo the fit, and switching off restores it`() {
val zoom = TimelineZoom(TimelineScale.Regular) {}
zoom.adoptHours(TimelineHours(true, 7, 22))
zoom.open()
zoom.adopt(TimelineScale.Comfortable)
assertThat(zoom.scale).isEqualTo(TimelineScale.FitHours(7, 22))
zoom.adoptHours(TimelineHours(false, 7, 22))
assertThat(zoom.open()).isNull()
assertThat(zoom.scale).isEqualTo(TimelineScale.Comfortable)
}
@Test
fun `with visible hours off a pinch is still saved`() {
val persisted = mutableListOf<TimelineScale>()
val zoom = TimelineZoom(TimelineScale.Regular) { persisted += it }
assertThat(zoom.open()).isNull()
zoom.beginPinch()
zoom.pinchTo(70.dp)
zoom.endPinch()
assertThat(persisted).containsExactly(TimelineScale.custom(70.dp))
}
}
@@ -65,6 +65,14 @@ class ViewBackStackTest {
assertThat(stack.drillToDay()).isEqualTo(stack)
}
@Test
fun `week number drills into week and back returns to month`() {
val stack = listOf(CalendarView.Month).drillToWeek()
assertThat(stack).containsExactly(CalendarView.Month, CalendarView.Week).inOrder()
assertThat(stack.dropLast(1).last()).isEqualTo(CalendarView.Month)
assertThat(stack.drillToWeek()).isEqualTo(stack)
}
@Test
fun `agenda widget date tap backs out agenda then home`() {
// openDate(source = Agenda): root in Agenda over the Week home, then drill.
@@ -0,0 +1,50 @@
package de.jeanlucmakiola.calendula.ui.common
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.calendula.domain.EventInstance
import kotlinx.datetime.LocalDate
import org.junit.jupiter.api.Test
import kotlin.time.Instant
class ViewMorphKeyTest {
private fun instance(instanceId: Long, eventId: Long = 7, startMillis: Long = 1_000L) = EventInstance(
instanceId = instanceId,
eventId = eventId,
calendarId = 1,
title = "Standup",
start = Instant.fromEpochMilliseconds(startMillis),
end = Instant.fromEpochMilliseconds(startMillis + 3_600_000L),
isAllDay = false,
color = 0,
location = null,
)
private val day = LocalDate(2026, 9, 25)
@Test
fun `the same occurrence on the same day matches across views`() {
// Each view reads its own instances query, so the row id is no anchor.
assertThat(ViewMorphKey.event(instance(instanceId = 1), day))
.isEqualTo(ViewMorphKey.event(instance(instanceId = 99), day))
}
@Test
fun `a multi-day event keys each day it is drawn from apart`() {
assertThat(ViewMorphKey.event(instance(1), day))
.isNotEqualTo(ViewMorphKey.event(instance(1), LocalDate(2026, 9, 26)))
}
@Test
fun `two occurrences of one series stay apart`() {
assertThat(ViewMorphKey.event(instance(1, startMillis = 1_000L), day))
.isNotEqualTo(ViewMorphKey.event(instance(2, startMillis = 2_000L), day))
}
@Test
fun `only the settled page morphs`() {
assertThat(morphPageActive(page = 5, settledPage = 5)).isTrue()
assertThat(morphPageActive(page = 4, settledPage = 5)).isFalse()
assertThat(morphPageActive(page = 6, settledPage = 5)).isFalse()
}
}
@@ -0,0 +1,20 @@
package de.jeanlucmakiola.calendula.ui.common
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
/** Which screen draws each view: the timeline views share one, so switching among them resizes it (#184). */
class ViewScreenTest {
@Test
fun `the day, multi-day and week views share the timeline`() {
assertThat(listOf(CalendarView.Day, CalendarView.MultiDay, CalendarView.Week).map { it.screen }.toSet())
.containsExactly(ViewScreen.Timeline)
}
@Test
fun `month and agenda each have their own screen`() {
assertThat(CalendarView.Month.screen).isEqualTo(ViewScreen.Month)
assertThat(CalendarView.Agenda.screen).isEqualTo(ViewScreen.Agenda)
}
}
@@ -0,0 +1,22 @@
package de.jeanlucmakiola.calendula.ui.day
import com.google.common.truth.Truth.assertThat
import kotlinx.datetime.LocalDate
import org.junit.jupiter.api.Test
class DayPagingTest {
@Test
fun `a page and its day round-trip`() {
listOf(LocalDate(2026, 9, 27), LocalDate(1990, 5, 16), LocalDate(2100, 2, 28)).forEach { day ->
assertThat(dayForPage(dayPageFor(day))).isEqualTo(day)
}
}
@Test
fun `adjacent pages are adjacent days across a month end`() {
val page = dayPageFor(LocalDate(2026, 2, 28))
assertThat(dayForPage(page + 1)).isEqualTo(LocalDate(2026, 3, 1))
assertThat(dayForPage(page - 1)).isEqualTo(LocalDate(2026, 2, 27))
}
}
@@ -340,4 +340,71 @@ class EventEditViewModelTest {
assertThat(fake.movedEvents).isEmpty()
job.cancel()
}
@Test
fun `setTitle caps a long paste at 255 chars`(
@TempDir tempDir: Path,
) = runTest(dispatcher) {
val fake = FakeCalendarDataSource().apply { calendarsResult = listOf(cal(1L)) }
val vm = viewModel(tempDir, fake)
val job = activate(vm)
vm.openNew(LocalDate(2030, 1, 15))
advanceUntilIdle()
vm.setTitle("a".repeat(300))
assertThat(vm.state.value?.form?.title).hasLength(MAX_SINGLE_LINE_FIELD)
job.cancel()
}
@Test
fun `setTitle refuses to grow past 255 chars once capped`(
@TempDir tempDir: Path,
) = runTest(dispatcher) {
val fake = FakeCalendarDataSource().apply { calendarsResult = listOf(cal(1L)) }
val vm = viewModel(tempDir, fake)
val job = activate(vm)
vm.openNew(LocalDate(2030, 1, 15))
advanceUntilIdle()
vm.setTitle("a".repeat(255))
vm.setTitle("a".repeat(256))
assertThat(vm.state.value?.form?.title).hasLength(255)
job.cancel()
}
@Test
fun `setLocation joins a multi-line address then caps it`(
@TempDir tempDir: Path,
) = runTest(dispatcher) {
val fake = FakeCalendarDataSource().apply { calendarsResult = listOf(cal(1L)) }
val vm = viewModel(tempDir, fake)
val job = activate(vm)
vm.openNew(LocalDate(2030, 1, 15))
advanceUntilIdle()
vm.setLocation("${"a".repeat(200)}\n${"b".repeat(200)}")
val location = vm.state.value?.form?.location
assertThat(location).hasLength(MAX_SINGLE_LINE_FIELD)
assertThat(location).contains(", ")
job.cancel()
}
@Test
fun `capLength lets an already-over-long value shrink`() {
val overLong = "a".repeat(300)
val shortened = overLong.dropLast(1)
assertThat(capLength(shortened, overLong)).hasLength(299)
}
@Test
fun `capLength never splits a surrogate pair at the cut point`() {
// U+1F600, a surrogate pair, sits right across the 255 boundary.
val new = "a".repeat(254) + "😀"
assertThat(capLength(new, "")).isEqualTo("a".repeat(254))
}
}
@@ -222,17 +222,17 @@ class ContinuousMonthIndexTest {
}
@Test
fun `the split selection follows the month, landing on today when it's there`() {
fun `the split agenda starts at today in the current month`() {
val today = LocalDate(2026, 6, 10)
assertThat(selectionForMonth(jun26, today)).isEqualTo(today)
assertThat(agendaStartForMonth(jun26, today)).isEqualTo(today)
}
@Test
fun `the split selection falls to the 1st of any other month`() {
fun `the split agenda starts at the 1st of another month`() {
val today = LocalDate(2026, 6, 10)
assertThat(selectionForMonth(YearMonth(2026, Month.JULY), today))
assertThat(agendaStartForMonth(YearMonth(2026, Month.JULY), today))
.isEqualTo(LocalDate(2026, 7, 1))
assertThat(selectionForMonth(YearMonth(2025, Month.JUNE), today))
assertThat(agendaStartForMonth(YearMonth(2025, Month.JUNE), today))
.isEqualTo(LocalDate(2025, 6, 1))
}
}
@@ -163,6 +163,18 @@ class MonthLayoutTest {
assertThat(week.spans.map { it.lane }).containsExactly(0, 1)
}
@Test
fun `multi-day bar is above a one-day all-day bar on the same date`() {
val day = LocalDate(2026, 6, 10)
val single = allDay(day, id = 1L, title = "Single")
val multi = allDay(day, day.plus(2, DateTimeUnit.DAY), id = 2L, title = "Multi")
val week = layoutCalendarWeek(weekOf8th, listOf(single, multi), zone)
val lanes = week.spans.associate { it.event.title to it.lane }
assertThat(lanes.getValue("Multi")).isLessThan(lanes.getValue("Single"))
assertThat(instancesByDay(listOf(day), listOf(single, multi), zone).getValue(day).map { it.title })
.containsExactly("Multi", "Single").inOrder()
}
@Test
fun `single-day timed events stay pills and sort by start`() {
val late = timed(LocalDate(2026, 6, 10), 14, 15, id = 1L)
@@ -0,0 +1,107 @@
package de.jeanlucmakiola.calendula.ui.week
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.calendula.domain.EventInstance
import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.LocalDate
import kotlinx.datetime.plus
import kotlin.time.Instant
import org.junit.jupiter.api.Test
/** The timeline's columns, standing still and mid view switch (#184). */
class ColumnGeometryTest {
// 2026-09-27 is a Sunday; the week runs Sun..Sat.
private val sunday = LocalDate(2026, 9, 27)
private val week = DaySpan(sunday, 7)
private val monday = sunday.plus(1, DateTimeUnit.DAY)
private val day = DaySpan(monday, 1)
private val width = 700f
private val gap = 7f
@Test
fun `a page's columns follow the pitch`() {
val slot = week.slot(sunday.plus(3, DateTimeUnit.DAY), width, gap)
assertThat(slot.left).isEqualTo(3 * 101f)
assertThat(slot.width).isEqualTo(94f)
}
@Test
fun `the ends of a switch are the two pages`() {
var p = 0f
val geometry = ColumnGeometry(week, day) { p }
assertThat(geometry.slot(monday, width, gap)).isEqualTo(week.slot(monday, width, gap))
p = 1f
assertThat(geometry.slot(monday, width, gap)).isEqualTo(day.slot(monday, width, gap))
}
@Test
fun `days off the target page end off screen on their side`() {
val geometry = ColumnGeometry(week, day) { 1f }
assertThat(geometry.slot(sunday, width, gap).right).isAtMost(0f)
assertThat(geometry.slot(monday.plus(1, DateTimeUnit.DAY), width, gap).left).isAtLeast(width)
}
@Test
fun `a switch covers both pages without a break`() {
// Focus on Saturday: the six-day run starting there reaches into next week.
val saturday = sunday.plus(6, DateTimeUnit.DAY)
val geometry = ColumnGeometry(week, DaySpan(saturday, 6)) { 0f }
assertThat(geometry.dates).hasSize(12)
assertThat(geometry.dates.first()).isEqualTo(sunday)
assertThat(geometry.dates.zipWithNext().all { (a, b) -> b == a.plus(1, DateTimeUnit.DAY) }).isTrue()
}
@Test
fun `a bar spans its extent on each page`() {
val tuesday = monday.plus(1, DateTimeUnit.DAY)
val range = monday..tuesday
val geometry = ColumnGeometry(week, day) { 0f }
val extent = geometry.extent(range, monday..monday, width, 0f)
assertThat(extent.left).isEqualTo(week.slot(monday, width, 0f).left)
assertThat(extent.right).isEqualTo(week.slot(tuesday, width, 0f).right)
}
@Test
fun `a bar only one page has keeps its days on the other`() {
val bar = AllDaySpan(event(1), startCol = 2, endCol = 3, lane = 1)
val from = state(week, listOf(bar))
val to = state(day, emptyList())
val placed = morphBars(from, to).single()
assertThat(placed.fromRange).isEqualTo(placed.toRange)
assertThat(placed.toLane).isEqualTo(1)
}
@Test
fun `a bar on both pages is placed once, clipped to each`() {
val event = event(1)
val from = state(week, listOf(AllDaySpan(event, startCol = 0, endCol = 6, lane = 0)))
val to = state(day, listOf(AllDaySpan(event, startCol = 0, endCol = 0, lane = 0)))
val placed = morphBars(from, to).single()
assertThat(placed.fromRange).isEqualTo(sunday..sunday.plus(6, DateTimeUnit.DAY))
assertThat(placed.toRange).isEqualTo(monday..monday)
}
private fun state(span: DaySpan, bars: List<AllDaySpan>): WeekUiState.Success {
val days = (0 until span.count).map { span.start.plus(it, DateTimeUnit.DAY) }
return WeekUiState.Success(
weekStart = span.start,
today = sunday,
days = days,
allDaySpans = bars,
timedByDay = emptyMap(),
)
}
private fun event(id: Long) = EventInstance(
instanceId = id,
eventId = id,
calendarId = 1L,
title = "Event",
start = Instant.fromEpochMilliseconds(0),
end = Instant.fromEpochMilliseconds(0),
isAllDay = true,
color = 0xFF000000.toInt(),
location = null,
)
}
@@ -0,0 +1,40 @@
package de.jeanlucmakiola.calendula.ui.week
import com.google.common.truth.Truth.assertThat
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate
import org.junit.jupiter.api.Test
/** Where the focused date goes as a timeline pages (#184). */
class FocusOnPageTest {
// 2026-09-30 is a Wednesday.
private val wednesday = LocalDate(2026, 9, 30)
@Test
fun `a page that still shows the focus keeps it`() {
val grid = WeekGrid(DayOfWeek.MONDAY)
assertThat(grid.focusOnPage(wednesday, grid.pageFor(wednesday))).isEqualTo(wednesday)
}
@Test
fun `a week on keeps the weekday`() {
val grid = WeekGrid(DayOfWeek.MONDAY)
val page = grid.pageFor(wednesday)
assertThat(grid.focusOnPage(wednesday, page + 1)).isEqualTo(LocalDate(2026, 10, 7))
assertThat(grid.focusOnPage(wednesday, page - 2)).isEqualTo(LocalDate(2026, 9, 16))
}
@Test
fun `a run of days keeps the focus's column`() {
val grid = DaysGrid.startingAt(LocalDate(2026, 9, 29), 3)
val page = grid.pageFor(wednesday)
assertThat(grid.focusOnPage(wednesday, page + 1)).isEqualTo(LocalDate(2026, 10, 3))
}
@Test
fun `a day page is the focus`() {
val page = DayGrid.pageFor(wednesday)
assertThat(DayGrid.focusOnPage(wednesday, page + 5)).isEqualTo(LocalDate(2026, 10, 5))
}
}
@@ -49,8 +49,8 @@ class WeekLayoutTest {
}
@Test
fun `weekRange spans seven days`() {
val range = weekRange(mon, zone)
fun `spanRange spans seven days`() {
val range = spanRange(mon, 7, zone)
assertThat(range.start).isEqualTo(at(mon, 0, 0))
// endInclusive is the last second of day 7 (Sunday 2026-06-14)
assertThat(range.endInclusive).isEqualTo(LocalDate(2026, 6, 14).atTime(23, 59, 59).toInstant(zone))
@@ -0,0 +1,81 @@
package de.jeanlucmakiola.calendula.ui.week
import com.google.common.truth.Truth.assertThat
import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate
import kotlinx.datetime.plus
import org.junit.jupiter.api.Test
class WeekPagingTest {
// 2026-09-27 is a Sunday.
private val sunday = LocalDate(2026, 9, 27)
@Test
fun `a page and its week round-trip for every first day`() {
DayOfWeek.entries.forEach { firstDay ->
val page = weekPageFor(sunday, firstDay)
val start = weekStartForPage(page, firstDay)
assertThat(start).isEqualTo(sunday.startOfWeek(firstDay))
assertThat(weekPageFor(start, firstDay)).isEqualTo(page)
}
}
@Test
fun `every day of a week maps to the same page`() {
val start = sunday.startOfWeek(DayOfWeek.MONDAY)
val pages = (0..6).map { weekPageFor(start.plus(it, DateTimeUnit.DAY), DayOfWeek.MONDAY) }
assertThat(pages.toSet()).hasSize(1)
}
@Test
fun `adjacent pages are adjacent weeks`() {
val page = weekPageFor(sunday, DayOfWeek.SUNDAY)
assertThat(weekStartForPage(page + 1, DayOfWeek.SUNDAY))
.isEqualTo(LocalDate(2026, 10, 4))
assertThat(weekStartForPage(page - 1, DayOfWeek.SUNDAY))
.isEqualTo(LocalDate(2026, 9, 20))
}
@Test
fun `dates before the epoch page resolve too`() {
val old = LocalDate(1990, 5, 16)
val page = weekPageFor(old, DayOfWeek.MONDAY)
assertThat(weekStartForPage(page, DayOfWeek.MONDAY)).isEqualTo(LocalDate(1990, 5, 14))
}
@Test
fun `multi-day pages begin on the selected date and advance by the chosen count`() {
(3..6).forEach { count ->
val grid = DaysGrid.startingAt(sunday, count)
val page = grid.pageFor(sunday)
assertThat(grid.startForPage(page)).isEqualTo(sunday)
assertThat(grid.startForPage(page + 1)).isEqualTo(sunday.plus(count, DateTimeUnit.DAY))
assertThat(grid.pageFor(sunday.plus(count - 1, DateTimeUnit.DAY))).isEqualTo(page)
}
}
@Test
fun `multi-day pages also work before the epoch`() {
val date = LocalDate(1990, 5, 16)
val grid = DaysGrid.startingAt(date, 3)
val page = grid.pageFor(date)
assertThat(grid.startForPage(page)).isEqualTo(date)
assertThat(grid.startForPage(page - 1)).isEqualTo(LocalDate(1990, 5, 13))
}
@Test
fun `a day page and its day round-trip`() {
listOf(LocalDate(2026, 9, 27), LocalDate(1990, 5, 16), LocalDate(2100, 2, 28)).forEach { day ->
assertThat(DayGrid.startForPage(DayGrid.pageFor(day))).isEqualTo(day)
}
}
@Test
fun `adjacent day pages are adjacent days across a month end`() {
val page = DayGrid.pageFor(LocalDate(2026, 2, 28))
assertThat(DayGrid.startForPage(page + 1)).isEqualTo(LocalDate(2026, 3, 1))
assertThat(DayGrid.startForPage(page - 1)).isEqualTo(LocalDate(2026, 2, 27))
}
}