Give the other end the picked time where the store can't keep a date alone (#101)
This commit is contained in:
1 parent
4796cf9856
commit
bf8aaf38a0
2 files changed
+21
-5
No files matched your search
@@ -32,8 +32,6 @@ import de.jeanlucmakiola.agendula.domain.populatedFields
|
||||
import de.jeanlucmakiola.agendula.domain.htmlToPlainText
|
||||
import de.jeanlucmakiola.agendula.domain.looksLikeHtml
|
||||
import de.jeanlucmakiola.agendula.domain.DefaultStartDate
|
||||
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
|
||||
import de.jeanlucmakiola.agendula.domain.calendarDate
|
||||
import de.jeanlucmakiola.agendula.domain.dueWindows
|
||||
import de.jeanlucmakiola.agendula.domain.showsIn
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
@@ -445,7 +443,8 @@ class TaskEditViewModel @Inject constructor(
|
||||
* Sets [end] to [date] at [time], or to the date alone when [time] is null
|
||||
* (#101). With the other end also without a time, or a store that cannot
|
||||
* keep one end apart, that makes the whole task all-day; a time on one end
|
||||
* of an all-day task leaves the other end's date without one.
|
||||
* of an all-day task leaves the other end's date without one, or, where the
|
||||
* store cannot keep that, gives it the same time.
|
||||
*/
|
||||
fun onWhenChange(end: TaskEnd, date: LocalDate, time: LocalTime?) = update { s ->
|
||||
val other = end.other
|
||||
@@ -467,7 +466,8 @@ class TaskEditViewModel @Inject constructor(
|
||||
when {
|
||||
allDay == s.isAllDay -> at
|
||||
allDay -> allDayInstantOf(at.calendarDate(allDay = false))
|
||||
else -> untimedInstantOf(other, at.calendarDate(allDay = true))
|
||||
s.untimedEnds -> untimedInstantOf(other, at.calendarDate(allDay = true))
|
||||
else -> localToInstant(at.calendarDate(allDay = true), checkNotNull(time))
|
||||
}
|
||||
}
|
||||
val untimed = when {
|
||||
|
||||
@@ -23,8 +23,8 @@ import de.jeanlucmakiola.agendula.domain.TaskForm
|
||||
import de.jeanlucmakiola.agendula.domain.TaskList
|
||||
import de.jeanlucmakiola.agendula.domain.TaskReminder
|
||||
import de.jeanlucmakiola.agendula.domain.TaskStatus
|
||||
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
|
||||
import de.jeanlucmakiola.agendula.domain.untimedInstantOf
|
||||
import de.jeanlucmakiola.agendula.ui.common.localToInstant
|
||||
import de.jeanlucmakiola.agendula.domain.recurrence.RecurringScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@@ -288,6 +288,22 @@ class TaskEditViewModelTest {
|
||||
assertThat(vm.state.value.untimed).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a store without untimed ends gives both ends the time picked for one`() {
|
||||
repository.untimedEnds = false
|
||||
val vm = editing(start = due - 1.days)
|
||||
val day = LocalDate.now().plusDays(3)
|
||||
vm.onWhenChange(TaskEnd.DUE, day, null)
|
||||
vm.onWhenChange(TaskEnd.START, day.minusDays(1), null)
|
||||
vm.onWhenChange(TaskEnd.DUE, day, LocalTime.of(17, 0))
|
||||
|
||||
val state = vm.state.value
|
||||
assertThat(state.isAllDay).isFalse()
|
||||
assertThat(state.untimed).isNull()
|
||||
assertThat(state.due).isEqualTo(localToInstant(day, LocalTime.of(17, 0)))
|
||||
assertThat(state.start).isEqualTo(localToInstant(day.minusDays(1), LocalTime.of(17, 0)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clearing the timed end leaves the other one all-day`() {
|
||||
val vm = editing(start = due - 1.days)
|
||||
|
||||
Reference in new issue
Block a user