Merge #71 into release/v1.4.0
# Conflicts: # app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt # app/src/main/java/de/jeanlucmakiola/agendula/ui/tasklist/TaskListScreen.kt # app/src/main/java/de/jeanlucmakiola/agendula/ui/tasklist/TaskListViewModel.kt
This commit is contained in:
commit
450179ffc4
9 files changed
+612
-58
No files matched your search
@@ -0,0 +1,50 @@
|
||||
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 `stored list keys only read back in their own store`() {
|
||||
assertThat(unscopeListKey("list:OWN:5", "OWN")).isEqualTo("list:5")
|
||||
assertThat(unscopeListKey("list:PROVIDER:5", "OWN")).isNull()
|
||||
assertThat(unscopeListKey("COMPLETED", "OWN")).isEqualTo("COMPLETED")
|
||||
assertThat(unscopeListKey("priority:HIGH", "OWN")).isEqualTo("priority:HIGH")
|
||||
}
|
||||
|
||||
@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,140 @@
|
||||
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,
|
||||
listOrder: List<Long> = emptyList(),
|
||||
) = TaskGroups.of(tasks, grouping, todayStart, todayEnd, todayList, listOrder, 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 follows the lists' own order and keeps the incoming order inside`() {
|
||||
val tasks = listOf(
|
||||
testTask(id = 1, listId = 2).copy(listName = "Work", accountName = "cloud"),
|
||||
testTask(id = 2, listId = 1).copy(listName = "Home"),
|
||||
testTask(id = 3, listId = 2).copy(listName = "Work", accountName = "cloud"),
|
||||
testTask(id = 4, listId = 9).copy(listName = "Unknown"),
|
||||
)
|
||||
val result = groups(tasks, TaskGrouping.LIST, listOrder = listOf(2, 1))
|
||||
assertThat(result.map { it.key }).containsExactly(
|
||||
TaskGroupKey.OfList(2, "Work", "cloud"),
|
||||
TaskGroupKey.OfList(1, "Home", null),
|
||||
TaskGroupKey.OfList(9, "Unknown", null),
|
||||
).inOrder()
|
||||
assertThat(result[0].tasks.map { it.taskId }).containsExactly(1L, 3L).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `only groupings that can change a view are offered`() {
|
||||
val all = TaskGrouping.entries
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.Smart(SmartList.ALL))).isEqualTo(all)
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.Smart(SmartList.COMPLETED))).isEmpty()
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.Smart(SmartList.TODAY))).doesNotContain(TaskGrouping.DAY)
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.OfList(1))).doesNotContain(TaskGrouping.LIST)
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.Tagged("x"))).isEqualTo(all)
|
||||
val oneList = SavedFilter(id = 1, name = "f", listIds = setOf(3L))
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.Saved(1), oneList)).doesNotContain(TaskGrouping.LIST)
|
||||
val overdueOnly = SavedFilter(id = 2, name = "g", due = setOf(DueWindow.OVERDUE))
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.Saved(2), overdueOnly)).doesNotContain(TaskGrouping.DAY)
|
||||
assertThat(TaskGroups.offeredFor(TaskFilter.OfLists(setOf(1, 2)))).isEmpty()
|
||||
}
|
||||
|
||||
@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", null).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