Release v2.24.0 (#487)
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 8s
Renovate / renovate (push) Successful in 2m19s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Successful in 20m28s
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Successful in 1m34s
Beta — Codeberg pre-release / detect (push) Successful in 6s
Beta — Codeberg pre-release / beta (push) Skipped
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 8s
Renovate / renovate (push) Successful in 2m19s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Successful in 20m28s
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Successful in 1m34s
Beta — Codeberg pre-release / detect (push) Successful in 6s
Beta — Codeberg pre-release / beta (push) Skipped
2.24.0: the widget redesign and the fixes collected on release/2.24.0. Full list in CHANGELOG.md under 2.24.0. - Seven new widgets (quick add, date, week strip, upcoming, today, countdown, month with day), each with its own settings; new look for the agenda and month widgets. - Drag all-day events between days or into the grid; cancelled and tentative events are marked; month view setting to hide start times. - Fixes: short events late at night, one notification per event, weekend missing from the week strip widget, split month view animations and back gesture. - Weblate translations from #434, including the new Traditional Chinese (zh-TW), with its store listing and What's New. Merges main's v2.23.1 in. #427 is moved out of the milestone until it can be reproduced. Closes #434 Co-authored-by: Jean-Luc Makiola <business@jeanlucmakiola.de> Co-authored-by: Sup99999 <alelmnour1o234@proton.me> Co-authored-by: Weblate <noreply-mt-weblate@weblate.org> Co-authored-by: Benutzer <gabrielegobboch@protonmail.ch> Co-authored-by: N Donkersloot <n@donkerslootjes.nl> Co-authored-by: VinCap <vcapaldo@ik.me> Co-authored-by: AventineC <AventineC@outlook.com> Co-authored-by: Weblate <noreply@weblate.org> Co-authored-by: NattyNarwhal <fr.schuessele@gmx.de> Co-authored-by: James Trivette <trivette@atlas.cz> Co-authored-by: Dmitri Gabinski <dkgabi@gmail.com> Co-authored-by: Tritra002 <tritratrulala002@outlook.com> Reviewed-on: https://codeberg.org/jlmakiola/calendula/pulls/487
This commit is contained in:
+3








committed 2026-11-06 17:49:13 +01:00
1 parent
a5c4a73de1
commit
9ccc303a2a
228 files changed
+11419
-2259
No files matched your search
@@ -4,6 +4,7 @@ import android.provider.CalendarContract
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.AccessLevel
|
||||
import de.jeanlucmakiola.calendula.domain.Availability
|
||||
import de.jeanlucmakiola.calendula.domain.EventStatus
|
||||
import de.jeanlucmakiola.calendula.domain.EventForm
|
||||
import de.jeanlucmakiola.calendula.domain.FormTime
|
||||
import de.jeanlucmakiola.calendula.domain.realignRecurrence
|
||||
@@ -1112,6 +1113,52 @@ class EventWriteMapperTest {
|
||||
assertThat(values).containsEntry(CalendarContract.Events.EVENT_COLOR_KEY, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a status change on update writes just the status`() {
|
||||
val original = form()
|
||||
val values = update(original, original.copy(status = EventStatus.Cancelled))
|
||||
assertThat(values).containsExactly(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CANCELED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an unchanged status writes no status column`() {
|
||||
val original = form().copy(status = EventStatus.Tentative)
|
||||
assertThat(update(original, original.copy(title = "Renamed")))
|
||||
.doesNotContainKey(CalendarContract.Events.STATUS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a new event writes its status only when it is not confirmed`() {
|
||||
val confirmed = form()
|
||||
assertThat(buildEventInsertValues(confirmed, "uid", confirmed.toWriteTimes(berlin)))
|
||||
.doesNotContainKey(CalendarContract.Events.STATUS)
|
||||
val tentative = form().copy(status = EventStatus.Tentative)
|
||||
assertThat(buildEventInsertValues(tentative, "uid", tentative.toWriteTimes(berlin)))
|
||||
.containsEntry(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_TENTATIVE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `occurrence exception writes the form's status`() {
|
||||
val values = buildOccurrenceExceptionValues(
|
||||
form = form().copy(status = EventStatus.Tentative),
|
||||
originalInstanceMillis = 0L,
|
||||
zone = berlin,
|
||||
)
|
||||
assertThat(values).containsEntry(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_TENTATIVE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `no new row is written cancelled`() {
|
||||
val cancelled = form().copy(status = EventStatus.Cancelled)
|
||||
assertThat(buildEventInsertValues(cancelled, "uid", cancelled.toWriteTimes(berlin)))
|
||||
.doesNotContainKey(CalendarContract.Events.STATUS)
|
||||
assertThat(buildOccurrenceExceptionValues(cancelled, originalInstanceMillis = 0L, zone = berlin))
|
||||
.containsEntry(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED)
|
||||
val snapshot = masterSnapshot().copy(status = CalendarContract.Events.STATUS_CANCELED)
|
||||
assertThat(buildMovedMasterValues(snapshot, targetCalendarId = 9L, uid = "u@calendula"))
|
||||
.doesNotContainKey(CalendarContract.Events.STATUS)
|
||||
}
|
||||
|
||||
// --- buildMovedMasterValues (calendar move: verbatim series copy) ---
|
||||
|
||||
private fun masterSnapshot(
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.jeanlucmakiola.calendula.data.calendar
|
||||
import android.provider.CalendarContract
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.EventColorOption
|
||||
import de.jeanlucmakiola.calendula.domain.EventStatus
|
||||
import de.jeanlucmakiola.calendula.domain.ics.ParsedIcsEvent
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Instant
|
||||
@@ -31,6 +32,12 @@ class ImportedEventValuesTest {
|
||||
private fun values(event: ParsedIcsEvent, palette: List<EventColorOption> = emptyList()) =
|
||||
buildImportedEventValues(event, calendarId = 7L, uid = "u@x", palette = palette)
|
||||
|
||||
@Test
|
||||
fun `a cancelled event is imported confirmed`() {
|
||||
assertThat(values(allDay().copy(status = EventStatus.Cancelled))[CalendarContract.Events.STATUS])
|
||||
.isEqualTo(CalendarContract.Events.STATUS_CONFIRMED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a one-off carries DTEND and no recurrence`() {
|
||||
val v = values(allDay())
|
||||
|
||||
@@ -3,7 +3,9 @@ package de.jeanlucmakiola.calendula.data.calendar
|
||||
import android.provider.CalendarContract
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.EventResponse
|
||||
import de.jeanlucmakiola.calendula.domain.isDeclined
|
||||
import de.jeanlucmakiola.calendula.domain.EventStatus
|
||||
import de.jeanlucmakiola.calendula.domain.isCrossedOut
|
||||
import de.jeanlucmakiola.calendula.domain.isOutlined
|
||||
import kotlin.time.Instant
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@@ -21,6 +23,7 @@ class InstanceMapperTest {
|
||||
calendarColor: Int = 0xFFAABBCC.toInt(),
|
||||
location: String? = null,
|
||||
selfAttendeeStatus: Int = CalendarContract.Attendees.ATTENDEE_STATUS_NONE,
|
||||
status: Int? = null,
|
||||
): MapColumnReader = MapColumnReader(
|
||||
InstanceProjection.IDX_INSTANCE_ID to instanceId,
|
||||
InstanceProjection.IDX_EVENT_ID to eventId,
|
||||
@@ -33,6 +36,7 @@ class InstanceMapperTest {
|
||||
InstanceProjection.IDX_CALENDAR_COLOR to calendarColor,
|
||||
InstanceProjection.IDX_LOCATION to location,
|
||||
InstanceProjection.IDX_SELF_ATTENDEE_STATUS to selfAttendeeStatus,
|
||||
InstanceProjection.IDX_STATUS to status,
|
||||
)
|
||||
|
||||
@Test
|
||||
@@ -98,17 +102,17 @@ class InstanceMapperTest {
|
||||
|
||||
@Test
|
||||
fun `a declined invitation is marked, any other answer is not`() {
|
||||
assertThat(reader().toEventInstance()!!.isDeclined).isFalse()
|
||||
assertThat(reader().toEventInstance()!!.isCrossedOut).isFalse()
|
||||
assertThat(
|
||||
reader(selfAttendeeStatus = CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
|
||||
.toEventInstance()!!.isDeclined,
|
||||
.toEventInstance()!!.isCrossedOut,
|
||||
).isTrue()
|
||||
listOf(
|
||||
CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED,
|
||||
CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE,
|
||||
CalendarContract.Attendees.ATTENDEE_STATUS_INVITED,
|
||||
).forEach { status ->
|
||||
assertThat(reader(selfAttendeeStatus = status).toEventInstance()!!.isDeclined).isFalse()
|
||||
assertThat(reader(selfAttendeeStatus = status).toEventInstance()!!.isCrossedOut).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,4 +133,42 @@ class InstanceMapperTest {
|
||||
.isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the event status is read, a missing one is confirmed`() {
|
||||
assertThat(reader().toEventInstance()!!.status).isEqualTo(EventStatus.Confirmed)
|
||||
assertThat(reader(status = CalendarContract.Events.STATUS_TENTATIVE).toEventInstance()!!.status)
|
||||
.isEqualTo(EventStatus.Tentative)
|
||||
assertThat(reader(status = CalendarContract.Events.STATUS_CANCELED).toEventInstance()!!.status)
|
||||
.isEqualTo(EventStatus.Cancelled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a cancelled event is crossed out, a tentative one outlined`() {
|
||||
val cancelled = reader(status = CalendarContract.Events.STATUS_CANCELED).toEventInstance()!!
|
||||
val tentative = reader(status = CalendarContract.Events.STATUS_TENTATIVE).toEventInstance()!!
|
||||
assertThat(cancelled.isCrossedOut).isTrue()
|
||||
assertThat(cancelled.isOutlined).isFalse()
|
||||
assertThat(tentative.isCrossedOut).isFalse()
|
||||
assertThat(tentative.isOutlined).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a cancelled unanswered invitation is crossed out rather than outlined`() {
|
||||
val event = reader(
|
||||
selfAttendeeStatus = CalendarContract.Attendees.ATTENDEE_STATUS_INVITED,
|
||||
status = CalendarContract.Events.STATUS_CANCELED,
|
||||
).toEventInstance()!!
|
||||
assertThat(event.isCrossedOut).isTrue()
|
||||
assertThat(event.isOutlined).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a cancelled one-off from the events table gets a negated id`() {
|
||||
val inst = reader(instanceId = 7L, eventId = 7L, status = CalendarContract.Events.STATUS_CANCELED)
|
||||
.toCancelledOneOff()
|
||||
assertThat(inst?.instanceId).isEqualTo(-7L)
|
||||
assertThat(inst?.eventId).isEqualTo(7L)
|
||||
assertThat(inst?.isCrossedOut).isTrue()
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,14 @@ class SettingsPrefsTest {
|
||||
assertThat(prefs.showWeekNumbers.first()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `month start times default on and round-trips`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
assertThat(prefs.monthShowStartTimes.first()).isTrue()
|
||||
prefs.setMonthShowStartTimes(false)
|
||||
assertThat(prefs.monthShowStartTimes.first()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `autofocus event title defaults on and round-trips`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
@@ -165,15 +173,12 @@ class SettingsPrefsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `agenda ranges default to month and round-trip independently`(@TempDir tempDir: Path) = runTest {
|
||||
fun `agenda screen range defaults to month and round-trips`(@TempDir tempDir: Path) = runTest {
|
||||
val prefs = testSettings(tempDir)
|
||||
assertThat(prefs.agendaScreenRange.first()).isEqualTo(AgendaRange.Month)
|
||||
assertThat(prefs.agendaWidgetRange.first()).isEqualTo(AgendaRange.Month)
|
||||
|
||||
prefs.setAgendaScreenRange(AgendaRange.Custom(14))
|
||||
prefs.setAgendaWidgetRange(AgendaRange.Week)
|
||||
assertThat(prefs.agendaScreenRange.first()).isEqualTo(AgendaRange.Custom(14))
|
||||
assertThat(prefs.agendaWidgetRange.first()).isEqualTo(AgendaRange.Week)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package de.jeanlucmakiola.calendula.data.reminders
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.reminders.PlannedReminder
|
||||
import de.jeanlucmakiola.calendula.domain.reminders.ReminderEventInstance
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ReminderAlertTest {
|
||||
|
||||
private fun instance(eventId: Long = 1L, beginMillis: Long = 1_800_000_000_000L) = ReminderEventInstance(
|
||||
eventId = eventId,
|
||||
calendarId = 1L,
|
||||
beginMillis = beginMillis,
|
||||
endMillis = beginMillis + 3_600_000L,
|
||||
title = "Dentist",
|
||||
location = null,
|
||||
isAllDay = false,
|
||||
)
|
||||
|
||||
private fun alert(instance: ReminderEventInstance, minutes: Int) =
|
||||
PlannedReminder(instance, minutes, instance.beginMillis - minutes * 60_000L).toAlert()
|
||||
|
||||
@Test
|
||||
fun `two reminders on one occurrence share a notification`() {
|
||||
val dayBefore = alert(instance(), 1_440)
|
||||
val hourBefore = alert(instance(), 60)
|
||||
|
||||
assertThat(dayBefore.key).isNotEqualTo(hourBefore.key)
|
||||
assertThat(dayBefore.occurrenceKey).isEqualTo(hourBefore.occurrenceKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `occurrences of one series keep their own notifications`() {
|
||||
val first = alert(instance(beginMillis = 1_800_000_000_000L), 60)
|
||||
val second = alert(instance(beginMillis = 1_800_086_400_000L), 60)
|
||||
|
||||
assertThat(first.occurrenceKey).isNotEqualTo(second.occurrenceKey)
|
||||
}
|
||||
}
|
||||
@@ -212,4 +212,30 @@ class ReminderTimeTextTest {
|
||||
)
|
||||
assertThat(text).isEqualTo("Today")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed event from local midnight to midnight reads like an all-day one`() {
|
||||
val oneDay = text(
|
||||
beginMillis = millisAt(LocalDateTime.of(2026, 6, 12, 0, 0), berlin),
|
||||
endMillis = millisAt(LocalDateTime.of(2026, 6, 13, 0, 0), berlin),
|
||||
today = LocalDate.of(2026, 6, 11),
|
||||
)
|
||||
assertThat(oneDay).isEqualTo("Tomorrow")
|
||||
val twoDays = text(
|
||||
beginMillis = millisAt(LocalDateTime.of(2026, 6, 11, 0, 0), berlin),
|
||||
endMillis = millisAt(LocalDateTime.of(2026, 6, 13, 0, 0), berlin),
|
||||
)
|
||||
assertThat(twoDays).startsWith("Today – ")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `midnight is read in the device zone`() {
|
||||
// Midnight in Berlin is 22:00 the day before in UTC, so it is timed there.
|
||||
val text = text(
|
||||
beginMillis = millisAt(LocalDateTime.of(2026, 6, 12, 0, 0), berlin),
|
||||
endMillis = millisAt(LocalDateTime.of(2026, 6, 13, 0, 0), berlin),
|
||||
zone = ZoneOffset.UTC,
|
||||
)
|
||||
assertThat(text).contains("22:00")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package de.jeanlucmakiola.calendula.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.testEvent
|
||||
import kotlinx.datetime.DateTimeUnit
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.atStartOfDayIn
|
||||
import kotlinx.datetime.plus
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Instant
|
||||
|
||||
class EventDisplayOrderTest {
|
||||
|
||||
@Test
|
||||
fun `whole-day events order by title east and west of UTC`() {
|
||||
listOf("Europe/Berlin", "America/New_York").map(TimeZone::of).forEach { zone ->
|
||||
val day = LocalDate(2026, 11, 5)
|
||||
val allDay = testEvent(
|
||||
id = 1, title = "B all-day", isAllDay = true,
|
||||
start = Instant.parse("2026-11-05T00:00:00Z"), end = Instant.parse("2026-11-06T00:00:00Z"),
|
||||
)
|
||||
val timed = testEvent(
|
||||
id = 2, title = "A timed",
|
||||
start = day.atStartOfDayIn(zone), end = day.plus(1, DateTimeUnit.DAY).atStartOfDayIn(zone),
|
||||
)
|
||||
|
||||
assertThat(listOf(allDay, timed).sortedForDisplay(zone)).containsExactly(timed, allDay).inOrder()
|
||||
assertThat(listOf(timed, allDay).sortedForDisplay(zone)).containsExactly(timed, allDay).inOrder()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,6 +346,7 @@ class EventFormTest {
|
||||
rrule = "FREQ=DAILY",
|
||||
availability = Availability.Free,
|
||||
accessLevel = AccessLevel.Private,
|
||||
status = EventStatus.Tentative,
|
||||
color = 0xFFD50000.toInt(),
|
||||
)
|
||||
assertThat(full.populatedFields()).containsExactly(
|
||||
@@ -354,6 +355,7 @@ class EventFormTest {
|
||||
EventFormField.Reminders,
|
||||
EventFormField.Recurrence,
|
||||
EventFormField.Availability,
|
||||
EventFormField.Status,
|
||||
EventFormField.Visibility,
|
||||
EventFormField.Color,
|
||||
)
|
||||
@@ -570,4 +572,20 @@ class EventFormTest {
|
||||
val started = form.withStart(LocalDateTime(LocalDate(2026, 3, 29), LocalTime(2, 30)), berlin)
|
||||
assertThat(started.start.dateTime).isEqualTo(LocalDateTime(LocalDate(2026, 3, 29), LocalTime(3, 30)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a cancelled form saves only as the whole series`() {
|
||||
assertThat(form().canSaveApartFromSeries()).isTrue()
|
||||
assertThat(form().copy(status = EventStatus.Tentative).canSaveApartFromSeries()).isTrue()
|
||||
assertThat(form().copy(status = EventStatus.Cancelled).canSaveApartFromSeries()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a copy of a cancelled event starts confirmed, a tentative one stays tentative`() {
|
||||
val zone = TimeZone.of("Europe/Berlin")
|
||||
assertThat(testDetail(status = EventStatus.Cancelled).toDuplicateForm(canModify = true, zone).status)
|
||||
.isEqualTo(EventStatus.Confirmed)
|
||||
assertThat(testDetail(status = EventStatus.Tentative).toDuplicateForm(canModify = true, zone).status)
|
||||
.isEqualTo(EventStatus.Tentative)
|
||||
}
|
||||
}
|
||||
@@ -82,4 +82,39 @@ class EventInstanceSpanTest {
|
||||
val timed = instance(utc(2026, 7, 19, 12), utc(2026, 7, 19, 13), isAllDay = false)
|
||||
assertThat(timed.dateZone(newYork)).isEqualTo(newYork)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed event from local midnight to local midnight covers whole days`() {
|
||||
// Stored as 22:00Z, the shape ICSx5 gives a date-only feed event (#296).
|
||||
val oneDay = instance(utc(2026, 7, 18, 22), utc(2026, 7, 19, 22), isAllDay = false)
|
||||
val twoDays = instance(utc(2026, 7, 18, 22), utc(2026, 7, 20, 22), isAllDay = false)
|
||||
assertThat(oneDay.coversWholeDays(berlin)).isTrue()
|
||||
assertThat(twoDays.coversWholeDays(berlin)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `local midnight is read in the device zone`() {
|
||||
val event = instance(utc(2026, 7, 18, 22), utc(2026, 7, 19, 22), isAllDay = false)
|
||||
assertThat(event.coversWholeDays(newYork)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed event off midnight at either end does not cover whole days`() {
|
||||
assertThat(instance(utc(2026, 7, 19), utc(2026, 7, 19, 23), isAllDay = false).coversWholeDays(TimeZone.UTC))
|
||||
.isFalse()
|
||||
assertThat(instance(utc(2026, 7, 19, 1), utc(2026, 7, 20), isAllDay = false).coversWholeDays(TimeZone.UTC))
|
||||
.isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a zero-length event at midnight does not cover whole days`() {
|
||||
assertThat(instance(utc(2026, 7, 19), utc(2026, 7, 19), isAllDay = false).coversWholeDays(TimeZone.UTC))
|
||||
.isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day event covers whole days in any zone`() {
|
||||
assertThat(allDayJul19().coversWholeDays(newYork)).isTrue()
|
||||
assertThat(allDayJul19().coversWholeDays(berlin)).isTrue()
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.jeanlucmakiola.calendula.domain
|
||||
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
@@ -195,11 +197,13 @@ class EventShiftTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day event ignores a resize`() {
|
||||
fun `a resized all-day event becomes timed`() {
|
||||
val allDay = form(isAllDay = true)
|
||||
val start = allDay.start.dateTime.toInstant(berlin)
|
||||
|
||||
assertThat(allDay.resizedTo(start, start, berlin)).isEqualTo(allDay)
|
||||
val timed = allDay.resizedTo(start, start + 1.hours, berlin)
|
||||
assertThat(timed.isAllDay).isFalse()
|
||||
assertThat(timed.end.dateTime).isEqualTo(allDay.start.dateTime.toInstant(berlin).plus(1.hours).toLocalDateTime(berlin))
|
||||
}
|
||||
|
||||
// 02:00 CEST to 02:00 CET on 2026-10-25: one real hour, one wall-clock value.
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.jeanlucmakiola.calendula.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.testEvent
|
||||
import kotlinx.datetime.TimeZone
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Instant
|
||||
|
||||
class HasEndedTest {
|
||||
|
||||
private val newYork = TimeZone.of("America/New_York")
|
||||
|
||||
// All-day Oct 28, stored as UTC midnights.
|
||||
private val holiday = testEvent(
|
||||
title = "Holiday",
|
||||
start = Instant.parse("2026-10-28T00:00:00Z"),
|
||||
end = Instant.parse("2026-10-29T00:00:00Z"),
|
||||
isAllDay = true,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `an all-day event runs until local midnight west of UTC`() {
|
||||
// 20:00 in New York, past the stored UTC end.
|
||||
assertThat(holiday.hasEnded(Instant.parse("2026-10-29T00:00:00Z"), newYork)).isFalse()
|
||||
assertThat(holiday.hasEnded(Instant.parse("2026-10-29T04:00:00Z"), newYork)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day event ends at local midnight east of UTC`() {
|
||||
val berlin = TimeZone.of("Europe/Berlin")
|
||||
assertThat(holiday.hasEnded(Instant.parse("2026-10-28T23:30:00Z"), berlin)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed event ends at its own end`() {
|
||||
val call = holiday.copy(isAllDay = false, end = Instant.parse("2026-10-28T15:00:00Z"))
|
||||
assertThat(call.hasEnded(Instant.parse("2026-10-28T15:00:00Z"), newYork)).isTrue()
|
||||
assertThat(call.hasEnded(Instant.parse("2026-10-28T14:59:00Z"), newYork)).isFalse()
|
||||
}
|
||||
}
|
||||
@@ -419,6 +419,30 @@ class ReminderPlanTest {
|
||||
assertThat(schedule.due).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `of several reminders due on one occurrence only the latest is posted`() {
|
||||
val planned = plan(
|
||||
instances = listOf(instance(1L, beginMillis = now + 20 * minute)),
|
||||
minutesByEvent = mapOf(1L to listOf(60, 30)),
|
||||
)
|
||||
|
||||
val schedule = scheduleReminders(
|
||||
planned, lastFiredMillis = now - day, nowMillis = now, horizonMillis = now + day,
|
||||
)
|
||||
|
||||
assertThat(schedule.due.map { it.minutes }).containsExactly(30)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `two reminders on one occurrence share an occurrence key`() {
|
||||
val planned = plan(
|
||||
instances = listOf(instance(1L)),
|
||||
minutesByEvent = mapOf(1L to listOf(10, 30)),
|
||||
)
|
||||
|
||||
assertThat(planned[0].occurrenceKey).isEqualTo(planned[1].occurrenceKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `due reminders come out in occurrence order`() {
|
||||
val planned = plan(
|
||||
|
||||
@@ -65,4 +65,14 @@ class AgendaTimeLabelTest {
|
||||
assertThat(labelOn(2026, 7, 1, e)).isEqualTo(AgendaTimeLabel.AllDay)
|
||||
assertThat(labelOn(2026, 7, 2, e)).isEqualTo(AgendaTimeLabel.Ends(e.end))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed event from midnight to midnight is all-day`() {
|
||||
val oneDay = event(at(2026, 7, 2), at(2026, 7, 3))
|
||||
val twoDays = event(at(2026, 7, 2), at(2026, 7, 4))
|
||||
|
||||
assertThat(labelOn(2026, 7, 2, oneDay)).isEqualTo(AgendaTimeLabel.AllDay)
|
||||
assertThat(labelOn(2026, 7, 2, twoDays)).isEqualTo(AgendaTimeLabel.AllDay)
|
||||
assertThat(labelOn(2026, 7, 3, twoDays)).isEqualTo(AgendaTimeLabel.AllDay)
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,13 @@ class DragPieceBoundsTest {
|
||||
assertThat(bounds.height).isEqualTo(MIN_EVENT_FRACTION * hourPx - insetPx * 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short piece at the end of the day rises as its block does`() {
|
||||
val bounds = dragPieceBounds(slice(startMin = 1438, spanMin = 1), hourPx, insetPx = 0f)
|
||||
assertThat(bounds.top + bounds.height).isWithin(0.01f).of(24 * hourPx)
|
||||
assertThat(bounds.height).isWithin(0.01f).of(MIN_EVENT_FRACTION * hourPx)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an inset taller than the piece leaves no height at all`() {
|
||||
val bounds = dragPieceBounds(slice(startMin = 0, spanMin = 60), hourPx = 4f, insetPx = insetPx)
|
||||
|
||||
@@ -78,6 +78,21 @@ class OutOfViewEdgesTest {
|
||||
assertThat(outOf(blip).above).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short event at midnight is judged by where it rises to`() {
|
||||
// 23:58–23:59 draws from 23:34, so a viewport ending at 23:40 already shows it.
|
||||
val late = block(6, 23 * 60 + 58, 23 * 60 + 59)
|
||||
assertThat(outOfViewEvents(listOf(late), topMin = 1000f, bottomMin = 1420f).below).isNull()
|
||||
val target = revealScrollTarget(late, ViewportEdge.Bottom, hourPx = 60f, viewportPx = 10, marginPx = 0f, maxScroll = 1440)
|
||||
assertThat(target).isEqualTo(1440 - 26)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short event carrying on past midnight is judged by its own start`() {
|
||||
val overnight = block(7, 23 * 60 + 58, 24 * 60).copy(continuesAfter = true)
|
||||
assertThat(outOfViewEvents(listOf(overnight), topMin = 1000f, bottomMin = 1420f).below).isEqualTo(overnight)
|
||||
}
|
||||
|
||||
@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)
|
||||
|
||||
@@ -5,7 +5,9 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.advanceTimeBy
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.math.abs
|
||||
@@ -13,16 +15,10 @@ 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))
|
||||
}
|
||||
private var running = 0
|
||||
|
||||
@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 ->
|
||||
private fun TestScope.trackingCache() =
|
||||
PageStateCache<Int, Int>(backgroundScope, -1, { a, b -> abs(a - b) <= 1 }) { key ->
|
||||
flow {
|
||||
running++
|
||||
try {
|
||||
@@ -33,13 +29,11 @@ class PageStateCacheTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
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 `the same key shares one state`() = runTest {
|
||||
val cache = trackingCache()
|
||||
assertThat(cache.get(5)).isSameInstanceAs(cache.get(5))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,4 +44,63 @@ class PageStateCacheTest {
|
||||
cache.get(6)
|
||||
assertThat(cache.size).isEqualTo(3)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an entry loads only while collected`() = runTest(UnconfinedTestDispatcher()) {
|
||||
val cache = trackingCache()
|
||||
val state = cache.get(0)
|
||||
assertThat(running).isEqualTo(0)
|
||||
|
||||
val page = backgroundScope.launch { state.collect {} }
|
||||
assertThat(running).isEqualTo(1)
|
||||
assertThat(state.value).isEqualTo(0)
|
||||
|
||||
page.cancel()
|
||||
advanceTimeBy(5_001)
|
||||
assertThat(running).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an unwatched entry far away is forgotten`() = runTest(UnconfinedTestDispatcher()) {
|
||||
val cache = trackingCache()
|
||||
cache.get(0)
|
||||
cache.get(10)
|
||||
assertThat(cache.size).isEqualTo(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an entry a page still collects is kept however far away`() = runTest(UnconfinedTestDispatcher()) {
|
||||
val cache = trackingCache()
|
||||
backgroundScope.launch { cache.get(0).collect {} }
|
||||
|
||||
cache.get(10)
|
||||
assertThat(running).isEqualTo(1)
|
||||
assertThat(cache.size).isEqualTo(2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a forgotten entry a page holds still loads once collected`() = runTest(UnconfinedTestDispatcher()) {
|
||||
val cache = trackingCache()
|
||||
// The page took its state but hasn't started collecting when 0 is let go.
|
||||
val held = cache.get(0)
|
||||
cache.get(10)
|
||||
|
||||
val values = mutableListOf<Int>()
|
||||
backgroundScope.launch { held.collect { values += it } }
|
||||
assertThat(running).isEqualTo(1)
|
||||
assertThat(values.last()).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an entry restarts after the screen comes back`() = runTest(UnconfinedTestDispatcher()) {
|
||||
val cache = trackingCache()
|
||||
val held = cache.get(0)
|
||||
backgroundScope.launch { held.collect {} }.cancel()
|
||||
advanceTimeBy(5_001)
|
||||
cache.get(10)
|
||||
assertThat(running).isEqualTo(0)
|
||||
|
||||
backgroundScope.launch { held.collect {} }
|
||||
assertThat(running).isEqualTo(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package de.jeanlucmakiola.calendula.ui.common
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/** A short block near midnight keeps its whole floor rather than running off the day (#483). */
|
||||
class RenderedSpanTest {
|
||||
|
||||
private val floor = MIN_EVENT_FRACTION * 60f
|
||||
|
||||
@Test
|
||||
fun `a long block draws at its own times`() {
|
||||
assertThat(renderedSpan(540, 600, continuesAfter = false)).isEqualTo(RenderedSpan(540f, 600f))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short block in the day is floored downwards`() {
|
||||
val span = renderedSpan(20 * 60 + 58, 20 * 60 + 59, continuesAfter = false)
|
||||
assertThat(span).isEqualTo(RenderedSpan(1258f, 1258f + floor))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short block at the end of the day rises to end at midnight`() {
|
||||
val span = renderedSpan(23 * 60 + 58, 23 * 60 + 59, continuesAfter = false)
|
||||
assertThat(span).isEqualTo(RenderedSpan(1440f - floor, 1440f))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a block ending at midnight rises too`() {
|
||||
val span = renderedSpan(23 * 60 + 59, 1440, continuesAfter = false)
|
||||
assertThat(span).isEqualTo(RenderedSpan(1440f - floor, 1440f))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an instant event at the end of the day rises`() {
|
||||
val span = renderedSpan(1439, 1439, continuesAfter = false)
|
||||
assertThat(span.bottomMin).isEqualTo(1440f)
|
||||
assertThat(span.bottomMin - span.topMin).isEqualTo(floor)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a block that just fits stays put`() {
|
||||
val start = 1440 - 26
|
||||
assertThat(renderedSpan(start, start + 5, continuesAfter = false)).isEqualTo(RenderedSpan(start.toFloat(), 1440f))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a block carrying on past midnight keeps its start`() {
|
||||
val span = renderedSpan(23 * 60 + 58, 1440, continuesAfter = true)
|
||||
assertThat(span.topMin).isEqualTo(1438f)
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import de.jeanlucmakiola.calendula.data.time.FakeZoneSource
|
||||
import de.jeanlucmakiola.calendula.data.calendar.FakeCalendarDataSource
|
||||
import de.jeanlucmakiola.calendula.domain.CalendarSource
|
||||
import de.jeanlucmakiola.calendula.domain.EventDetail
|
||||
import de.jeanlucmakiola.calendula.domain.EventStatus
|
||||
import de.jeanlucmakiola.calendula.domain.RecurringWriteScope
|
||||
import de.jeanlucmakiola.calendula.testDetail
|
||||
import de.jeanlucmakiola.calendula.testEvent
|
||||
@@ -27,6 +28,8 @@ import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.RegisterExtension
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Path
|
||||
import kotlinx.datetime.atStartOfDayIn
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
@@ -63,6 +66,7 @@ class RescheduleViewModelTest {
|
||||
isAllDay: Boolean = false,
|
||||
isException: Boolean = false,
|
||||
anchorMillis: Long = beginMillis,
|
||||
status: EventStatus = EventStatus.Confirmed,
|
||||
): EventDetail = testDetail(
|
||||
instance = testEvent(
|
||||
id = 42L, title = "Standup",
|
||||
@@ -72,6 +76,7 @@ class RescheduleViewModelTest {
|
||||
),
|
||||
rrule = rrule,
|
||||
isException = isException,
|
||||
status = status,
|
||||
)
|
||||
|
||||
private fun viewModel(tempDir: Path, fake: FakeCalendarDataSource): RescheduleViewModel {
|
||||
@@ -671,4 +676,109 @@ class RescheduleViewModelTest {
|
||||
assertThat(vm.scopePrompt.value)
|
||||
.isEqualTo(MoveScopePrompt(occurrenceOnly = true, resize = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a cancelled series moves as a whole without asking`(
|
||||
@TempDir tempDir: Path,
|
||||
) = runTest(dispatcher) {
|
||||
val fake = FakeCalendarDataSource().apply {
|
||||
eventDetailResult = { detail(rrule = "FREQ=WEEKLY", status = EventStatus.Cancelled) }
|
||||
}
|
||||
val vm = viewModel(tempDir, fake)
|
||||
|
||||
vm.move(oneHourLater())
|
||||
advanceUntilIdle()
|
||||
|
||||
assertThat(vm.scopePrompt.value).isNull()
|
||||
assertThat(fake.updatedEvents).hasSize(1)
|
||||
assertThat(fake.updatedOccurrences).isEmpty()
|
||||
assertThat(fake.updatedFromOccurrences).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a cancelled series whose rule cannot be realigned is not moved at all`(
|
||||
@TempDir tempDir: Path,
|
||||
) = runTest(dispatcher) {
|
||||
val fake = FakeCalendarDataSource().apply {
|
||||
eventDetailResult = { detail(rrule = "FREQ=WEEKLY;BYDAY=MO,WE", status = EventStatus.Cancelled) }
|
||||
}
|
||||
val vm = viewModel(tempDir, fake)
|
||||
|
||||
vm.move(toWednesday())
|
||||
advanceUntilIdle()
|
||||
|
||||
assertThat(vm.scopePrompt.value).isNull()
|
||||
assertThat(vm.outcome.value).isEqualTo(MoveOutcome.BlockedCancelledSeries)
|
||||
assertThat(vm.abandoned.value).isEqualTo(1)
|
||||
assertThat(fake.updatedEvents).isEmpty()
|
||||
assertThat(fake.updatedOccurrences).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day event dropped into the time grid becomes timed`(
|
||||
@TempDir tempDir: Path,
|
||||
) = runTest(dispatcher) {
|
||||
val dayStart = monday.atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds()
|
||||
val fake = FakeCalendarDataSource().apply {
|
||||
eventDetailResult = {
|
||||
testDetail(
|
||||
instance = testEvent(
|
||||
id = 42L, title = "Offsite", isAllDay = true,
|
||||
start = Instant.fromEpochMilliseconds(dayStart),
|
||||
end = Instant.fromEpochMilliseconds(dayStart + 86_400_000L),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
val vm = viewModel(tempDir, fake)
|
||||
val start = Instant.fromEpochMilliseconds(beginMillis)
|
||||
|
||||
vm.move(
|
||||
MoveRequest(
|
||||
eventId = 42L,
|
||||
beginMillis = dayStart,
|
||||
endMillis = dayStart + 86_400_000L,
|
||||
target = MoveTarget.Span(start, Instant.fromEpochMilliseconds(endMillis)),
|
||||
),
|
||||
)
|
||||
advanceUntilIdle()
|
||||
|
||||
val updated = fake.updatedEvents.single().third
|
||||
assertThat(updated.isAllDay).isFalse()
|
||||
assertThat(updated.start.dateTime).isEqualTo(LocalDateTime(monday, LocalTime(12, 0)))
|
||||
assertThat(updated.end.dateTime).isEqualTo(LocalDateTime(monday, LocalTime(13, 0)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a recurring all-day event dropped into the grid early on its own day can still move the series`(
|
||||
@TempDir tempDir: Path,
|
||||
) = runTest(dispatcher) {
|
||||
val dayStart = monday.atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds()
|
||||
val fake = FakeCalendarDataSource().apply {
|
||||
eventDetailResult = {
|
||||
testDetail(
|
||||
instance = testEvent(
|
||||
id = 42L, title = "Offsite", isAllDay = true,
|
||||
start = Instant.fromEpochMilliseconds(dayStart),
|
||||
end = Instant.fromEpochMilliseconds(dayStart + 86_400_000L),
|
||||
),
|
||||
rrule = "FREQ=WEEKLY;BYDAY=MO",
|
||||
)
|
||||
}
|
||||
}
|
||||
val vm = viewModel(tempDir, fake)
|
||||
val eight = LocalDateTime(monday, LocalTime(8, 0)).toInstant(TimeZone.currentSystemDefault())
|
||||
|
||||
vm.move(
|
||||
MoveRequest(
|
||||
eventId = 42L,
|
||||
beginMillis = dayStart,
|
||||
endMillis = dayStart + 86_400_000L,
|
||||
target = MoveTarget.Span(eight, eight + 1.hours),
|
||||
),
|
||||
)
|
||||
advanceUntilIdle()
|
||||
|
||||
assertThat(vm.scopePrompt.value).isEqualTo(MoveScopePrompt(occurrenceOnly = false))
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class TimedBlockShapeTest {
|
||||
val block = layoutDay(listOf(ev), day1, zone).single()
|
||||
|
||||
assertThat(block.continuesBefore(day1, zone)).isFalse()
|
||||
assertThat(block.continuesAfter(day1, zone)).isFalse()
|
||||
assertThat(block.continuesAfter).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,11 +46,11 @@ class TimedBlockShapeTest {
|
||||
|
||||
val head = layoutDay(listOf(ev), day1, zone).single()
|
||||
assertThat(head.continuesBefore(day1, zone)).isFalse()
|
||||
assertThat(head.continuesAfter(day1, zone)).isTrue()
|
||||
assertThat(head.continuesAfter).isTrue()
|
||||
|
||||
val tail = layoutDay(listOf(ev), day2, zone).single()
|
||||
assertThat(tail.continuesBefore(day2, zone)).isTrue()
|
||||
assertThat(tail.continuesAfter(day2, zone)).isFalse()
|
||||
assertThat(tail.continuesAfter).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +59,7 @@ class TimedBlockShapeTest {
|
||||
val middle = layoutDay(listOf(ev), day2, zone).single()
|
||||
|
||||
assertThat(middle.continuesBefore(day2, zone)).isTrue()
|
||||
assertThat(middle.continuesAfter(day2, zone)).isTrue()
|
||||
assertThat(middle.continuesAfter).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +67,7 @@ class TimedBlockShapeTest {
|
||||
val ev = event(at(day1, 20), at(day2, 0))
|
||||
val block = layoutDay(listOf(ev), day1, zone).single()
|
||||
|
||||
assertThat(block.continuesAfter(day1, zone)).isFalse()
|
||||
assertThat(block.continuesAfter).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -45,6 +45,14 @@ class TimelineHoursTest {
|
||||
.isEqualTo(280)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the clearance under midnight is not counted as day`() {
|
||||
// 40px an hour plus 100px of clearance over a 600px viewport: 460px of scroll.
|
||||
assertThat(
|
||||
startHourScroll(maxValue = 460, viewportPx = 600, startHour = 7, hourPx = 40f, clearancePx = 100),
|
||||
).isEqualTo(280)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a layout still at the previous scale is waited out`() {
|
||||
// Still 56px an hour: 1344 - 600 = 744 of scroll.
|
||||
|
||||
@@ -40,6 +40,19 @@ class TimelineScaleTest {
|
||||
assertThat(h * 24).isGreaterThan(phoneViewport * 0.9f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fit-day leaves the FAB clearance under midnight`() {
|
||||
val viewport = 800.dp
|
||||
val h = TimelineScale.FitDay.hourHeight(dayFitHeight(viewport))
|
||||
assertThat(h * 24 + FabClearance).isAtMost(viewport)
|
||||
assertThat(h * 24 + FabClearance).isGreaterThan(viewport * 0.99f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the fitted height never goes negative`() {
|
||||
assertThat(dayFitHeight(40.dp)).isEqualTo(0.dp)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fit-day clamps instead of shrinking hours past legibility`() {
|
||||
// A very short viewport (split screen, tiny device) would otherwise give
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.jeanlucmakiola.calendula.ui.month
|
||||
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.testEvent
|
||||
import de.jeanlucmakiola.calendula.ui.common.startOfWeek
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.datetime.DateTimeUnit
|
||||
@@ -10,6 +12,7 @@ import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.YearMonth
|
||||
import kotlinx.datetime.minus
|
||||
import kotlinx.datetime.plus
|
||||
import kotlinx.datetime.yearMonth
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
@@ -34,22 +37,22 @@ class ContinuousMonthIndexTest {
|
||||
@Test
|
||||
fun `index round-trips back to its month`() {
|
||||
listOf(
|
||||
YearMonth(1900, Month.JANUARY),
|
||||
YearMonth(1600, Month.JANUARY),
|
||||
jun26,
|
||||
YearMonth(2026, Month.DECEMBER),
|
||||
YearMonth(2100, Month.DECEMBER),
|
||||
YearMonth(2399, Month.DECEMBER),
|
||||
).forEach { ym ->
|
||||
assertThat(yearMonthForIndex(monthIndexOf(ym))).isEqualTo(ym)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `indices are non-negative and span 1900 through 2100`() {
|
||||
assertThat(monthIndexOf(YearMonth(1900, Month.JANUARY))).isEqualTo(0)
|
||||
fun `indices are non-negative and span 1600 through 2399`() {
|
||||
assertThat(monthIndexOf(YearMonth(1600, Month.JANUARY))).isEqualTo(0)
|
||||
assertThat(monthIndexOf(jun26)).isGreaterThan(0)
|
||||
assertThat(monthIndexOf(YearMonth(2100, Month.DECEMBER)))
|
||||
assertThat(monthIndexOf(YearMonth(2399, Month.DECEMBER)))
|
||||
.isEqualTo(continuousMonthCount() - 1)
|
||||
assertThat(continuousMonthCount()).isEqualTo(201 * 12)
|
||||
assertThat(continuousMonthCount()).isEqualTo(800 * 12)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,9 +157,9 @@ class ContinuousMonthIndexTest {
|
||||
DayOfWeek.entries.forEach { ws ->
|
||||
val index = weekIndexOf(wed, ws)
|
||||
assertThat(weekStartForIndex(index, ws)).isEqualTo(wed.startOfWeek(ws))
|
||||
assertThat(weekIndexOf(LocalDate(1900, 1, 1), ws)).isAtLeast(0)
|
||||
assertThat(weekIndexOf(LocalDate(1600, 1, 1), ws)).isAtLeast(0)
|
||||
assertThat(index).isLessThan(continuousWeekCount(ws))
|
||||
assertThat(weekIndexOf(LocalDate(2100, 12, 31), ws))
|
||||
assertThat(weekIndexOf(LocalDate(2399, 12, 31), ws))
|
||||
.isLessThan(continuousWeekCount(ws))
|
||||
}
|
||||
}
|
||||
@@ -236,4 +239,68 @@ class ContinuousMonthIndexTest {
|
||||
assertThat(agendaStartForMonth(YearMonth(2025, Month.JUNE), today))
|
||||
.isEqualTo(LocalDate(2025, 6, 1))
|
||||
}
|
||||
|
||||
private fun days(month: YearMonth, today: LocalDate, byDay: Map<LocalDate, List<EventInstance>>, showToday: Boolean = true) =
|
||||
splitAgendaDays(month, today, byDay, showToday).map { it.date }
|
||||
|
||||
@Test
|
||||
fun `the split agenda skips a free first day of another month`() {
|
||||
val today = LocalDate(2026, 6, 10)
|
||||
val byDay = mapOf(
|
||||
LocalDate(2026, 7, 1) to emptyList(),
|
||||
LocalDate(2026, 7, 3) to listOf(testEvent()),
|
||||
)
|
||||
assertThat(days(YearMonth(2026, Month.JULY), today, byDay)).containsExactly(LocalDate(2026, 7, 3))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the split agenda keeps a free today`() {
|
||||
val today = LocalDate(2026, 6, 10)
|
||||
val byDay = mapOf(LocalDate(2026, 6, 12) to listOf(testEvent()))
|
||||
assertThat(days(jun26, today, byDay)).containsExactly(today, LocalDate(2026, 6, 12)).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the split agenda drops a free today when the agenda would`() {
|
||||
val today = LocalDate(2026, 6, 10)
|
||||
val byDay = mapOf(LocalDate(2026, 6, 12) to listOf(testEvent()))
|
||||
assertThat(days(jun26, today, byDay, showToday = false)).containsExactly(LocalDate(2026, 6, 12))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the split agenda leaves out past days and the grid's other months`() {
|
||||
val today = LocalDate(2026, 6, 10)
|
||||
val byDay = mapOf(
|
||||
LocalDate(2026, 5, 31) to listOf(testEvent()),
|
||||
LocalDate(2026, 6, 9) to listOf(testEvent()),
|
||||
LocalDate(2026, 6, 10) to listOf(testEvent()),
|
||||
LocalDate(2026, 7, 1) to listOf(testEvent()),
|
||||
)
|
||||
assertThat(days(jun26, today, byDay)).containsExactly(today)
|
||||
assertThat(days(YearMonth(2026, Month.JULY), today, byDay)).containsExactly(LocalDate(2026, 7, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an empty month lists no days`() {
|
||||
assertThat(days(YearMonth(2026, Month.JULY), LocalDate(2026, 6, 10), emptyMap())).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a date before 1600 is held at the first day of the grid`() {
|
||||
val held = coerceToMonthRange(LocalDate(1599, 12, 31))
|
||||
assertThat(held).isEqualTo(LocalDate(1600, 1, 1))
|
||||
assertThat(monthIndexOf(held.yearMonth)).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a date after 2399 is held at the last day of the grid`() {
|
||||
val held = coerceToMonthRange(LocalDate(2400, 1, 1))
|
||||
assertThat(held).isEqualTo(LocalDate(2399, 12, 31))
|
||||
assertThat(monthIndexOf(held.yearMonth)).isEqualTo(continuousMonthCount() - 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a date inside the span is left alone`() {
|
||||
assertThat(coerceToMonthRange(LocalDate(2026, 6, 10))).isEqualTo(LocalDate(2026, 6, 10))
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,40 @@ class MonthChipTimeTest {
|
||||
val time = monthChipTime(timed(9, 5), continuesLeft = true, zone, is24Hour = true, locale)
|
||||
assertThat(time).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `switched off, no chip shows a time however wide`() {
|
||||
assertThat(monthChipShowsTime(enabled = false, availableWidth = 1000f, labelWidth = 10f)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the time shows only while the label fits beside it`() {
|
||||
assertThat(monthChipShowsTime(enabled = true, availableWidth = 80f, labelWidth = 80f)).isTrue()
|
||||
assertThat(monthChipShowsTime(enabled = true, availableWidth = 79f, labelWidth = 80f)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short title has to fit whole`() {
|
||||
assertThat(monthTitleToKeep("Lunch")).isEqualTo("Lunch")
|
||||
assertThat(monthTitleToKeep("Appointments")).isEqualTo("Appointments")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a long title only has to keep its first twelve characters`() {
|
||||
assertThat(monthTitleToKeep("Quarterly planning review")).isEqualTo("Quarterly pl")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an emoji at the cut is kept whole`() {
|
||||
val title = "Birthday 🎂 party at home"
|
||||
val kept = monthTitleToKeep(title)
|
||||
assertThat(kept).isEqualTo("Birthday 🎂 p")
|
||||
assertThat(Character.isHighSurrogate(kept.last())).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an emoji as the twelfth character is not split`() {
|
||||
val kept = monthTitleToKeep("Team dinner🍕 tonight")
|
||||
assertThat(kept).isEqualTo("Team dinner🍕")
|
||||
}
|
||||
}
|
||||
@@ -321,4 +321,18 @@ class MonthLayoutTest {
|
||||
private fun declinedTimed(date: LocalDate) =
|
||||
timed(date, 7, 8, id = 4L, title = "Declined early")
|
||||
.copy(response = EventResponse.Declined)
|
||||
|
||||
@Test
|
||||
fun `a timed event from midnight to midnight is a bar, not a timed chip`() {
|
||||
val ev = timedEvent(
|
||||
LocalDate(2026, 6, 10), 0, 0, zone = zone, id = 3L,
|
||||
endDate = LocalDate(2026, 6, 11),
|
||||
)
|
||||
val week = layoutCalendarWeek(weekOf8th, listOf(ev), zone)
|
||||
|
||||
assertThat(week.spans.map { it.event }).containsExactly(ev)
|
||||
assertThat(week.spans.single().startCol).isEqualTo(2)
|
||||
assertThat(week.spans.single().endCol).isEqualTo(2)
|
||||
assertThat(week.timedByDay.values.flatten()).isEmpty()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package de.jeanlucmakiola.calendula.ui.month
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.MainDispatcherExtension
|
||||
import de.jeanlucmakiola.calendula.data.calendar.FakeCalendarDataSource
|
||||
import de.jeanlucmakiola.calendula.data.time.TodaySource
|
||||
import de.jeanlucmakiola.calendula.testPrefs
|
||||
import de.jeanlucmakiola.calendula.testRepository
|
||||
import de.jeanlucmakiola.calendula.testSettings
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.Month
|
||||
import kotlinx.datetime.YearMonth
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.RegisterExtension
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Path
|
||||
|
||||
/** The month view never leaves the span its pager can show (#457). */
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class MonthViewModelRangeTest {
|
||||
|
||||
@JvmField @RegisterExtension
|
||||
val mainDispatcher = MainDispatcherExtension()
|
||||
private val dispatcher = mainDispatcher.dispatcher
|
||||
|
||||
private fun viewModel(tempDir: Path): MonthViewModel {
|
||||
val settings = testSettings(tempDir, CoroutineScope(dispatcher))
|
||||
val repo = testRepository(
|
||||
FakeCalendarDataSource(), tempDir, dispatcher,
|
||||
prefs = testPrefs(tempDir, CoroutineScope(dispatcher)),
|
||||
settings = settings,
|
||||
)
|
||||
val today = object : TodaySource {
|
||||
override val today = flowOf(LocalDate(2026, 11, 2))
|
||||
}
|
||||
return MonthViewModel(repo, settings, today, dispatcher)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a focus before 1600 opens the first month`(@TempDir tempDir: Path) = runTest(dispatcher) {
|
||||
val vm = viewModel(tempDir)
|
||||
vm.goToDate(LocalDate(1599, 12, 31))
|
||||
assertThat(vm.month.value).isEqualTo(YearMonth(1600, Month.JANUARY))
|
||||
assertThat(vm.selectedDate.value).isEqualTo(LocalDate(1600, 1, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a focus after 2399 opens the last month`(@TempDir tempDir: Path) = runTest(dispatcher) {
|
||||
val vm = viewModel(tempDir)
|
||||
vm.goToDate(LocalDate(2400, 1, 1))
|
||||
assertThat(vm.month.value).isEqualTo(YearMonth(2399, Month.DECEMBER))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a tap on a day past the span is ignored`(@TempDir tempDir: Path) = runTest(dispatcher) {
|
||||
val vm = viewModel(tempDir)
|
||||
vm.goToDate(LocalDate(1600, 1, 1))
|
||||
vm.selectDate(LocalDate(1599, 12, 31))
|
||||
assertThat(vm.month.value).isEqualTo(YearMonth(1600, Month.JANUARY))
|
||||
assertThat(vm.selectedDate.value).isEqualTo(LocalDate(1600, 1, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the split pane stops at the first month`(@TempDir tempDir: Path) = runTest(dispatcher) {
|
||||
val vm = viewModel(tempDir)
|
||||
vm.goToDate(LocalDate(1600, 1, 15))
|
||||
vm.clearSelection()
|
||||
vm.stepSplitPane(-1)
|
||||
assertThat(vm.month.value).isEqualTo(YearMonth(1600, Month.JANUARY))
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,9 @@ import kotlinx.datetime.plus
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* Pins each grid's page numbering to the formulas it shipped with: a pager
|
||||
* restores its page by number, so a change here moves the user to another date.
|
||||
* Pins each grid's page numbering: a pager restores its page by number, so a
|
||||
* change here moves the user to another date. Page 0 holds the first day of
|
||||
* the shared span, and the last page holds its last day (#457).
|
||||
*/
|
||||
class PageNumberingTest {
|
||||
|
||||
@@ -26,6 +27,7 @@ class PageNumberingTest {
|
||||
add(e)
|
||||
e = e.plus(1, DateTimeUnit.DAY)
|
||||
}
|
||||
addAll(listOf(FIRST, FIRST.minus(1, DateTimeUnit.DAY), LAST, LAST.plus(1, DateTimeUnit.DAY)))
|
||||
}
|
||||
|
||||
private fun pages(count: Int): List<Int> =
|
||||
@@ -36,13 +38,14 @@ class PageNumberingTest {
|
||||
fun `week pages keep their numbering for every first day`() {
|
||||
DayOfWeek.entries.forEach { firstDay ->
|
||||
val grid = DaysGrid.weeks(firstDay)
|
||||
val phase = DAYS_EPOCH.daysUntil(WEEK_EPOCH.weekStart(firstDay))
|
||||
assertThat(grid.dayCount).isEqualTo(7)
|
||||
assertThat(grid.pageCount).isEqualTo(LEGACY_WEEK_COUNT)
|
||||
pages(LEGACY_WEEK_COUNT).forEach { page ->
|
||||
assertThat(grid.startForPage(page)).isEqualTo(legacyWeekStart(page, firstDay))
|
||||
assertThat(grid.pageCount).isEqualTo(expectedCount(7, phase))
|
||||
pages(grid.pageCount).forEach { page ->
|
||||
assertThat(grid.startForPage(page)).isEqualTo(expectedStart(page, 7, phase))
|
||||
}
|
||||
dates.forEach { date ->
|
||||
assertThat(grid.pageFor(date)).isEqualTo(legacyWeekPage(date, firstDay))
|
||||
assertThat(grid.pageFor(date)).isEqualTo(expectedPage(date, 7, phase))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,12 +55,12 @@ class PageNumberingTest {
|
||||
(1..7).forEach { count ->
|
||||
(-count..count * 2).forEach { phase ->
|
||||
val grid = DaysGrid(count, phase)
|
||||
assertThat(grid.pageCount).isEqualTo(LEGACY_DAYS_COUNT)
|
||||
pages(LEGACY_DAYS_COUNT).forEach { page ->
|
||||
assertThat(grid.startForPage(page)).isEqualTo(legacyDaysStart(page, count, phase))
|
||||
assertThat(grid.pageCount).isEqualTo(expectedCount(count, phase))
|
||||
pages(grid.pageCount).forEach { page ->
|
||||
assertThat(grid.startForPage(page)).isEqualTo(expectedStart(page, count, phase))
|
||||
}
|
||||
dates.forEach { date ->
|
||||
assertThat(grid.pageFor(date)).isEqualTo(legacyDaysPage(date, count, phase))
|
||||
assertThat(grid.pageFor(date)).isEqualTo(expectedPage(date, count, phase))
|
||||
}
|
||||
}
|
||||
dates.filter { it.year in 1950..2050 }.forEach { date ->
|
||||
@@ -71,12 +74,21 @@ class PageNumberingTest {
|
||||
fun `day pages keep their numbering`() {
|
||||
val grid = DaysGrid.days
|
||||
assertThat(grid.dayCount).isEqualTo(1)
|
||||
assertThat(grid.pageCount).isEqualTo(LEGACY_DAY_COUNT)
|
||||
pages(LEGACY_DAY_COUNT).forEach { page ->
|
||||
assertThat(grid.startForPage(page)).isEqualTo(legacyDayStart(page))
|
||||
assertThat(grid.pageCount).isEqualTo(FIRST.daysUntil(LAST) + 1)
|
||||
pages(grid.pageCount).forEach { page ->
|
||||
assertThat(grid.startForPage(page)).isEqualTo(FIRST.plus(page, DateTimeUnit.DAY))
|
||||
}
|
||||
dates.forEach { date ->
|
||||
assertThat(grid.pageFor(date)).isEqualTo(legacyDayPage(date))
|
||||
assertThat(grid.pageFor(date)).isEqualTo(FIRST.daysUntil(date).coerceIn(0, grid.pageCount - 1))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `every grid reaches both ends of the span`() {
|
||||
(DayOfWeek.entries.map { DaysGrid.weeks(it) } + DaysGrid.days + (1..7).map { DaysGrid(it, 0) }).forEach { grid ->
|
||||
assertThat(grid.startForPage(grid.pageFor(FIRST))).isAtMost(FIRST)
|
||||
val lastStart = grid.startForPage(grid.pageFor(LAST))
|
||||
assertThat(lastStart.plus(grid.dayCount - 1, DateTimeUnit.DAY)).isAtLeast(LAST)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,34 +116,28 @@ class PageNumberingTest {
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val LEGACY_WEEK_COUNT = 20_000
|
||||
const val LEGACY_DAYS_COUNT = 40_000
|
||||
const val LEGACY_DAY_COUNT = 140_000
|
||||
val FIRST = LocalDate(1600, 1, 1)
|
||||
val LAST = LocalDate(2399, 12, 31)
|
||||
val WEEK_EPOCH = LocalDate(2000, 1, 3)
|
||||
val DAYS_EPOCH = LocalDate(2000, 1, 1)
|
||||
|
||||
fun LocalDate.weekStart(firstDay: DayOfWeek): LocalDate =
|
||||
minus(((dayOfWeek.ordinal - firstDay.ordinal) + 7) % 7, DateTimeUnit.DAY)
|
||||
|
||||
fun legacyWeekStart(page: Int, firstDay: DayOfWeek): LocalDate =
|
||||
WEEK_EPOCH.weekStart(firstDay).plus((page - LEGACY_WEEK_COUNT / 2) * 7, DateTimeUnit.DAY)
|
||||
|
||||
fun legacyWeekPage(date: LocalDate, firstDay: DayOfWeek): Int {
|
||||
val days = WEEK_EPOCH.weekStart(firstDay).daysUntil(date.weekStart(firstDay))
|
||||
return (LEGACY_WEEK_COUNT / 2 + days / 7).coerceIn(0, LEGACY_WEEK_COUNT - 1)
|
||||
/** Page 0 starts on the page boundary at or before [FIRST]. */
|
||||
fun firstStart(count: Int, phase: Int): LocalDate {
|
||||
val origin = DAYS_EPOCH.plus(phase, DateTimeUnit.DAY)
|
||||
return origin.plus(Math.floorDiv(origin.daysUntil(FIRST), count) * count, DateTimeUnit.DAY)
|
||||
}
|
||||
|
||||
fun legacyDaysStart(page: Int, count: Int, phase: Int): LocalDate =
|
||||
DAYS_EPOCH.plus(phase + (page - LEGACY_DAYS_COUNT / 2) * count, DateTimeUnit.DAY)
|
||||
fun expectedStart(page: Int, count: Int, phase: Int): LocalDate =
|
||||
firstStart(count, phase).plus(page * count, DateTimeUnit.DAY)
|
||||
|
||||
fun legacyDaysPage(date: LocalDate, count: Int, phase: Int): Int =
|
||||
(LEGACY_DAYS_COUNT / 2 + Math.floorDiv(DAYS_EPOCH.daysUntil(date) - phase, count))
|
||||
.coerceIn(0, LEGACY_DAYS_COUNT - 1)
|
||||
fun expectedCount(count: Int, phase: Int): Int =
|
||||
Math.floorDiv(firstStart(count, phase).daysUntil(LAST), count) + 1
|
||||
|
||||
fun legacyDayStart(page: Int): LocalDate =
|
||||
DAYS_EPOCH.plus(page - LEGACY_DAY_COUNT / 2, DateTimeUnit.DAY)
|
||||
|
||||
fun legacyDayPage(date: LocalDate): Int =
|
||||
(LEGACY_DAY_COUNT / 2 + DAYS_EPOCH.daysUntil(date)).coerceIn(0, LEGACY_DAY_COUNT - 1)
|
||||
fun expectedPage(date: LocalDate, count: Int, phase: Int): Int =
|
||||
Math.floorDiv(firstStart(count, phase).daysUntil(date), count)
|
||||
.coerceIn(0, expectedCount(count, phase) - 1)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.jeanlucmakiola.calendula.ui.week
|
||||
|
||||
import de.jeanlucmakiola.calendula.ui.common.StripDrag
|
||||
import de.jeanlucmakiola.calendula.ui.common.startOfWeek
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.testEvent
|
||||
import kotlinx.datetime.DateTimeUnit
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
@@ -106,6 +108,42 @@ class WeekLayoutTest {
|
||||
assertThat(blocks.all { it.lane == 0 && it.laneCount == 1 }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `two short entries near midnight sit side by side`() {
|
||||
// Both lift to end at midnight, so on real times alone the later one would hide the earlier (#483).
|
||||
val a = event(at(wed, 23, 40), at(wed, 23, 41), id = 1L)
|
||||
val b = event(at(wed, 23, 55), at(wed, 23, 56), id = 2L)
|
||||
val blocks = layoutDay(listOf(a, b), wed, zone).sortedBy { it.lane }
|
||||
assertThat(blocks.map { it.event.instanceId }).containsExactly(1L, 2L).inOrder()
|
||||
assertThat(blocks.all { it.laneCount == 2 }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short entry lifted into the event before it takes its own lane`() {
|
||||
val a = event(at(wed, 23), at(wed, 23, 45), id = 1L)
|
||||
val b = event(at(wed, 23, 58), at(wed, 23, 59), id = 2L)
|
||||
val blocks = layoutDay(listOf(a, b), wed, zone)
|
||||
assertThat(blocks.map { it.lane }).containsExactly(0, 1)
|
||||
assertThat(blocks.all { it.laneCount == 2 }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a short entry clear of the next one keeps a single lane`() {
|
||||
val a = event(at(wed, 9), at(wed, 9, 10), id = 1L)
|
||||
val b = event(at(wed, 9, 30), at(wed, 10), id = 2L)
|
||||
val blocks = layoutDay(listOf(a, b), wed, zone)
|
||||
assertThat(blocks.all { it.lane == 0 && it.laneCount == 1 }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a block knows whether its event carries on past midnight`() {
|
||||
val overnight = event(at(wed, 23), at(wed.plusDays(1), 1))
|
||||
assertThat(layoutDay(listOf(overnight), wed, zone).single().continuesAfter).isTrue()
|
||||
assertThat(layoutDay(listOf(overnight), wed.plusDays(1), zone).single().continuesAfter).isFalse()
|
||||
val toMidnight = event(at(wed, 23), at(wed.plusDays(1), 0))
|
||||
assertThat(layoutDay(listOf(toMidnight), wed, zone).single().continuesAfter).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `event spanning midnight is clipped to the day`() {
|
||||
// Starts the previous evening, ends 02:00 on wed.
|
||||
@@ -126,9 +164,9 @@ class WeekLayoutTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `all-day events are excluded from the timed layout`() {
|
||||
fun `all-day events are kept out of the timed layout`() {
|
||||
val ev = event(at(wed, 0), at(wed.plusDays(1), 0), allDay = true)
|
||||
assertThat(layoutDay(listOf(ev), wed, zone)).isEmpty()
|
||||
assertThat(listOf(ev).splitWholeDays(zone)).isEqualTo(listOf(ev) to emptyList<EventInstance>())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -300,4 +338,30 @@ class WeekLayoutTest {
|
||||
val second = event(Instant.parse("2026-10-25T01:10:00Z"), Instant.parse("2026-10-25T01:40:00Z"))
|
||||
assertThat(layoutDay(listOf(second), day, brussels).single().endMin).isEqualTo(2 * 60 + 40)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed event from midnight to midnight stays out of the time grid`() {
|
||||
val ev = testEvent(start = at(wed, 0), end = at(wed.plus(1, DateTimeUnit.DAY), 0))
|
||||
|
||||
assertThat(listOf(ev).splitWholeDays(zone)).isEqualTo(listOf(ev) to emptyList<EventInstance>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a bar held over another day makes room there`() {
|
||||
val held = event(at(mon, 0), at(mon.plusDays(1), 0), allDay = true, id = 1, title = "A")
|
||||
val there = event(at(wed, 0), at(wed.plusDays(1), 0), allDay = true, id = 2, title = "B")
|
||||
val state = WeekUiState.Success(
|
||||
weekStart = mon, today = mon, days = weekDays,
|
||||
allDaySpans = layoutAllDay(listOf(held, there), weekDays, zone), timedByDay = emptyMap(),
|
||||
)
|
||||
assertThat(state.allDaySpans.map { it.lane }).containsExactly(0, 0)
|
||||
|
||||
val preview = state.withStripPreview(StripDrag(held, dayShift = 2), zone).allDaySpans
|
||||
val moved = preview.single { it.event.instanceId == held.instanceId }
|
||||
|
||||
assertThat(moved.event).isEqualTo(held)
|
||||
assertThat(moved.startCol).isEqualTo(2)
|
||||
assertThat(preview.map { it.lane }).containsExactly(0, 1)
|
||||
assertThat(state.withStripPreview(StripDrag(held, dayShift = 2, overGrid = true), zone)).isSameInstanceAs(state)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package de.jeanlucmakiola.calendula.widget
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class MonthWindowCenterTest {
|
||||
|
||||
@Test
|
||||
fun `the loaded window always reaches two months past the shown one`() {
|
||||
for (index in -40..40) {
|
||||
val center = monthWindowCenter(index)
|
||||
assertThat(index - 2).isAtLeast(center - MONTH_WIDGET_PAD_MONTHS)
|
||||
assertThat(index + 2).isAtMost(center + MONTH_WIDGET_PAD_MONTHS)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `paging within a step of three keeps the same window`() {
|
||||
val year = 2026 * 12
|
||||
assertThat(monthWindowCenter(year)).isEqualTo(monthWindowCenter(year + 2))
|
||||
assertThat(monthWindowCenter(year + 3)).isNotEqualTo(monthWindowCenter(year + 2))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.jeanlucmakiola.calendula.widget
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.LocalDate
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class WeekOfTest {
|
||||
|
||||
@Test
|
||||
fun `the week starts on the configured day and holds today`() {
|
||||
val wednesday = LocalDate(2026, 10, 21)
|
||||
assertThat(weekOf(wednesday, DayOfWeek.MONDAY)).isEqualTo(LocalDate(2026, 10, 19)..LocalDate(2026, 10, 25))
|
||||
assertThat(weekOf(wednesday, DayOfWeek.SUNDAY)).isEqualTo(LocalDate(2026, 10, 18)..LocalDate(2026, 10, 24))
|
||||
assertThat(weekOf(wednesday, DayOfWeek.WEDNESDAY).start).isEqualTo(wednesday)
|
||||
assertThat(weekOf(wednesday, DayOfWeek.THURSDAY).start).isEqualTo(LocalDate(2026, 10, 15))
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
package de.jeanlucmakiola.calendula.widget
|
||||
|
||||
import android.content.Intent
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.atStartOfDayIn
|
||||
import kotlinx.datetime.toInstant
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* The rollover alarm is what makes the widgets stop highlighting yesterday
|
||||
* (#228), so the "when is the next local midnight" arithmetic is the one piece
|
||||
* worth pinning down — especially where midnight is not 00:00.
|
||||
*/
|
||||
class WidgetRolloverSchedulerTest {
|
||||
|
||||
private val berlin = TimeZone.of("Europe/Berlin")
|
||||
|
||||
private fun at(local: String, zone: TimeZone): Instant =
|
||||
LocalDateTime.parse(local).toInstant(zone)
|
||||
|
||||
private fun nextRollover(local: String, zone: TimeZone = berlin): Instant =
|
||||
WidgetRolloverScheduler.nextRolloverAt(at(local, zone), zone)
|
||||
|
||||
// --- the ordinary day ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun `midday rolls over at the coming midnight`() {
|
||||
val next = nextRollover("2026-08-27T12:00:00")
|
||||
assertThat(next).isEqualTo(at("2026-08-28T00:00:05", berlin))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a second before midnight still targets tonight, not tomorrow night`() {
|
||||
val next = nextRollover("2026-08-27T23:59:59")
|
||||
assertThat(next).isEqualTo(at("2026-08-28T00:00:05", berlin))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `at midnight exactly the target is the next day, never the current instant`() {
|
||||
// Re-arming after a firing must move a whole day on, or the widget wakes
|
||||
// itself in a tight loop.
|
||||
val now = at("2026-08-28T00:00:00", berlin)
|
||||
val next = WidgetRolloverScheduler.nextRolloverAt(now, berlin)
|
||||
assertThat(next).isEqualTo(at("2026-08-29T00:00:05", berlin))
|
||||
assertThat(next - now).isGreaterThan(Duration.ZERO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `re-arming from the slack instant itself moves a full day on`() {
|
||||
// What actually happens in practice: the receiver runs at midnight + slack.
|
||||
val now = at("2026-08-28T00:00:05", berlin)
|
||||
assertThat(WidgetRolloverScheduler.nextRolloverAt(now, berlin))
|
||||
.isEqualTo(at("2026-08-29T00:00:05", berlin))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the result is always in the future for every minute of a day`() {
|
||||
val zone = berlin
|
||||
// Spans Berlin's 2024 spring-forward: the likeliest source of a target
|
||||
// in the past, i.e. an alarm that fires immediately, forever.
|
||||
var probe = LocalDateTime.parse("2024-03-29T00:00:00").toInstant(zone)
|
||||
val end = LocalDateTime.parse("2024-04-01T00:00:00").toInstant(zone)
|
||||
while (probe < end) {
|
||||
assertThat(WidgetRolloverScheduler.nextRolloverAt(probe, zone)).isGreaterThan(probe)
|
||||
probe += 1.minutes
|
||||
}
|
||||
}
|
||||
|
||||
// --- daylight saving -----------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun `spring forward keeps the rollover one day away, not one hour short`() {
|
||||
// Berlin skipped 02:00-03:00 on 31 March 2024, so that day was 23h long.
|
||||
// A rollover computed as "now + 24h" would land at 01:00 on 1 April.
|
||||
val now = at("2024-03-30T12:00:00", berlin)
|
||||
val next = WidgetRolloverScheduler.nextRolloverAt(now, berlin)
|
||||
assertThat(next).isEqualTo(at("2024-03-31T00:00:05", berlin))
|
||||
assertThat(next - now).isLessThan(24.hours)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fall back does not overshoot into the repeated hour`() {
|
||||
// Berlin repeated 02:00-03:00 on 27 October 2024: a 25h day, so
|
||||
// "now + 24h" would land at 23:00 on the 26th and never roll over.
|
||||
val now = at("2024-10-26T12:00:00", berlin)
|
||||
val next = WidgetRolloverScheduler.nextRolloverAt(now, berlin)
|
||||
assertThat(next).isEqualTo(at("2024-10-27T00:00:05", berlin))
|
||||
assertThat(next.toLocalDateTime(berlin).date).isEqualTo(LocalDate.parse("2024-10-27"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a zone that repeats midnight takes the first start of day`() {
|
||||
// Sao Paulo used to end DST by moving 00:00 back to 23:00, so the day
|
||||
// began twice. Pinned as the accepted trade: the widget runs an hour
|
||||
// ahead until the next redraw. No live zone does this since 2019.
|
||||
val saoPaulo = TimeZone.of("America/Sao_Paulo")
|
||||
val next = WidgetRolloverScheduler.nextRolloverAt(
|
||||
at("2018-02-16T12:00:00", saoPaulo), saoPaulo,
|
||||
)
|
||||
val local = next.toLocalDateTime(saoPaulo)
|
||||
assertThat(local.date).isEqualTo(LocalDate.parse("2018-02-17"))
|
||||
assertThat(local.hour).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a zone where midnight does not exist rolls over at the real start of day`() {
|
||||
// Cuba starts DST at 00:00, so 11 March 2018 began at 01:00 in Havana.
|
||||
// Targeting a literal 00:00 there would arm an instant on the wrong day.
|
||||
val havana = TimeZone.of("America/Havana")
|
||||
val next = WidgetRolloverScheduler.nextRolloverAt(at("2018-03-10T12:00:00", havana), havana)
|
||||
val local = next.toLocalDateTime(havana)
|
||||
assertThat(local.date).isEqualTo(LocalDate.parse("2018-03-11"))
|
||||
assertThat(local.hour).isEqualTo(1)
|
||||
assertThat(local.minute).isEqualTo(0)
|
||||
// And it is genuinely the first instant of that date, not a guess.
|
||||
assertThat(next).isEqualTo(
|
||||
LocalDate.parse("2018-03-11").atStartOfDayIn(havana) +
|
||||
WidgetRolloverScheduler.ROLLOVER_SLACK,
|
||||
)
|
||||
}
|
||||
|
||||
// --- timezone changes ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun `the same instant rolls over at different times in different zones`() {
|
||||
// TIMEZONE_CHANGED must re-arm to the new local midnight: the arithmetic
|
||||
// follows the zone, not a cached offset.
|
||||
val instant = at("2026-08-27T12:00:00", berlin)
|
||||
val tokyo = TimeZone.of("Asia/Tokyo")
|
||||
val berlinNext = WidgetRolloverScheduler.nextRolloverAt(instant, berlin)
|
||||
val tokyoNext = WidgetRolloverScheduler.nextRolloverAt(instant, tokyo)
|
||||
assertThat(tokyoNext).isNotEqualTo(berlinNext)
|
||||
assertThat(tokyoNext).isLessThan(berlinNext)
|
||||
assertThat(tokyoNext.toLocalDateTime(tokyo).hour).isEqualTo(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a half-hour offset zone still lands on its own midnight`() {
|
||||
val kathmandu = TimeZone.of("Asia/Kathmandu")
|
||||
val next = WidgetRolloverScheduler.nextRolloverAt(
|
||||
at("2026-08-27T12:00:00", kathmandu), kathmandu,
|
||||
)
|
||||
val local = next.toLocalDateTime(kathmandu)
|
||||
assertThat(local.date.toString()).isEqualTo("2026-08-28")
|
||||
assertThat(local.hour).isEqualTo(0)
|
||||
}
|
||||
|
||||
// --- the wiring ----------------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun `the receiver actually handles the action the alarm is sent with`() {
|
||||
// The single point where the whole fix would die silently: the alarm
|
||||
// fires, the receiver drops it on the action guard, nothing redraws.
|
||||
assertThat(WidgetUpdateReceiver.HANDLED_ACTIONS)
|
||||
.contains(WidgetUpdateReceiver.ACTION_ROLLOVER)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a data change is handled, and re-arms only on the throttle`() {
|
||||
// PROVIDER_CHANGED fires on every calendar write — each event of a bulk
|
||||
// import, each drop of a drag — so it is not an unconditional re-arm.
|
||||
// It is not dropped either: the alarm is inexact and the system may lose
|
||||
// it, and this is the only signal that keeps arriving to notice.
|
||||
assertThat(WidgetUpdateReceiver.HANDLED_ACTIONS)
|
||||
.containsAtLeast(Intent.ACTION_PROVIDER_CHANGED, Intent.ACTION_DATE_CHANGED)
|
||||
assertThat(WidgetUpdateReceiver.REARM_ACTIONS)
|
||||
.doesNotContain(Intent.ACTION_PROVIDER_CHANGED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `everything that loses the alarm re-arms it`() {
|
||||
assertThat(WidgetUpdateReceiver.REARM_ACTIONS).containsAtLeast(
|
||||
WidgetUpdateReceiver.ACTION_ROLLOVER,
|
||||
Intent.ACTION_BOOT_COMPLETED,
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||
Intent.ACTION_TIME_CHANGED,
|
||||
Intent.ACTION_TIMEZONE_CHANGED,
|
||||
Intent.ACTION_DATE_CHANGED,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -15,25 +15,12 @@ class AgendaScaleTest {
|
||||
// SMALL is the default, so if this fails an agenda widget whose owner never
|
||||
// touched the size setting no longer looks as it did (#51).
|
||||
val m = metricsFor(WidgetSize.SMALL)
|
||||
assertThat(m.title).isEqualTo(16.sp)
|
||||
assertThat(m.dayHeader).isEqualTo(13.sp)
|
||||
assertThat(m.eventTitle).isEqualTo(14.sp)
|
||||
assertThat(m.eventTime).isEqualTo(12.sp)
|
||||
assertThat(m.placeholder).isEqualTo(14.sp)
|
||||
assertThat(m.message).isEqualTo(14.sp)
|
||||
assertThat(m.stripeH).isEqualTo(36.dp)
|
||||
assertThat(m.iconImage).isEqualTo(22.dp)
|
||||
assertThat(m.iconBox).isEqualTo(40.dp)
|
||||
assertThat(m.contentH).isEqualTo(36.dp)
|
||||
assertThat(m.rowVPad).isEqualTo(4.dp)
|
||||
assertThat(m.dayHeaderTopPad).isEqualTo(10.dp)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the derived text indent matches the original hardcoded inset`() {
|
||||
// TEXT_INDENT replaced a hardcoded 19dp; it must still resolve to 19dp or
|
||||
// day headers and the placeholder line stop aligning with event titles.
|
||||
assertThat(TEXT_INDENT).isEqualTo(19.dp)
|
||||
assertThat(TEXT_INDENT).isEqualTo(ROW_H_PAD + STRIPE_WIDTH + STRIPE_GAP)
|
||||
}
|
||||
|
||||
// --- the ramp ------------------------------------------------------------
|
||||
@@ -43,17 +30,17 @@ class AgendaScaleTest {
|
||||
val steps = WidgetSize.entries.map(::metricsFor)
|
||||
|
||||
steps.zipWithNext { small, big ->
|
||||
assertThat(big.title.value).isAtLeast(small.title.value)
|
||||
assertThat(big.dayHeader.value).isAtLeast(small.dayHeader.value)
|
||||
assertThat(big.pillWeekday.value).isAtLeast(small.pillWeekday.value)
|
||||
assertThat(big.pillDay.value).isAtLeast(small.pillDay.value)
|
||||
assertThat(big.eventTitle.value).isAtLeast(small.eventTitle.value)
|
||||
assertThat(big.eventTime.value).isAtLeast(small.eventTime.value)
|
||||
assertThat(big.placeholder.value).isAtLeast(small.placeholder.value)
|
||||
assertThat(big.message.value).isAtLeast(small.message.value)
|
||||
assertThat(big.stripeH.value).isAtLeast(small.stripeH.value)
|
||||
assertThat(big.iconImage.value).isAtLeast(small.iconImage.value)
|
||||
assertThat(big.iconBox.value).isAtLeast(small.iconBox.value)
|
||||
assertThat(big.contentH.value).isAtLeast(small.contentH.value)
|
||||
assertThat(big.pillWidth.value).isAtLeast(small.pillWidth.value)
|
||||
assertThat(big.rowVPad.value).isAtLeast(small.rowVPad.value)
|
||||
assertThat(big.dayHeaderTopPad.value).isAtLeast(small.dayHeaderTopPad.value)
|
||||
assertThat(big.dayGap.value).isAtLeast(small.dayGap.value)
|
||||
assertThat(big.monthLabel.value).isAtLeast(small.monthLabel.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,20 +58,28 @@ class AgendaScaleTest {
|
||||
// Guards against a future edit turning "more readable" into "absurd".
|
||||
val base = metricsFor(WidgetSize.SMALL)
|
||||
val top = metricsFor(WidgetSize.EXTRA_LARGE)
|
||||
assertThat(top.title.value / base.title.value).isLessThan(1.5f)
|
||||
assertThat(top.pillDay.value / base.pillDay.value).isLessThan(1.5f)
|
||||
assertThat(top.eventTitle.value / base.eventTitle.value).isLessThan(1.5f)
|
||||
}
|
||||
|
||||
// --- font scale ----------------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun `the stripe tracks the system font scale`() {
|
||||
// The stripe is Dp, the text beside it is sp: without this the two diverge
|
||||
// at large accessibility font settings and the stripe under-runs the row.
|
||||
fun `the row height tracks the system font scale`() {
|
||||
// The row height is Dp, the text in it is sp: without this the two diverge
|
||||
// at large accessibility font settings and the text outgrows the row.
|
||||
val m = metricsFor(WidgetSize.SMALL)
|
||||
assertThat(m.scaledForFont(1f).stripeH).isEqualTo(36.dp)
|
||||
assertThat(m.scaledForFont(1.3f).stripeH.value).isWithin(0.01f).of(46.8f)
|
||||
assertThat(m.scaledForFont(0.85f).stripeH.value).isWithin(0.01f).of(30.6f)
|
||||
assertThat(m.scaledForFont(1f).contentH).isEqualTo(36.dp)
|
||||
assertThat(m.scaledForFont(1.3f).contentH.value).isWithin(0.01f).of(46.8f)
|
||||
assertThat(m.scaledForFont(0.85f).contentH.value).isWithin(0.01f).of(30.6f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the date pill widens with the system font scale`() {
|
||||
// The pill's text is sp; a fixed-width pill clips "Wed" / "23" at large font settings.
|
||||
val m = metricsFor(WidgetSize.SMALL)
|
||||
assertThat(m.scaledForFont(2f).pillWidth).isEqualTo(m.pillWidth * 2)
|
||||
assertThat(m.scaledForFont(2f).rowHeight).isEqualTo(m.contentH * 2 + m.rowVPad * 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +94,7 @@ class AgendaScaleTest {
|
||||
// double-count it.
|
||||
val m = metricsFor(WidgetSize.MEDIUM)
|
||||
val scaled = m.scaledForFont(1.3f)
|
||||
assertThat(scaled.title).isEqualTo(m.title)
|
||||
assertThat(scaled.pillDay).isEqualTo(m.pillDay)
|
||||
assertThat(scaled.eventTitle).isEqualTo(m.eventTitle)
|
||||
assertThat(scaled.rowVPad).isEqualTo(m.rowVPad)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package de.jeanlucmakiola.calendula.widget.countdown
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.domain.EventResponse
|
||||
import de.jeanlucmakiola.calendula.domain.EventStatus
|
||||
import kotlinx.datetime.TimeZone
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Duration.Companion.days
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import kotlin.time.Instant
|
||||
|
||||
class CountdownTest {
|
||||
|
||||
private val zone = TimeZone.UTC
|
||||
private val now = Instant.parse("2026-10-21T12:00:00Z")
|
||||
|
||||
private fun event(
|
||||
start: Instant,
|
||||
end: Instant = start + 1.hours,
|
||||
id: Long = 1,
|
||||
allDay: Boolean = false,
|
||||
response: EventResponse = EventResponse.Going,
|
||||
status: EventStatus = EventStatus.Confirmed,
|
||||
) = EventInstance(
|
||||
instanceId = id, eventId = id, calendarId = 1, title = "e$id",
|
||||
start = start, end = end, isAllDay = allDay, color = 0, location = null, response = response,
|
||||
status = status,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `the last half hour before the day mark still reads 23 h`() {
|
||||
assertThat(countdownLabel(event(now + 23.hours + 40.minutes), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.HOURS, 23))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `labels step from days to hours to minutes to now`() {
|
||||
assertThat(countdownLabel(event(now + 30.seconds), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.NOW, 0))
|
||||
assertThat(countdownLabel(event(now + 24.minutes + 10.seconds), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.MINUTES, 25))
|
||||
assertThat(countdownLabel(event(now + 2.hours + 40.minutes), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.HOURS, 3))
|
||||
assertThat(countdownLabel(event(now + 1.hours + 10.minutes), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.HOURS, 1))
|
||||
// Tomorrow 23:00 is 35 h away but one calendar day.
|
||||
assertThat(countdownLabel(event(now + 35.hours), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.DAYS, 1))
|
||||
assertThat(countdownLabel(event(now + 12.days), now, zone)).isEqualTo(CountdownLabel(false, CountdownUnit.DAYS, 12))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a running event counts to its end`() {
|
||||
val running = event(start = now - 20.minutes, end = now + 10.minutes)
|
||||
assertThat(countdownLabel(running, now, zone)).isEqualTo(CountdownLabel(true, CountdownUnit.MINUTES, 10))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the next redraw lands where the label changes`() {
|
||||
// "in 25 min" turns into "in 24 min" a minute later.
|
||||
assertThat(nextLabelChange(event(now + 25.minutes), now, zone)).isEqualTo(now + 1.minutes)
|
||||
// "in 3 h" (2 h 40 min) holds until 2 h 30 min are left.
|
||||
assertThat(nextLabelChange(event(now + 2.hours + 40.minutes), now, zone)).isEqualTo(now + 10.minutes)
|
||||
// "in 1 h" holds until the last hour, then counts minutes.
|
||||
assertThat(nextLabelChange(event(now + 1.hours + 10.minutes), now, zone)).isEqualTo(now + 10.minutes)
|
||||
// Days change at midnight.
|
||||
assertThat(nextLabelChange(event(now + 5.days), now, zone)).isEqualTo(Instant.parse("2026-10-22T00:00:00Z"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `next mode skips all-day, declined and finished events`() {
|
||||
val allDay = event(now + 1.hours, id = 1, allDay = true)
|
||||
val declined = event(now + 1.hours, id = 2, response = EventResponse.Declined)
|
||||
val over = event(now - 2.hours, now - 1.hours, id = 3)
|
||||
val later = event(now + 3.hours, id = 4)
|
||||
val running = event(now - 1.hours, now + 2.hours, id = 5)
|
||||
assertThat(pickNextEvent(listOf(allDay, declined, over, later), now, zone)?.eventId).isEqualTo(4)
|
||||
// A running event ending before the next one starts comes first.
|
||||
assertThat(pickNextEvent(listOf(later, running), now, zone)?.eventId).isEqualTo(5)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `next-event mode skips a timed event filling whole days`() {
|
||||
val wholeDay = event(Instant.parse("2026-10-22T00:00:00Z"), Instant.parse("2026-10-23T00:00:00Z"), id = 1)
|
||||
val later = event(now + 30.hours, id = 2)
|
||||
assertThat(pickNextEvent(listOf(wholeDay, later), now, zone)?.eventId).isEqualTo(2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a pinned series follows its next occurrence`() {
|
||||
val past = event(now - 7.days)
|
||||
val next = event(now + 7.days)
|
||||
assertThat(pickPinnedOccurrence(listOf(past, next), now, zone)).isEqualTo(next)
|
||||
assertThat(pickPinnedOccurrence(listOf(past), now, zone)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a pinned series skips cancelled occurrences`() {
|
||||
val cancelled = event(now + 7.days, id = 1, status = EventStatus.Cancelled)
|
||||
val next = event(now + 14.days, id = 2)
|
||||
assertThat(pickPinnedOccurrence(listOf(cancelled, next), now, zone)).isEqualTo(next)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day event counts in local days west of UTC`() {
|
||||
val newYork = TimeZone.of("America/New_York")
|
||||
// 21 Oct, 20:00 in New York; the vacation is all day on the 23rd.
|
||||
val evening = Instant.parse("2026-10-22T00:00:00Z")
|
||||
val vacation = event(Instant.parse("2026-10-23T00:00:00Z"), Instant.parse("2026-10-24T00:00:00Z"), allDay = true)
|
||||
val counted = vacation.counted(newYork)
|
||||
assertThat(counted.start).isEqualTo(Instant.parse("2026-10-23T04:00:00Z"))
|
||||
assertThat(countdownLabel(counted, evening, newYork)).isEqualTo(CountdownLabel(false, CountdownUnit.DAYS, 2))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package de.jeanlucmakiola.calendula.widget.month
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.allDayEvent
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.timedEvent
|
||||
import de.jeanlucmakiola.calendula.ui.month.MonthWeek
|
||||
import de.jeanlucmakiola.calendula.ui.month.layoutMonthWeeks
|
||||
import kotlinx.datetime.DateTimeUnit
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.Month
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.YearMonth
|
||||
import kotlinx.datetime.plus
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/** How the month widget seats a week's events into lanes (#372). */
|
||||
class MonthGridTest {
|
||||
|
||||
private val zone = TimeZone.UTC
|
||||
private val jul26 = YearMonth(2026, Month.JULY)
|
||||
|
||||
/** Monday Jul 6 to Sunday Jul 12. */
|
||||
private val monday = LocalDate(2026, 7, 6)
|
||||
|
||||
private fun weeks(events: List<EventInstance>): List<MonthWeek> =
|
||||
layoutMonthWeeks(jul26, DayOfWeek.MONDAY, events, zone)
|
||||
|
||||
/** July 2026 with [perDay] timed events on every day of the grid. */
|
||||
private fun busyWeeks(perDay: Int): List<MonthWeek> {
|
||||
val first = LocalDate(2026, 6, 29)
|
||||
var id = 0L
|
||||
return weeks(
|
||||
(0 until 42).flatMap { offset ->
|
||||
val day = first.plus(offset, DateTimeUnit.DAY)
|
||||
(1..perDay).map { hour -> timedEvent(day, hour, zone = zone, id = ++id, title = "E$id") }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a week that fits keeps every lane`() {
|
||||
val layouts = fitWeeks(busyWeeks(perDay = 2), lanes = 3)
|
||||
assertThat(layouts.map { it.laneCap }.distinct()).containsExactly(3)
|
||||
assertThat(layouts.all { it.overflow.isEmpty() }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a week that doesn't fit gives its last lane to the overflow`() {
|
||||
val layouts = fitWeeks(busyWeeks(perDay = 5), lanes = 3)
|
||||
assertThat(layouts.map { it.laneCap }.distinct()).containsExactly(2)
|
||||
assertThat(layouts.all { it.overflow.isNotEmpty() }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a taller week fits more lanes`() {
|
||||
assertThat(lanesFitting(19.dp)).isEqualTo(0)
|
||||
assertThat(lanesFitting(50.dp)).isEqualTo(2)
|
||||
assertThat(lanesFitting(100.dp)).isEqualTo(5)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lanes stop at the cap however tall the week`() {
|
||||
assertThat(lanesFitting(1000.dp)).isEqualTo(MAX_LANES)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a week with no room for a lane draws no overflow row either`() {
|
||||
val layouts = fitWeeks(busyWeeks(perDay = 5), lanes = 0)
|
||||
assertThat(layouts.none { it.showsOverflow }).isTrue()
|
||||
assertThat(layouts.all { it.lanes.isEmpty() }).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `folded events are counted in the overflow`() {
|
||||
val layout = WeekLayout(busyWeeks(perDay = 5)[1], laneCap = 1)
|
||||
assertThat(layout.usedLanes).isEqualTo(1)
|
||||
assertThat(layout.overflow).containsExactly(GridCell(4, 1), GridCell(4, 1), GridCell(4, 1),
|
||||
GridCell(4, 1), GridCell(4, 1), GridCell(4, 1), GridCell(4, 1)).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a multi-day bar is one cell as wide as its days`() {
|
||||
val bar = allDayEvent(monday.plus(1, DateTimeUnit.DAY), monday.plus(3, DateTimeUnit.DAY), id = 1)
|
||||
val layout = WeekLayout(weeks(listOf(bar))[1], laneCap = 3)
|
||||
assertThat(layout.lanes).hasSize(1)
|
||||
assertThat(layout.lanes[0]).containsExactly(GridCell(null, 1), GridCell(bar, 3), GridCell(null, 3)).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a bar on a folded lane moves into the overflow of each day it covers`() {
|
||||
val top = allDayEvent(monday, monday.plus(6, DateTimeUnit.DAY), id = 1)
|
||||
val lower = allDayEvent(monday.plus(2, DateTimeUnit.DAY), monday.plus(3, DateTimeUnit.DAY), id = 2)
|
||||
val layout = WeekLayout(weeks(listOf(top, lower))[1], laneCap = 1)
|
||||
assertThat(layout.lanes).hasSize(1)
|
||||
assertThat(layout.lanes[0]).containsExactly(GridCell(top, 7))
|
||||
assertThat(layout.overflow).containsExactly(GridCell(null, 2), GridCell(1, 1), GridCell(1, 1), GridCell(null, 3))
|
||||
.inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `gaps are merged`() {
|
||||
val counts = listOf(0, 0, 2, 0, 0, 0, 1)
|
||||
val cells = mergeGaps(counts.size) { col -> counts[col].takeIf { it > 0 }?.let { GridCell(it, 1) } }
|
||||
assertThat(cells).containsExactly(GridCell(null, 2), GridCell(2, 1), GridCell(null, 3), GridCell(1, 1))
|
||||
.inOrder()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package de.jeanlucmakiola.calendula.widget.split
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.LocalDate
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class MonthGridDaysTest {
|
||||
|
||||
@Test
|
||||
fun `whole weeks from the week start cover the month and no more`() {
|
||||
// October 2026 starts on a Thursday and has 31 days.
|
||||
val october = 2026 * 12 + 9
|
||||
val monday = monthGridDays(october, DayOfWeek.MONDAY)
|
||||
assertThat(monday.first()).isEqualTo(LocalDate(2026, 9, 28))
|
||||
assertThat(monday.last()).isEqualTo(LocalDate(2026, 11, 1))
|
||||
assertThat(monday).hasSize(35)
|
||||
|
||||
// February 2027 starts on a Monday and fills exactly four weeks.
|
||||
val february = 2027 * 12 + 1
|
||||
assertThat(monthGridDays(february, DayOfWeek.MONDAY)).hasSize(28)
|
||||
assertThat(monthGridDays(february, DayOfWeek.SUNDAY)).hasSize(35)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.jeanlucmakiola.calendula.widget.today
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.ui.agenda.AgendaDay
|
||||
import de.jeanlucmakiola.calendula.ui.agenda.AgendaRange
|
||||
import de.jeanlucmakiola.calendula.widget.AgendaWidgetOptions
|
||||
import de.jeanlucmakiola.calendula.widget.DaysWidgetData
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetSize
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.LocalDate
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Instant
|
||||
|
||||
class TodayRowsTest {
|
||||
|
||||
private val now = Instant.parse("2026-10-21T12:00:00Z")
|
||||
private val today = LocalDate(2026, 10, 21)
|
||||
private val tomorrow = LocalDate(2026, 10, 22)
|
||||
|
||||
private fun event(id: Long, start: Instant, end: Instant) = EventInstance(
|
||||
instanceId = id, eventId = id, calendarId = 1, title = "e$id",
|
||||
start = start, end = end, isAllDay = false, color = 0, location = null,
|
||||
)
|
||||
|
||||
private fun data(past: PastEventDisplay, vararg days: AgendaDay) = DaysWidgetData.Ready(
|
||||
today = today,
|
||||
firstDay = today,
|
||||
lastDay = tomorrow,
|
||||
days = days.toList(),
|
||||
weekStart = DayOfWeek.MONDAY,
|
||||
is24Hour = true,
|
||||
soften = true,
|
||||
options = AgendaWidgetOptions(AgendaRange.Day, WidgetSize.SMALL, true, past),
|
||||
now = now,
|
||||
)
|
||||
|
||||
private val ended = event(1, now - 3.hours, now - 1.hours)
|
||||
private val later = event(2, now + 1.hours, now + 2.hours)
|
||||
private val next = event(3, now + 22.hours, now + 23.hours)
|
||||
|
||||
@Test
|
||||
fun `an event still to come lists today, finished ones as the past setting says`() {
|
||||
val days = arrayOf(AgendaDay(today, listOf(ended, later)), AgendaDay(tomorrow, listOf(next)))
|
||||
assertThat(todayRows(data(PastEventDisplay.DIM, *days))).isEqualTo(TodayRows.Today(listOf(ended, later)))
|
||||
assertThat(todayRows(data(PastEventDisplay.HIDE, *days))).isEqualTo(TodayRows.Today(listOf(later)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `once today is over it looks ahead to tomorrow`() {
|
||||
val over = data(PastEventDisplay.SHOW, AgendaDay(today, listOf(ended)), AgendaDay(tomorrow, listOf(next)))
|
||||
assertThat(todayRows(over)).isEqualTo(TodayRows.NothingLeft(listOf(next)))
|
||||
assertThat(todayRows(data(PastEventDisplay.SHOW))).isEqualTo(TodayRows.NothingLeft(emptyList()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package de.jeanlucmakiola.calendula.widget.upcoming
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.ui.agenda.AgendaDay
|
||||
import de.jeanlucmakiola.calendula.ui.agenda.AgendaRange
|
||||
import de.jeanlucmakiola.calendula.widget.AgendaWidgetOptions
|
||||
import de.jeanlucmakiola.calendula.widget.DaysWidgetData
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetSize
|
||||
import kotlinx.datetime.DayOfWeek
|
||||
import kotlinx.datetime.LocalDate
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Instant
|
||||
|
||||
class UpcomingEventsTest {
|
||||
|
||||
private val now = Instant.parse("2026-10-21T12:00:00Z")
|
||||
|
||||
private fun event(id: Long, start: Instant, end: Instant) = EventInstance(
|
||||
instanceId = id, eventId = id, calendarId = 1, title = "e$id",
|
||||
start = start, end = end, isAllDay = false, color = 0, location = null,
|
||||
)
|
||||
|
||||
private fun data(vararg days: AgendaDay) = DaysWidgetData.Ready(
|
||||
today = LocalDate(2026, 10, 21),
|
||||
firstDay = LocalDate(2026, 10, 21),
|
||||
lastDay = LocalDate(2026, 10, 27),
|
||||
days = days.toList(),
|
||||
weekStart = DayOfWeek.MONDAY,
|
||||
is24Hour = true,
|
||||
soften = true,
|
||||
options = AgendaWidgetOptions(AgendaRange.Week, WidgetSize.SMALL, true, PastEventDisplay.SHOW),
|
||||
now = now,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `ended events drop out and a multi-day one lists once, on its first day`() {
|
||||
val ended = event(1, now - 3.hours, now - 1.hours)
|
||||
val running = event(2, now - 1.hours, now + 30.hours)
|
||||
val later = event(3, now + 2.hours, now + 3.hours)
|
||||
val today = AgendaDay(LocalDate(2026, 10, 21), listOf(ended, running, later))
|
||||
val tomorrow = AgendaDay(LocalDate(2026, 10, 22), listOf(running))
|
||||
|
||||
val upcoming = upcomingEvents(data(today, tomorrow))
|
||||
|
||||
assertThat(upcoming.map { it.second.instanceId }).containsExactly(2L, 3L).inOrder()
|
||||
assertThat(upcoming.first().first).isEqualTo(LocalDate(2026, 10, 21))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user