A view's scope applied with deleted lists matching nothing, block sources and their deleted state, pinning a list or filter, reordering, and where a start destination opens. The view icons grow to the curated set.
This commit is contained in:
1 parent
080afe7aa3
commit
fa5b8e1cef
3 files changed
+364
-2
No files matched your search
@@ -0,0 +1,170 @@
|
||||
package de.jeanlucmakiola.agendula.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.DayOfWeek
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
|
||||
class ViewScopeTest {
|
||||
|
||||
private val zone = ZoneId.of("Europe/Berlin")
|
||||
private val today = LocalDate.of(2026, 11, 26)
|
||||
private val clock = RuleClock(startOfDay(today, zone), startOfDay(today.plusDays(1), zone), zone, DayOfWeek.MONDAY)
|
||||
private val context = SourceContext(clock, upcomingEnd = null, filters = emptyMap())
|
||||
|
||||
private fun view(scope: Rule?) = View(2, "Work", ViewIcon.WORK, scope, emptyList())
|
||||
|
||||
@Test
|
||||
fun `a scope names its lists and the lists a task must be in`() {
|
||||
val rule = Rule.AllOf(
|
||||
listOf(
|
||||
Rule.AnyOf(listOf(Rule.InList(setOf(1L, 2L)), Rule.InList(setOf(3L)))),
|
||||
Rule.Not(Rule.InList(setOf(4L))),
|
||||
Rule.HasTag("x"),
|
||||
),
|
||||
)
|
||||
assertThat(rule.namedListIds()).containsExactly(1L, 2L, 3L, 4L)
|
||||
assertThat(rule.listUniverse()).containsExactly(1L, 2L, 3L)
|
||||
assertThat(Rule.AllOf(listOf(Rule.InList(setOf(1L, 2L)), Rule.InList(setOf(2L, 3L)))).listUniverse()).containsExactly(2L)
|
||||
assertThat(Rule.AnyOf(listOf(Rule.InList(setOf(1L)), Rule.HasTag("x"))).listUniverse()).isNull()
|
||||
assertThat(Rule.Not(Rule.InList(setOf(1L))).listUniverse()).isNull()
|
||||
assertThat(Rule.Everything.listUniverse()).isNull()
|
||||
assertThat(Rule.AnyOf(emptyList()).listUniverse()).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `no scope admits every task`() {
|
||||
val applied = view(null).appliedScope(setOf(1L))
|
||||
assertThat(applied).isEqualTo(AppliedScope.None)
|
||||
assertThat(applied.admits(testTask(listId = 9), clock)).isTrue()
|
||||
assertThat(applied.lists).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a deleted list in the scope matches nothing, never widening`() {
|
||||
val applied = view(Rule.InList(setOf(1L, 2L))).appliedScope(exist = setOf(2L, 3L))
|
||||
assertThat(applied.goneLists).containsExactly(1L)
|
||||
assertThat(applied.admits(testTask(listId = 2), clock)).isTrue()
|
||||
assertThat(applied.admits(testTask(listId = 3), clock)).isFalse()
|
||||
|
||||
val allGone = view(Rule.AllOf(listOf(Rule.InList(setOf(1L)), Rule.HasTag("x")))).appliedScope(exist = setOf(3L))
|
||||
assertThat(allGone.goneLists).containsExactly(1L)
|
||||
assertThat(allGone.admits(testTask(listId = 3, tags = listOf("x")), clock)).isFalse()
|
||||
// A list made later with the deleted one's id doesn't creep back in.
|
||||
assertThat(allGone.admits(testTask(listId = 1, tags = listOf("x")), clock)).isFalse()
|
||||
assertThat(allGone.lists).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a read finding no lists proves none gone`() {
|
||||
val applied = view(Rule.InList(setOf(1L))).appliedScope(exist = emptySet())
|
||||
assertThat(applied.goneLists).isEmpty()
|
||||
assertThat(applied.admits(testTask(listId = 1), clock)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a list named in the scope shows in the smart lists though hidden`() {
|
||||
val applied = view(Rule.InList(setOf(1L))).appliedScope(setOf(1L, 2L))
|
||||
assertThat(applied.hiddenFromSmart(setOf(1L, 2L))).containsExactly(2L)
|
||||
assertThat(AppliedScope.None.hiddenFromSmart(setOf(1L))).containsExactly(1L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a block that ignores the scope reads through none`() {
|
||||
val applied = view(Rule.HasTag("x")).appliedScope(setOf(1L))
|
||||
val block = Block(1, BlockType.TAGS)
|
||||
assertThat(applied.forBlock(block)).isEqualTo(applied)
|
||||
assertThat(applied.forBlock(block.copy(ignoreScope = true))).isEqualTo(AppliedScope.None)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a source is gone once its list or filter is`() {
|
||||
assertThat(BlockSource.List(1).isGone(lists = setOf(2L), filters = emptySet())).isTrue()
|
||||
assertThat(BlockSource.List(1).isGone(lists = emptySet(), filters = emptySet())).isFalse()
|
||||
assertThat(BlockSource.Filter(4).isGone(lists = setOf(1L), filters = setOf(5L))).isTrue()
|
||||
assertThat(BlockSource.Filter(4).isGone(lists = setOf(1L), filters = setOf(4L))).isFalse()
|
||||
assertThat(BlockSource.Smart(SmartList.ALL).isGone(emptySet(), emptySet())).isFalse()
|
||||
assertThat(BlockSource.Tag("x").isGone(setOf(1L), emptySet())).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sources hold their tasks, counts the open ones but for Completed`() {
|
||||
val open = testTask(listId = 1, tags = listOf("x"))
|
||||
val done = testTask(id = 2, listId = 1, status = TaskStatus.COMPLETED)
|
||||
val filter = SavedFilter(4, "f", Rule.HasTag("x"))
|
||||
val withFilter = SourceContext(clock, null, mapOf(4L to filter))
|
||||
assertThat(BlockSource.List(1).contains(done, context)).isTrue()
|
||||
assertThat(BlockSource.List(1).counts(done, context)).isFalse()
|
||||
assertThat(BlockSource.List(1).counts(open, context)).isTrue()
|
||||
assertThat(BlockSource.Smart(SmartList.COMPLETED).counts(done, context)).isTrue()
|
||||
assertThat(BlockSource.Smart(SmartList.COMPLETED).counts(open, context)).isFalse()
|
||||
assertThat(BlockSource.Smart(SmartList.ALL).counts(open, context, hidden = setOf(1L))).isFalse()
|
||||
assertThat(BlockSource.Tag("x").counts(open, context)).isTrue()
|
||||
assertThat(BlockSource.Filter(4).counts(open, withFilter)).isTrue()
|
||||
assertThat(BlockSource.Filter(4).counts(open, context)).isFalse()
|
||||
assertThat(BlockSource.ListElsewhere("OWN:1").contains(open, context)).isFalse()
|
||||
assertThat(BlockSource.Rules(Rule.InList(setOf(1L))).counts(open, context)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pinning a list or filter makes a view of it`() {
|
||||
val list = TaskList(7, "Work", 0, "Local", "local", isSynced = false, isVisible = true, owner = null)
|
||||
val pinned = pinnedViewOf(list, null)!!
|
||||
assertThat(pinned.id).isEqualTo(0L)
|
||||
assertThat(pinned.name).isEqualTo("Work")
|
||||
assertThat(pinned.icon).isEqualTo(ViewIcon.LIST)
|
||||
assertThat(pinned.scope).isEqualTo(Rule.InList(setOf(7L)))
|
||||
assertThat(pinned.quickAdd).isTrue()
|
||||
assertThat(pinned.blocks.map { it.type to it.source })
|
||||
.containsExactly(BlockType.TASK_LIST to BlockSource.Smart(SmartList.ALL))
|
||||
assertThat(pinned.problems).isEmpty()
|
||||
|
||||
val rule = Rule.AnyOf(listOf(Rule.HasTag("next"), Rule.InList(setOf(3L))))
|
||||
val fromFilter = pinnedViewOf(null, SavedFilter(4, "Next", rule))!!
|
||||
assertThat(fromFilter.name).isEqualTo("Next")
|
||||
assertThat(fromFilter.icon).isEqualTo(ViewIcon.FILTER)
|
||||
assertThat(fromFilter.scope).isEqualTo(rule)
|
||||
assertThat(pinnedViewOf(null, null)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a new view starts with Home's blocks and no scope`() {
|
||||
val view = newView(0, "Mine")
|
||||
assertThat(view.blocks).isEqualTo(View.home().blocks)
|
||||
assertThat(view.scope).isNull()
|
||||
assertThat(view.deletable).isTrue()
|
||||
assertThat(View.home().deletable).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `reordering keeps Home first and leaves views not named after the others`() {
|
||||
val views = listOf(View.home(), view(null), view(null).copy(id = 3), view(null).copy(id = 4))
|
||||
assertThat(views.reordered(listOf(4L, View.HOME_ID, 2L)).map { it.id }).containsExactly(1L, 4L, 2L, 3L).inOrder()
|
||||
assertThat(views.reordered(listOf(3L, 2L, 4L)).map { it.id }).containsExactly(1L, 3L, 2L, 4L).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the start destination opens its view, or a list or filter over Home`() {
|
||||
val views = setOf(1L, 2L, 3L)
|
||||
assertThat(StartDestination.LastUsed.plan(views, lastUsed = 3, lists = null, filters = emptySet()))
|
||||
.isEqualTo(StartPlan(3))
|
||||
assertThat(StartDestination.LastUsed.plan(views, lastUsed = 9, lists = null, filters = emptySet()))
|
||||
.isEqualTo(StartPlan(View.HOME_ID))
|
||||
assertThat(StartDestination.View(2).plan(views, lastUsed = 3, lists = null, filters = emptySet()))
|
||||
.isEqualTo(StartPlan(2))
|
||||
assertThat(StartDestination.View(9).plan(views, lastUsed = 3, lists = null, filters = emptySet()))
|
||||
.isEqualTo(StartPlan(View.HOME_ID))
|
||||
assertThat(StartDestination.List(5).plan(views, lastUsed = 3, lists = setOf(5L), filters = emptySet()))
|
||||
.isEqualTo(StartPlan(View.HOME_ID, TaskFilter.OfList(5)))
|
||||
assertThat(StartDestination.List(5).plan(views, lastUsed = 3, lists = setOf(6L), filters = emptySet()))
|
||||
.isEqualTo(StartPlan(View.HOME_ID))
|
||||
assertThat(StartDestination.List(5).plan(views, lastUsed = 3, lists = null, filters = emptySet()))
|
||||
.isEqualTo(StartPlan(View.HOME_ID, TaskFilter.OfList(5)))
|
||||
assertThat(StartDestination.Filter(4).plan(views, lastUsed = 3, lists = null, filters = setOf(4L)))
|
||||
.isEqualTo(StartPlan(View.HOME_ID, TaskFilter.Saved(4)))
|
||||
assertThat(StartDestination.Filter(4).plan(views, lastUsed = 3, lists = null, filters = emptySet()))
|
||||
.isEqualTo(StartPlan(View.HOME_ID))
|
||||
assertThat(DefaultStartDestination).isEqualTo(StartDestination.View(View.HOME_ID))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user