Read untimed ends in the task's zone, ring them by their date, review fixes (#101)
This commit is contained in:
1 parent
3adfeb16a5
commit
e3a2d974c7
25 files changed
+438
-160
No files matched your search
@@ -2,10 +2,12 @@ package de.jeanlucmakiola.agendula.data.tasks
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.data.prefs.Settings
|
||||
import de.jeanlucmakiola.agendula.domain.TaskEnd
|
||||
import de.jeanlucmakiola.agendula.domain.TaskForm
|
||||
import de.jeanlucmakiola.agendula.domain.TaskReminder
|
||||
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
|
||||
import de.jeanlucmakiola.agendula.domain.testTask
|
||||
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
|
||||
import de.jeanlucmakiola.agendula.domain.asReminderLead
|
||||
import de.jeanlucmakiola.floret.reminders.asReminderLeads
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -29,6 +31,25 @@ class StoredRemindersTest {
|
||||
private fun stored(form: TaskForm, current: de.jeanlucmakiola.agendula.domain.Task? = null, with: Settings = settings) =
|
||||
StoredReminders.of(form, current, with, now.toEpochMilliseconds(), zone)
|
||||
|
||||
@Test
|
||||
fun `an end without a time is past or not by the time it rings at, not the one it is stored at`() {
|
||||
val today = LocalDate.of(2026, 10, 1)
|
||||
val withTimes = Settings(
|
||||
defaultReminders = listOf(TaskReminder(60), TaskReminder(0, fromStart = true)).map { it.asReminderLead() },
|
||||
allDayReminderMinuteOfDay = 13 * 60,
|
||||
)
|
||||
val untimedDue = TaskForm(
|
||||
title = "t", listId = 1, start = now - 1.hours,
|
||||
due = untimedInstantOf(TaskEnd.DUE, today, zone), untimed = TaskEnd.DUE,
|
||||
)
|
||||
val untimedStart = TaskForm(
|
||||
title = "t", listId = 1, start = untimedInstantOf(TaskEnd.START, today, zone),
|
||||
due = now + 5.days, untimed = TaskEnd.START,
|
||||
)
|
||||
assertThat(stored(untimedDue, with = withTimes.copy(allDayReminderMinuteOfDay = 9 * 60))).isEmpty()
|
||||
assertThat(stored(untimedStart, with = withTimes)).contains(TaskReminder(0, fromStart = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a new task takes the defaults for the dates it has`() {
|
||||
val form = TaskForm(title = "t", listId = 1, start = now + 2.days, due = now + 5.days)
|
||||
|
||||
@@ -475,7 +475,11 @@ class VTodoMapperTest {
|
||||
|
||||
@Test
|
||||
fun `an untimed due round-trips too`() {
|
||||
val dueOnly = mixed.copy(untimed = TaskEnd.DUE)
|
||||
val dueOnly = mixed.copy(
|
||||
dtstart = Instant.parse("2026-09-01T07:00:00Z"),
|
||||
due = Instant.parse("2026-09-01T21:59:59Z"),
|
||||
untimed = TaskEnd.DUE,
|
||||
)
|
||||
val written = VTodoMapper.write(dueOnly)
|
||||
assertThat(written.property("DUE")?.param(ICalValues.NO_TIME_PARAM)).isEqualTo("TRUE")
|
||||
assertThat(written.property("DTSTART")?.param(ICalValues.NO_TIME_PARAM)).isNull()
|
||||
@@ -503,6 +507,18 @@ class VTodoMapperTest {
|
||||
assertThat(mapped.entity.unknownProperties).contains("DUE;X-AGENDULA-NO-TIME=TRUE")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a marked value another client moved off its day boundary has a time, and loses the mark`() {
|
||||
val mapped = VTodoMapper.read(
|
||||
vtodo(
|
||||
"DTSTART;TZID=Europe/Berlin:20260901T090000",
|
||||
"DUE;X-AGENDULA-NO-TIME=TRUE;TZID=Europe/Berlin:20260901T150000",
|
||||
),
|
||||
)
|
||||
assertThat(mapped.entity.untimed).isNull()
|
||||
assertThat(VTodoMapper.write(mapped.entity).property("DUE")?.param(ICalValues.NO_TIME_PARAM)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a mark on a DATE is ignored, the task is all-day`() {
|
||||
val read = VTodoMapper.read(
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package de.jeanlucmakiola.agendula.data.tasks.room
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.domain.TaskEnd
|
||||
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.Instant
|
||||
|
||||
class OccurrenceTimesTest {
|
||||
|
||||
private val berlin = ZoneId.of("Europe/Berlin")
|
||||
|
||||
private fun at(date: LocalDate, hour: Int) =
|
||||
Instant.fromEpochMilliseconds(date.atTime(hour, 0).atZone(berlin).toInstant().toEpochMilli())
|
||||
|
||||
@Test
|
||||
fun `a due without a time stays on its day across a clock change (#101)`() {
|
||||
val master = TaskEntity(
|
||||
listId = 1,
|
||||
uid = "u",
|
||||
dtstart = at(LocalDate.of(2026, 10, 24), 10),
|
||||
due = untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 10, 26), berlin),
|
||||
timezone = "Europe/Berlin",
|
||||
untimed = TaskEnd.DUE,
|
||||
rrule = "FREQ=WEEKLY",
|
||||
)
|
||||
val (_, due) = occurrenceTimes(master, at(LocalDate.of(2026, 10, 31), 10))
|
||||
assertThat(due).isEqualTo(untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 11, 2), berlin))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a timed due keeps the master's length`() {
|
||||
val master = TaskEntity(
|
||||
listId = 1,
|
||||
uid = "u",
|
||||
dtstart = at(LocalDate.of(2026, 9, 1), 10),
|
||||
due = at(LocalDate.of(2026, 9, 1), 12),
|
||||
timezone = "Europe/Berlin",
|
||||
)
|
||||
val (_, due) = occurrenceTimes(master, at(LocalDate.of(2026, 9, 8), 10))
|
||||
assertThat(due).isEqualTo(at(LocalDate.of(2026, 9, 8), 12))
|
||||
}
|
||||
}
|
||||
@@ -67,4 +67,15 @@ class AllDayTimeTest {
|
||||
assertThat(start.calendarDate(allDay = false, zone = newYork)).isEqualTo(julyTwentieth)
|
||||
assertThat(due.calendarDate(allDay = false, zone = newYork)).isEqualTo(julyTwentieth)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an untimed end reads as its date in the task's zone, wherever the device is`() {
|
||||
val due = untimedInstantOf(TaskEnd.DUE, julyTwentieth, berlin)
|
||||
val task = testTask(start = due - kotlin.time.Duration.parse("2h"), due = due)
|
||||
.copy(untimed = TaskEnd.DUE, timeZone = "Europe/Berlin")
|
||||
assertThat(task.dateOf(TaskEnd.DUE, ZoneId.of("Asia/Tokyo"))).isEqualTo(julyTwentieth)
|
||||
assertThat(task.shownValue(TaskEnd.DUE)).isEqualTo(allDayInstantOf(julyTwentieth))
|
||||
assertThat(task.hasTime(TaskEnd.DUE)).isFalse()
|
||||
assertThat(task.hasTime(TaskEnd.START)).isTrue()
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.setMain
|
||||
@@ -73,11 +74,10 @@ class TaskEditViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `untouched reminders survive an all-day switch while the task has no date`() {
|
||||
fun `untouched reminders survive the task coming back all-day`() {
|
||||
val vm = editing(reminders = listOf(TaskReminder(0)))
|
||||
vm.onDueChange(null)
|
||||
vm.onAllDayChange(true)
|
||||
vm.onDueChange(due)
|
||||
vm.onWhenChange(TaskEnd.DUE, LocalDate.now().plusDays(3), null)
|
||||
|
||||
assertThat(vm.state.value.reminders).isNotEmpty()
|
||||
assertThat(vm.state.value.reminders.all { it.allDay.minuteOfDay != null || it.minutesBefore % (24 * 60) == 0 })
|
||||
@@ -109,10 +109,9 @@ class TaskEditViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day switch or another list does not bring them back`() {
|
||||
fun `another list does not bring them back`() {
|
||||
val vm = editing()
|
||||
vm.onDueChange(null)
|
||||
vm.onAllDayChange(true)
|
||||
vm.onListChange(LIST_ID + 1)
|
||||
|
||||
assertThat(vm.state.value.reminders).isEmpty()
|
||||
@@ -214,6 +213,51 @@ class TaskEditViewModelTest {
|
||||
assertThat(vm.state.value.untimed).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clearing the timed end leaves the other one all-day`() {
|
||||
val vm = editing(start = due - 1.days)
|
||||
val day = LocalDate.now().plusDays(3)
|
||||
vm.onWhenChange(TaskEnd.DUE, day, null)
|
||||
vm.onStartChange(null)
|
||||
|
||||
val state = vm.state.value
|
||||
assertThat(state.isAllDay).isTrue()
|
||||
assertThat(state.untimed).isNull()
|
||||
assertThat(state.due).isEqualTo(allDayInstantOf(day))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a new task's untouched start goes all-day with a due picked without a time`() {
|
||||
val prefs = settingsPrefs().apply { runBlocking { setDefaultStartToday(true) } }
|
||||
val vm = TaskEditViewModel(repository, prefs).apply { bindNew() }
|
||||
val day = LocalDate.now().plusDays(2)
|
||||
vm.onWhenChange(TaskEnd.DUE, day, null)
|
||||
|
||||
assertThat(vm.state.value.isAllDay).isTrue()
|
||||
assertThat(vm.state.value.start).isEqualTo(allDayInstantOf(LocalDate.now()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a start the user picked keeps its time beside a due without one`() {
|
||||
val prefs = settingsPrefs().apply { runBlocking { setDefaultStartToday(true) } }
|
||||
val vm = TaskEditViewModel(repository, prefs).apply { bindNew() }
|
||||
vm.onWhenChange(TaskEnd.START, LocalDate.now(), LocalTime.of(9, 0))
|
||||
vm.onWhenChange(TaskEnd.DUE, LocalDate.now().plusDays(2), null)
|
||||
|
||||
assertThat(vm.state.value.untimed).isEqualTo(TaskEnd.DUE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an untimed end from another zone opens on its own date`() {
|
||||
val berlinDue = untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 11, 20), java.time.ZoneId.of("Pacific/Kiritimati"))
|
||||
repository.task = task(due - 1.days, berlinDue).copy(untimed = TaskEnd.DUE, timeZone = "Pacific/Kiritimati")
|
||||
repository.reminders = emptyList()
|
||||
val vm = TaskEditViewModel(repository, settingsPrefs()).apply { bindEdit(TASK_ID) }
|
||||
|
||||
assertThat(vm.state.value.due).isEqualTo(untimedInstantOf(TaskEnd.DUE, LocalDate.of(2026, 11, 20)))
|
||||
assertThat(vm.state.value.isDirty).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clearing the untimed end drops its mark`() {
|
||||
val vm = editing(start = due - 1.days)
|
||||
|
||||
Reference in new issue
Block a user