Merge #95 into release/v1.4.0
# Conflicts: # 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
ebe3bcc5a8
11 files changed
+854
-127
No files matched your search
@@ -0,0 +1,176 @@
|
||||
package de.jeanlucmakiola.agendula.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.time.Instant
|
||||
|
||||
class TaskSearchTest {
|
||||
|
||||
private fun at(millis: Long) = Instant.fromEpochMilliseconds(millis)
|
||||
|
||||
private fun done(id: Long, title: String, completedAt: Long) =
|
||||
testTask(id = id, title = title, status = TaskStatus.COMPLETED, completedAt = at(completedAt))
|
||||
|
||||
@Test
|
||||
fun `a blank query finds nothing and offers nothing`() {
|
||||
val result = TaskSearch.inList(listOf(testTask(title = "Bread")), " ")
|
||||
|
||||
assertThat(result).isEqualTo(ListSearchResult.Empty)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `matches open and completed tasks by title, ignoring case`() {
|
||||
val open = testTask(id = 1, title = "Brown bread")
|
||||
val completed = done(2, "Bread", 10)
|
||||
val other = testTask(id = 3, title = "Milk")
|
||||
|
||||
val result = TaskSearch.inList(listOf(open, completed, other), "BREAD")
|
||||
|
||||
assertThat(result.open).containsExactly(open)
|
||||
assertThat(result.completed).containsExactly(completed)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `titles starting with the query rank first`() {
|
||||
val inside = testTask(id = 1, title = "Brown bread")
|
||||
val starts = testTask(id = 2, title = "Bread rolls")
|
||||
|
||||
val result = TaskSearch.inList(listOf(inside, starts), "bread")
|
||||
|
||||
assertThat(result.open).containsExactly(starts, inside).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a title completed many times shows once, the latest`() {
|
||||
val older = done(1, "Bread", 10)
|
||||
val newer = done(2, "bread ", 20)
|
||||
|
||||
val result = TaskSearch.inList(listOf(older, newer), "bread")
|
||||
|
||||
assertThat(result.completed).containsExactly(newer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a completed task already open again is left out`() {
|
||||
val open = testTask(id = 1, title = "Bread")
|
||||
val completed = done(2, "bread", 10)
|
||||
|
||||
val result = TaskSearch.inList(listOf(open, completed), "bre")
|
||||
|
||||
assertThat(result.open).containsExactly(open)
|
||||
assertThat(result.completed).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an exact title, open or completed, is the match and blocks creating`() {
|
||||
val completed = done(2, "Bread", 10)
|
||||
|
||||
val reopenable = TaskSearch.inList(listOf(completed), " bread ")
|
||||
assertThat(reopenable.exactMatch).isEqualTo(completed)
|
||||
assertThat(reopenable.offerCreate).isFalse()
|
||||
|
||||
val open = testTask(id = 1, title = "Bread")
|
||||
val alreadyOpen = TaskSearch.inList(listOf(open, completed), "bread")
|
||||
assertThat(alreadyOpen.exactMatch).isEqualTo(open)
|
||||
assertThat(alreadyOpen.offerCreate).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a new title is offered for creating`() {
|
||||
val result = TaskSearch.inList(listOf(done(1, "Bread rolls", 10)), "Bread")
|
||||
|
||||
assertThat(result.exactMatch).isNull()
|
||||
assertThat(result.offerCreate).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cancelled tasks are not search hits`() {
|
||||
val cancelled = testTask(id = 1, title = "Bread", status = TaskStatus.CANCELLED)
|
||||
|
||||
val result = TaskSearch.inList(listOf(cancelled), "bread")
|
||||
|
||||
assertThat(result.open).isEmpty()
|
||||
assertThat(result.completed).isEmpty()
|
||||
assertThat(result.offerCreate).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a series matches once, on its current occurrence`() {
|
||||
val past = testTask(id = 2, title = "Water plants", status = TaskStatus.COMPLETED, completedAt = at(5))
|
||||
.copy(seriesId = 1, occurrenceStart = at(100), distanceFromCurrent = -1)
|
||||
val current = testTask(id = 3, title = "Water plants")
|
||||
.copy(seriesId = 1, occurrenceStart = at(200), distanceFromCurrent = 0)
|
||||
|
||||
val result = TaskSearch.inList(listOf(past, current), "water")
|
||||
|
||||
assertThat(result.open).containsExactly(current)
|
||||
assertThat(result.completed).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a subtask's title does not stand in for a top-level task`() {
|
||||
val sub = done(2, "Milk", 10).copy(parentId = 1)
|
||||
|
||||
val result = TaskSearch.inList(listOf(sub), "milk")
|
||||
|
||||
assertThat(result.completed).containsExactly(sub)
|
||||
assertThat(result.exactMatch).isNull()
|
||||
assertThat(result.offerCreate).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a title just added is not offered again`() {
|
||||
val result = TaskSearch.inList(emptyList(), "milk", pendingTitles = setOf("Milk"))
|
||||
|
||||
assertThat(result.offerCreate).isFalse()
|
||||
assertThat(result.adding).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a series shows its open occurrence even when the current one is done`() {
|
||||
val today = testTask(id = 2, title = "Water plants", status = TaskStatus.COMPLETED, completedAt = at(5))
|
||||
.copy(seriesId = 1, occurrenceStart = at(100), distanceFromCurrent = 0)
|
||||
val tomorrow = testTask(id = 3, title = "Water plants")
|
||||
.copy(seriesId = 1, occurrenceStart = at(200), distanceFromCurrent = 1)
|
||||
|
||||
val result = TaskSearch.inList(listOf(today, tomorrow), "water")
|
||||
|
||||
assertThat(result.open).containsExactly(tomorrow)
|
||||
assertThat(result.completed).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a closed series shows its latest completion`() {
|
||||
val older = done(2, "Water plants", 5).copy(seriesId = 1, occurrenceStart = at(100))
|
||||
val newer = done(3, "Water plants", 50).copy(seriesId = 1, occurrenceStart = at(200))
|
||||
|
||||
assertThat(TaskSearch.inList(listOf(older, newer), "water").completed).containsExactly(newer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an ended series is found by its last completion, not a later skipped occurrence`() {
|
||||
val completed = done(2, "Water plants", 50).copy(seriesId = 1, occurrenceStart = at(100), distanceFromCurrent = -1)
|
||||
val skipped = testTask(id = 3, title = "Water plants", status = TaskStatus.CANCELLED)
|
||||
.copy(seriesId = 1, occurrenceStart = at(200), distanceFromCurrent = 0)
|
||||
|
||||
val result = TaskSearch.inList(listOf(completed, skipped), "water plants")
|
||||
|
||||
assertThat(result.completed).containsExactly(completed)
|
||||
assertThat(result.exactMatch).isEqualTo(completed)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `description and location match too, after title matches`() {
|
||||
val byNote = testTask(id = 1, title = "Call landlord").copy(description = "about the rent")
|
||||
val byTitle = testTask(id = 2, title = "Pay rent")
|
||||
|
||||
val result = TaskSearch.inList(listOf(byNote, byTitle), "rent")
|
||||
|
||||
assertThat(result.open).containsExactly(byTitle, byNote).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the result carries the trimmed query`() {
|
||||
assertThat(TaskSearch.inList(emptyList(), " Milk ").query).isEqualTo("Milk")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.jeanlucmakiola.agendula.ui.tasklist
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSearch
|
||||
import de.jeanlucmakiola.agendula.domain.TaskStatus
|
||||
import de.jeanlucmakiola.agendula.domain.testTask
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SearchSubmitTest {
|
||||
|
||||
private val completed = testTask(id = 1, title = "Bread", status = TaskStatus.COMPLETED)
|
||||
|
||||
@Test
|
||||
fun `submitting a completed title reopens it`() {
|
||||
val result = TaskSearch.inList(listOf(completed), "bread")
|
||||
|
||||
assertThat(result.submitAction(canCreate = true)).isEqualTo(SearchSubmit.Reopen(completed))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `submitting a new title creates it, trimmed`() {
|
||||
val result = TaskSearch.inList(listOf(completed), " Milk ")
|
||||
|
||||
assertThat(result.submitAction(canCreate = true)).isEqualTo(SearchSubmit.Create("Milk"))
|
||||
assertThat(result.submitAction(canCreate = false)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `submitting an open title or a read-only one does nothing`() {
|
||||
val open = testTask(id = 2, title = "Milk")
|
||||
assertThat(TaskSearch.inList(listOf(open), "milk").submitAction(canCreate = true)).isNull()
|
||||
|
||||
val readOnly = completed.copy(isReadOnly = true)
|
||||
assertThat(TaskSearch.inList(listOf(readOnly), "bread").submitAction(canCreate = true)).isNull()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user