Group tasks by due date, day, priority or list (#71)
This commit is contained in:
1 parent
1463b08d6f
commit
4c261cdb9d
8 files changed
+447
-30
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package de.jeanlucmakiola.agendula.data.prefs
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.TaskGrouping
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.LocalDate
|
||||
|
||||
class TaskGroupingPrefsTest {
|
||||
|
||||
@Test
|
||||
fun `groupings decode per view and keep only the current store's lists`() {
|
||||
val decoded = decodeGroupings(
|
||||
setOf("DAY|smart:UPCOMING", "PRIORITY|list:OWN:5", "LIST|list:PROVIDER:5", "DAY|tag:work", "BOGUS|saved:1", "DAY|"),
|
||||
mode = "OWN",
|
||||
)
|
||||
assertThat(decoded).containsExactly(
|
||||
"smart:UPCOMING", TaskGrouping.DAY,
|
||||
"list:5", TaskGrouping.PRIORITY,
|
||||
"tag:work", TaskGrouping.DAY,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a view without a stored grouping groups by due date`() {
|
||||
val settings = Settings(groupings = mapOf("list:5" to TaskGrouping.PRIORITY))
|
||||
assertThat(settings.groupingFor(TaskFilter.OfList(5))).isEqualTo(TaskGrouping.PRIORITY)
|
||||
assertThat(settings.groupingFor(TaskFilter.OfList(6))).isEqualTo(TaskGrouping.DUE)
|
||||
assertThat(settings.groupingFor(TaskFilter.Smart(SmartList.ALL))).isEqualTo(TaskGrouping.DUE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `collapsed day groups that have passed are dropped`() {
|
||||
val today = LocalDate.of(2026, 11, 17)
|
||||
val kept = dropPastDays(
|
||||
setOf("COMPLETED", "priority:LOW", "day:2026-11-16", "day:2026-11-18", "day:garbage"),
|
||||
today,
|
||||
)
|
||||
assertThat(kept).containsExactly("COMPLETED", "priority:LOW", "day:2026-11-18")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package de.jeanlucmakiola.agendula.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneOffset
|
||||
import kotlin.time.Instant
|
||||
|
||||
class TaskGroupsTest {
|
||||
|
||||
private val dayMs = 86_400_000L
|
||||
private val todayStart = Instant.fromEpochMilliseconds(1000 * dayMs)
|
||||
private val todayEnd = Instant.fromEpochMilliseconds(1001 * dayMs)
|
||||
private val today = LocalDate.ofEpochDay(1000)
|
||||
|
||||
private fun at(millis: Long) = Instant.fromEpochMilliseconds(millis)
|
||||
|
||||
private fun groups(tasks: List<Task>, grouping: TaskGrouping, todayList: Boolean = false) =
|
||||
TaskGroups.of(tasks, grouping, todayStart, todayEnd, todayList, ZoneOffset.UTC)
|
||||
|
||||
private fun keys(tasks: List<Task>, grouping: TaskGrouping, todayList: Boolean = false) =
|
||||
groups(tasks, grouping, todayList).map { it.key }
|
||||
|
||||
@Test
|
||||
fun `due grouping keeps the classic sections`() {
|
||||
val tasks = listOf(
|
||||
testTask(id = 1, due = at(1002 * dayMs)),
|
||||
testTask(id = 2, due = at(1000 * dayMs - 1)),
|
||||
testTask(id = 3),
|
||||
testTask(id = 4, status = TaskStatus.COMPLETED),
|
||||
testTask(id = 5, due = at(1000 * dayMs + 1)),
|
||||
)
|
||||
assertThat(keys(tasks, TaskGrouping.DUE)).containsExactly(
|
||||
TaskGroupKey.Section(TaskSection.OVERDUE),
|
||||
TaskGroupKey.Section(TaskSection.TODAY),
|
||||
TaskGroupKey.Section(TaskSection.UPCOMING),
|
||||
TaskGroupKey.Section(TaskSection.NO_DATE),
|
||||
TaskGroupKey.Section(TaskSection.COMPLETED),
|
||||
).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `day grouping splits upcoming into one group per day in date order`() {
|
||||
val tasks = listOf(
|
||||
testTask(id = 1, due = at(1003 * dayMs + 5)),
|
||||
testTask(id = 2, due = at(1001 * dayMs + 5)),
|
||||
testTask(id = 3, due = at(1003 * dayMs + 9)),
|
||||
testTask(id = 4, due = at(1000 * dayMs + 5)),
|
||||
testTask(id = 5, due = at(999 * dayMs)),
|
||||
testTask(id = 6),
|
||||
)
|
||||
val result = groups(tasks, TaskGrouping.DAY)
|
||||
assertThat(result.map { it.key }).containsExactly(
|
||||
TaskGroupKey.Section(TaskSection.OVERDUE),
|
||||
TaskGroupKey.Section(TaskSection.TODAY),
|
||||
TaskGroupKey.Day(today.plusDays(1)),
|
||||
TaskGroupKey.Day(today.plusDays(3)),
|
||||
TaskGroupKey.Section(TaskSection.NO_DATE),
|
||||
).inOrder()
|
||||
assertThat(result[3].tasks.map { it.taskId }).containsExactly(1L, 3L).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `day grouping reads an all-day due as its calendar date`() {
|
||||
val allDay = testTask(due = at(1002 * dayMs), isAllDay = true)
|
||||
assertThat(keys(listOf(allDay), TaskGrouping.DAY)).containsExactly(TaskGroupKey.Day(today.plusDays(2)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the Today list keeps open tasks under Today for date groupings`() {
|
||||
val tasks = listOf(testTask(id = 1, start = at(1000 * dayMs + 1), due = at(1003 * dayMs)))
|
||||
assertThat(keys(tasks, TaskGrouping.DAY, todayList = true))
|
||||
.containsExactly(TaskGroupKey.Section(TaskSection.TODAY))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `priority grouping runs from high to none and keeps completed last`() {
|
||||
val tasks = listOf(
|
||||
testTask(id = 1, priority = Priority.LOW),
|
||||
testTask(id = 2, priority = Priority.NONE),
|
||||
testTask(id = 3, priority = Priority.HIGH, status = TaskStatus.COMPLETED),
|
||||
testTask(id = 4, priority = Priority.HIGH),
|
||||
)
|
||||
assertThat(keys(tasks, TaskGrouping.PRIORITY)).containsExactly(
|
||||
TaskGroupKey.OfPriority(Priority.HIGH),
|
||||
TaskGroupKey.OfPriority(Priority.LOW),
|
||||
TaskGroupKey.OfPriority(Priority.NONE),
|
||||
TaskGroupKey.Section(TaskSection.COMPLETED),
|
||||
).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `list grouping orders lists by name and keeps the incoming order inside`() {
|
||||
val tasks = listOf(
|
||||
testTask(id = 1, listId = 2).copy(listName = "work"),
|
||||
testTask(id = 2, listId = 1).copy(listName = "Home"),
|
||||
testTask(id = 3, listId = 2).copy(listName = "work"),
|
||||
)
|
||||
val result = groups(tasks, TaskGrouping.LIST)
|
||||
assertThat(result.map { it.key }).containsExactly(
|
||||
TaskGroupKey.OfList(1, "Home"),
|
||||
TaskGroupKey.OfList(2, "work"),
|
||||
).inOrder()
|
||||
assertThat(result[1].tasks.map { it.taskId }).containsExactly(1L, 3L).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `group ids stay stable and match the stored section names`() {
|
||||
assertThat(TaskGroupKey.Section(TaskSection.COMPLETED).id).isEqualTo("COMPLETED")
|
||||
assertThat(TaskGroupKey.Day(LocalDate.of(2026, 11, 20)).id).isEqualTo("day:2026-11-20")
|
||||
assertThat(TaskGroupKey.OfPriority(Priority.HIGH).id).isEqualTo("priority:HIGH")
|
||||
assertThat(TaskGroupKey.OfList(7, "x").id).isEqualTo("list:7")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `empty input yields no groups`() {
|
||||
TaskGrouping.entries.forEach { assertThat(groups(emptyList(), it)).isEmpty() }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user