Read and write view rules through the shared rule codec (#59)
This commit is contained in:
1 parent
bb6e027011
commit
e7b726ee82
4 files changed
+38
-8
No files matched your search
@@ -14,6 +14,24 @@ import org.junit.jupiter.api.Test
|
||||
|
||||
class SavedFilterCodecTest {
|
||||
|
||||
@Test
|
||||
fun `the stored line stays byte for byte, and its rule reads back through decodeRule`() {
|
||||
val rule = Rule.AllOf(
|
||||
listOf(
|
||||
Rule.AnyOf(listOf(Rule.InList(setOf(4L, 2L), setOf("EXTERNAL:7")), Rule.HasTag("a b,c"))),
|
||||
Rule.Not(Rule.Due(DueSpec.Window(DueWindow.NO_DATE))),
|
||||
Rule.MinPriority(Priority.HIGH),
|
||||
Rule.Due(DueSpec.ThisWeek),
|
||||
Rule.Due(DueSpec.NextDays(7)),
|
||||
),
|
||||
)
|
||||
val text = "and(or(list(OWN%3A2,OWN%3A4,EXTERNAL%3A7),tag(a+b%2Cc)),not(due(NO_DATE)),prio(HIGH),range(week),range(next,7))"
|
||||
assertThat(SavedFilterCodec.upsert(null, SavedFilter(3, "Work | x", rule), "OWN")).isEqualTo("v2|3|Work+%7C+x|$text")
|
||||
assertThat(SavedFilterCodec.encodeRule(rule, "OWN")).isEqualTo(text)
|
||||
assertThat(SavedFilterCodec.decodeRule(text, "OWN")).isEqualTo(rule)
|
||||
assertThat(SavedFilterCodec.decodeRule("list()", "OWN")).isEqualTo(Rule.InList(emptySet()))
|
||||
}
|
||||
|
||||
private val criteria = FilterCriteria(
|
||||
due = setOf(DueWindow.TODAY, DueWindow.OVERDUE),
|
||||
listIds = setOf(4L, 9L),
|
||||
|
||||
@@ -97,6 +97,19 @@ class ViewCodecTest {
|
||||
assertThat(odd.blocks.single().source).isEqualTo(BlockSource.ListElsewhere("OWN:abc"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a rule reads back exactly as written, with no saved-filter pruning`() {
|
||||
val scopes = listOf(
|
||||
Rule.InList(emptySet()),
|
||||
Rule.AllOf(listOf(Rule.InList(emptySet()), Rule.HasTag("x"))),
|
||||
Rule.AllOf(listOf(Rule.InList(emptySet(), setOf("EXTERNAL:7")))),
|
||||
)
|
||||
scopes.forEachIndexed { i, scope ->
|
||||
val view = View(i + 1L, "x", ViewIcon.HOME, scope, listOf(Block(1, BlockType.TASK_LIST, BlockSource.Rules(scope))))
|
||||
assertThat(ViewCodec.decode(ViewCodec.encode(listOf(view), "OWN"), "OWN")).containsExactly(view)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nothing stored, or another version, reads as no views`() {
|
||||
assertThat(ViewCodec.decode(null, "OWN")).isEmpty()
|
||||
|
||||
Reference in new issue
Block a user