Release 1.3.1 (#146)
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 18s
Renovate / renovate (push) Successful in 2m30s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Successful in 21m13s
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Successful in 1m28s
Beta — Codeberg pre-release / detect (push) Successful in 5s
Beta — Codeberg pre-release / beta (push) Skipped
Release — F-Droid repo + Gitea/Codeberg release + Play / detect (push) Successful in 18s
Renovate / renovate (push) Successful in 2m30s
Release — F-Droid repo + Gitea/Codeberg release + Play / release (push) Successful in 21m13s
Release — F-Droid repo + Gitea/Codeberg release + Play / play (push) Successful in 1m28s
Beta — Codeberg pre-release / detect (push) Successful in 5s
Beta — Codeberg pre-release / beta (push) Skipped
Bumps to 1.3.1 (1030199), dates the changelog and adds the What's New for all eight store locales. - Ticking a repeating task moves the series on (#137, #144) - Recurring tasks keep their rule with tasks.org and OpenTasks (#135, #142) - Keep the list order with tasks.org and OpenTasks (#136, #143) Closes #135, closes #136, closes #137 Co-authored-by: Jean-Luc Makiola <business@jeanlucmakiola.de> Reviewed-on: https://codeberg.org/jlmakiola/agendula/pulls/146
This commit is contained in:
1 parent
caf4357cee
commit
3e34c60577
43 files changed
+3419
-225
No files matched your search
+76
@@ -0,0 +1,76 @@
|
||||
package de.jeanlucmakiola.agendula.data.tasks
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.After
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* List order against a real external provider (#136). Skipped unless one is
|
||||
* installed and its permissions are granted.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExternalProviderListOrderTest {
|
||||
|
||||
private val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
private val resolver = ProviderResolver(AndroidProviderEnvironment(context)).apply {
|
||||
storageMode = StorageMode.EXTERNAL
|
||||
}
|
||||
private val source = AndroidTasksDataSource(context, resolver)
|
||||
private val created = mutableListOf<Long>()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
val provider = resolver.resolve()
|
||||
assumeTrue("no external tasks provider, or not granted", provider != null && resolver.hasPermission(provider))
|
||||
listOf("Order A", "Order B", "Order C").forEach { created += source.createLocalList(it, 0) }
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() = created.forEach { runCatching { source.deleteList(it) } }
|
||||
|
||||
private fun ours() = source.taskLists().map { it.id }.filter { it in created }
|
||||
|
||||
/** Waits until the provider has gone quiet, so a change seen afterwards is the test's own. */
|
||||
private fun settle() {
|
||||
var last = System.currentTimeMillis()
|
||||
val observer = source.registerObserver { last = System.currentTimeMillis() }
|
||||
while (System.currentTimeMillis() - last < 1_500) Thread.sleep(100)
|
||||
observer.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aReorderIsKeptAndReported() {
|
||||
val (a, b, c) = created
|
||||
settle()
|
||||
val changed = CountDownLatch(1)
|
||||
val observer = source.registerObserver { changed.countDown() }
|
||||
|
||||
source.reorderLists(listOf(c, a, b))
|
||||
|
||||
assertThat(changed.await(5, TimeUnit.SECONDS)).isTrue()
|
||||
observer.close()
|
||||
assertThat(ours()).containsExactly(c, a, b).inOrder()
|
||||
assertThat(AndroidTasksDataSource(context, resolver).taskLists().map { it.id }.filter { it in created })
|
||||
.containsExactly(c, a, b).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDeletedListLeavesNoPositionBehind() {
|
||||
val (a, b, c) = created
|
||||
source.reorderLists(listOf(c, a, b))
|
||||
|
||||
source.deleteList(c)
|
||||
created -= c
|
||||
|
||||
source.taskLists()
|
||||
assertThat(source.storedListOrder().keys).doesNotContain(c)
|
||||
}
|
||||
}
|
||||
+361
@@ -0,0 +1,361 @@
|
||||
package de.jeanlucmakiola.agendula.data.tasks
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksContract.Tasks
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import de.jeanlucmakiola.agendula.domain.TaskForm
|
||||
import de.jeanlucmakiola.agendula.domain.TaskReminder
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.Instant
|
||||
|
||||
/**
|
||||
* Recurrence against a real external provider (#135). Skipped unless one is
|
||||
* installed and its permissions are granted, so it only runs where set up:
|
||||
* `pm grant <app> org.tasks.permission.READ_TASKS` (and WRITE_TASKS).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExternalProviderRecurrenceTest {
|
||||
|
||||
private val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
private val resolver = ProviderResolver(AndroidProviderEnvironment(context)).apply {
|
||||
storageMode = StorageMode.EXTERNAL
|
||||
}
|
||||
private val source = AndroidTasksDataSource(context, resolver)
|
||||
private var listId = 0L
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
val provider = resolver.resolve()
|
||||
assumeTrue("no external tasks provider, or not granted", provider != null && resolver.hasPermission(provider))
|
||||
listId = source.createLocalList("Recurrence test", 0)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
if (listId != 0L) source.deleteList(listId)
|
||||
}
|
||||
|
||||
private fun dailyTask(): Long {
|
||||
// Milliseconds and all, as the "start today" default gives.
|
||||
val start = Clock.System.now() + 1.hours
|
||||
return source.insertTask(
|
||||
TaskForm(title = "Daily", listId = listId, start = start, due = start + 1.hours, rrule = "FREQ=DAILY"),
|
||||
reminders = null,
|
||||
)
|
||||
}
|
||||
|
||||
private fun storedRule(taskId: Long): String? = context.contentResolver.query(
|
||||
TasksContract.tasksUri(resolver.resolve()!!.authority),
|
||||
arrayOf(Tasks.RRULE),
|
||||
"${Tasks.ID} = ?",
|
||||
arrayOf(taskId.toString()),
|
||||
null,
|
||||
)?.use { c -> if (c.moveToFirst()) c.getString(0) else null }
|
||||
|
||||
private fun setRule(taskId: Long, rule: String) {
|
||||
context.contentResolver.update(
|
||||
TasksContract.tasksUri(resolver.resolve()!!.authority),
|
||||
ContentValues().apply { put(Tasks.RRULE, rule) },
|
||||
"${Tasks.ID} = ?",
|
||||
arrayOf(taskId.toString()),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesReadsAsRecurringWithItsRule() {
|
||||
val id = dailyTask()
|
||||
|
||||
val listed = source.tasks(TaskQuery(listId = listId)).filter { it.taskId == id }.minBy { it.occurrenceStart!! }
|
||||
assertThat(listed.isRecurring).isTrue()
|
||||
assertThat(listed.isOccurrence).isTrue()
|
||||
assertThat(listed.recurrenceRule).isEqualTo("FREQ=DAILY")
|
||||
|
||||
val opened = source.task(id)!!
|
||||
assertThat(opened.recurrenceRule).isEqualTo("FREQ=DAILY")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun savingTheSeriesKeepsItsRule() {
|
||||
val id = dailyTask()
|
||||
val task = source.task(id)!!
|
||||
|
||||
source.updateSeries(
|
||||
id,
|
||||
task.occurrenceStart!!,
|
||||
TaskForm(title = "Daily, renamed", listId = listId, start = task.start, due = task.due, rrule = task.recurrenceRule),
|
||||
reminders = null,
|
||||
)
|
||||
|
||||
assertThat(storedRule(id)).isEqualTo("FREQ=DAILY")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun completingAnOccurrenceMovesTheSeriesOn() {
|
||||
val id = dailyTask()
|
||||
val task = source.task(id)!!
|
||||
|
||||
source.setCompletedInstance(id, task.occurrenceStart!!, completed = true)
|
||||
|
||||
assertSeriesMovedOn(id, task.occurrenceStart!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTickedOccurrenceReadsAsItsCopy() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart!!
|
||||
|
||||
source.setCompletedInstance(id, anchor, completed = true)
|
||||
|
||||
val read = source.task(id, anchor)!!
|
||||
assertThat(read.taskId).isNotEqualTo(id)
|
||||
assertThat(read.isClosed).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun undoingATickMovesTheSeriesBack() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart!!
|
||||
source.setCompletedInstance(id, anchor, completed = true)
|
||||
val copy = source.task(id, anchor)!!.taskId
|
||||
|
||||
source.setCompletedInstance(id, anchor, completed = false)
|
||||
|
||||
val read = source.task(id, anchor)!!
|
||||
assertThat(read.taskId).isEqualTo(id)
|
||||
assertThat(read.isClosed).isFalse()
|
||||
assertThat(source.task(copy)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningTheCopyItselfMovesTheSeriesBack() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart!!
|
||||
source.setCompletedInstance(id, anchor, completed = true)
|
||||
val copy = source.task(id, anchor)!!.taskId
|
||||
|
||||
source.setCompleted(copy, completed = false)
|
||||
|
||||
assertThat(source.task(id, anchor)!!.taskId).isEqualTo(id)
|
||||
assertThat(source.task(copy)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesChangedSinceTheTickReopensOnlyTheCopy() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart!!
|
||||
source.setCompletedInstance(id, anchor, completed = true)
|
||||
val copy = source.task(id, anchor)!!.taskId
|
||||
setRule(id, "FREQ=WEEKLY")
|
||||
|
||||
source.setCompletedInstance(id, anchor, completed = false)
|
||||
|
||||
assertThat(source.task(copy)!!.isClosed).isFalse()
|
||||
assertThat(storedRule(id)).isEqualTo("FREQ=WEEKLY")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anOccurrenceThatIsGoneReadsAsNothing() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart!!
|
||||
|
||||
assertThat(source.task(id, anchor + 30.hours)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesStoredWithMillisecondsStillMovesOn() {
|
||||
val id = legacySeries()
|
||||
val task = source.task(id)!!
|
||||
|
||||
source.setCompletedInstance(id, task.occurrenceStart!!, completed = true)
|
||||
|
||||
assertSeriesMovedOn(id, task.occurrenceStart)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUnknownOccurrenceDoesNotCloseTheSeries() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart!!
|
||||
|
||||
assertThrows(TaskWriteFailedException::class.java) {
|
||||
source.setCompletedInstance(id, anchor + 30.hours, completed = true)
|
||||
}
|
||||
|
||||
assertThat(source.task(id)!!.isClosed).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun roundingALegacySeriesLeavesItUnmodified() {
|
||||
val id = legacySeries()
|
||||
val before = storedColumn(id, Tasks.LAST_MODIFIED)
|
||||
|
||||
source.task(id)
|
||||
|
||||
assertThat(storedStart(id)!! % 1000).isEqualTo(0L)
|
||||
assertThat(storedColumn(id, Tasks.LAST_MODIFIED)).isEqualTo(before)
|
||||
}
|
||||
|
||||
/** A daily series as builds before whole-second writes left it, already in sync with its server. */
|
||||
private fun legacySeries(): Long {
|
||||
val start = (Clock.System.now() + 1.hours).toEpochMilliseconds() / 1000 * 1000
|
||||
return insertAsSyncAdapter(
|
||||
Tasks.LIST_ID to listId,
|
||||
Tasks.TITLE to "Old daily",
|
||||
Tasks.DTSTART to start + 345,
|
||||
Tasks.DUE to start + 3_600_345,
|
||||
Tasks.TZ to "UTC",
|
||||
Tasks.RRULE to "FREQ=DAILY",
|
||||
).also {
|
||||
// The app's own reads may already have run the one-time rounding.
|
||||
context.getSharedPreferences("provider_migrations", Context.MODE_PRIVATE).edit().clear().commit()
|
||||
}
|
||||
}
|
||||
|
||||
private fun insertAsSyncAdapter(vararg values: Pair<String, Any>): Long {
|
||||
val uri = TasksContract.asSyncAdapter(
|
||||
TasksContract.tasksUri(resolver.resolve()!!.authority),
|
||||
TasksContract.LOCAL_ACCOUNT_NAME,
|
||||
TasksContract.LOCAL_ACCOUNT_TYPE,
|
||||
)
|
||||
val cv = ContentValues().apply {
|
||||
values.forEach { (k, v) -> if (v is Long) put(k, v) else put(k, v.toString()) }
|
||||
}
|
||||
return context.contentResolver.insert(uri, cv)!!.lastPathSegment!!.toLong()
|
||||
}
|
||||
|
||||
/** Edits the series' first occurrence on its own and returns the override that makes. */
|
||||
private fun overrideOf(id: Long): Task {
|
||||
val task = source.task(id)!!
|
||||
source.updateInstance(
|
||||
id,
|
||||
task.occurrenceStart!!,
|
||||
TaskForm(title = "Just this once", listId = listId, start = task.start, due = task.due),
|
||||
reminders = null,
|
||||
)
|
||||
return source.tasks(TaskQuery(listId = listId)).single { it.seriesId == id && it.taskId != id }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anOverrideBelongsToItsSeries() {
|
||||
val id = dailyTask()
|
||||
val anchor = source.task(id)!!.occurrenceStart
|
||||
|
||||
val override = overrideOf(id)
|
||||
|
||||
assertThat(override.title).isEqualTo("Just this once")
|
||||
assertThat(override.isOccurrence).isTrue()
|
||||
assertThat(override.occurrenceStart).isEqualTo(anchor)
|
||||
assertThat(override.recurrenceRule).isEqualTo("FREQ=DAILY")
|
||||
assertThat(source.task(override.taskId, override.occurrenceStart)?.taskId).isEqualTo(override.taskId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anAllDayDueAddedToTheSeriesStaysOnItsDay() {
|
||||
val day = Clock.System.now().toEpochMilliseconds() / 86_400_000 * 86_400_000
|
||||
val id = source.insertTask(
|
||||
TaskForm(title = "All day", listId = listId, start = Instant.fromEpochMilliseconds(day), isAllDay = true, rrule = "FREQ=DAILY"),
|
||||
reminders = null,
|
||||
)
|
||||
val task = source.task(id)!!
|
||||
// Local midnight the next day, as the date picker hands it over.
|
||||
val localMidnight = Instant.fromEpochMilliseconds(day + 86_400_000 - java.util.TimeZone.getDefault().getOffset(day))
|
||||
|
||||
source.updateSeries(
|
||||
id,
|
||||
task.occurrenceStart!!,
|
||||
TaskForm(title = "All day", listId = listId, start = task.start, due = localMidnight, isAllDay = true, rrule = "FREQ=DAILY"),
|
||||
reminders = null,
|
||||
)
|
||||
|
||||
assertThat(storedColumn(id, Tasks.DUE)!!.toLong() % 86_400_000).isEqualTo(0L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun savingAllFromAnOverrideKeepsTheSeriesWhereItIs() {
|
||||
val id = dailyTask()
|
||||
val before = storedStart(id)
|
||||
val override = overrideOf(id)
|
||||
|
||||
source.updateSeries(
|
||||
id,
|
||||
override.occurrenceStart!!,
|
||||
TaskForm(title = "Renamed", listId = listId, start = override.start, due = override.due, rrule = override.recurrenceRule),
|
||||
reminders = null,
|
||||
)
|
||||
|
||||
assertThat(storedStart(id)).isEqualTo(before)
|
||||
assertThat(storedRule(id)).isEqualTo("FREQ=DAILY")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deletingAnOverrideExcludesItsOccurrence() {
|
||||
val id = dailyTask()
|
||||
val override = overrideOf(id)
|
||||
|
||||
source.deleteOverride(override.taskId, override.occurrenceStart!!)
|
||||
|
||||
// Excluded on the master, not just the override dropped.
|
||||
assertThat(storedColumn(id, Tasks.EXDATE)).isNotNull()
|
||||
val open = source.tasks(TaskQuery(listId = listId)).filter { it.seriesId == id }
|
||||
assertThat(open.map { it.occurrenceStart }).doesNotContain(override.occurrenceStart)
|
||||
assertThat(storedRule(id)).isEqualTo("FREQ=DAILY")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun editingAnOverrideAgainKeepsItsNewTagsAndReminders() {
|
||||
val id = dailyTask()
|
||||
val override = overrideOf(id)
|
||||
val form = TaskForm(
|
||||
title = override.title,
|
||||
listId = listId,
|
||||
start = override.start,
|
||||
due = override.due,
|
||||
tags = listOf("urgent"),
|
||||
reminders = listOf(TaskReminder(minutesBefore = 15)),
|
||||
)
|
||||
|
||||
source.updateInstance(override.taskId, override.occurrenceStart!!, form, form.reminders)
|
||||
|
||||
assertThat(source.task(override.taskId)!!.tags).containsExactly("urgent")
|
||||
assertThat(source.reminders()[override.taskId]).containsExactly(TaskReminder(minutesBefore = 15))
|
||||
assertThat(source.task(id)?.tags.orEmpty()).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anOccurrenceIsFoundByItsAnchorToTheSecond() {
|
||||
val id = dailyTask()
|
||||
val override = overrideOf(id)
|
||||
|
||||
val found = source.task(id, override.occurrenceStart!! + 345.milliseconds)
|
||||
|
||||
assertThat(found?.taskId).isEqualTo(override.taskId)
|
||||
}
|
||||
|
||||
private fun storedStart(taskId: Long): Long? = storedColumn(taskId, Tasks.DTSTART)?.toLong()
|
||||
|
||||
private fun storedColumn(taskId: Long, column: String): String? = context.contentResolver.query(
|
||||
TasksContract.tasksUri(resolver.resolve()!!.authority),
|
||||
arrayOf(column),
|
||||
"${Tasks.ID} = ?",
|
||||
arrayOf(taskId.toString()),
|
||||
null,
|
||||
)?.use { c -> if (c.moveToFirst()) c.getString(0) else null }
|
||||
|
||||
private fun assertSeriesMovedOn(id: Long, completed: Instant) {
|
||||
assertThat(storedRule(id)).isNotNull()
|
||||
val open = source.tasks(TaskQuery(listId = listId)).filter { it.seriesId == id }
|
||||
assertThat(open).isNotEmpty()
|
||||
assertThat(open.minOf { it.occurrenceStart!! }).isGreaterThan(completed)
|
||||
}
|
||||
}
|
||||
+5
@@ -124,6 +124,7 @@ class AgendulaTaskProviderTest {
|
||||
|
||||
@Test
|
||||
fun aBadWriteReachesTheClientAsIllegalArgument() {
|
||||
assumeTrue("Agendula is running on an external provider", ownStore())
|
||||
// No list has this id, so nothing in the app's real store is touched.
|
||||
val values = ContentValues().apply {
|
||||
put("list_id", Long.MAX_VALUE)
|
||||
@@ -135,6 +136,7 @@ class AgendulaTaskProviderTest {
|
||||
|
||||
@Test
|
||||
fun aFailingBatchWritesNothing() {
|
||||
assumeTrue("Agendula is running on an external provider", ownStore())
|
||||
val missingList = Long.MAX_VALUE
|
||||
val operations = arrayListOf(
|
||||
ContentProviderOperation.newInsert(uri("tasks")).withValue("list_id", missingList).withValue("title", "a").build(),
|
||||
@@ -145,6 +147,9 @@ class AgendulaTaskProviderTest {
|
||||
.use { assertThat(it.count).isEqualTo(0) }
|
||||
}
|
||||
|
||||
/** Whether the app's own store is active: only then does the provider take writes at all. */
|
||||
private fun ownStore() = runCatching { resolver.delete(uri("tasks"), "_id = -1", null) }.isSuccess
|
||||
|
||||
/** stdout and stderr of [command]; the denial lands on stderr. */
|
||||
private fun shell(command: String): String {
|
||||
val (stdout, stdin, stderr) = InstrumentationRegistry.getInstrumentation().uiAutomation
|
||||
|
||||
+18
-2
@@ -734,9 +734,11 @@ class ProviderWriterTest {
|
||||
val series = db.tasks().insert(
|
||||
TaskEntity(listId = home, uid = "f", title = "Floating", due = today, rrule = "FREQ=DAILY;COUNT=3", timezone = null),
|
||||
)
|
||||
val row = readRow(ProviderTable.INSTANCES, instanceId(today))
|
||||
// The second occurrence: ticking the first moves the series on instead.
|
||||
val second = today + 1.days
|
||||
val row = readRow(ProviderTable.INSTANCES, instanceId(second))
|
||||
|
||||
writer.update(ProviderTable.INSTANCES, row + (Tasks.STATUS to 2), byId(ProviderTable.INSTANCES, instanceId(today)), null)
|
||||
writer.update(ProviderTable.INSTANCES, row + (Tasks.STATUS to 2), byId(ProviderTable.INSTANCES, instanceId(second)), null)
|
||||
writer.update(ProviderTable.TASKS, mapOf(Tasks.TITLE to "Still floating"), byId(ProviderTable.TASKS, series), null)
|
||||
|
||||
assertThat(db.tasks().overrides(series).single().status).isEqualTo(TaskStatus.COMPLETED)
|
||||
@@ -795,6 +797,20 @@ class ProviderWriterTest {
|
||||
|
||||
private fun store() = RoomTasksDataSource(db)
|
||||
|
||||
@Test
|
||||
fun reopeningATickedOccurrencesCopyMovesTheSeriesBack() {
|
||||
val series = db.tasks().insert(
|
||||
TaskEntity(listId = home, uid = "w", title = "Weekly", dtstart = today, rrule = "FREQ=WEEKLY", timezone = "UTC"),
|
||||
)
|
||||
store().setCompletedInstance(series, today, true)
|
||||
val copy = db.tasks().allIn(home).single { it.id != series }
|
||||
|
||||
writer.update(ProviderTable.TASKS, mapOf(Tasks.STATUS to 0), byId(ProviderTable.TASKS, copy.id), null)
|
||||
|
||||
assertThat(task(series)!!.dtstart).isEqualTo(today)
|
||||
assertThat(task(copy.id)).isNull()
|
||||
}
|
||||
|
||||
/** Every column of one published row, as a client that read it would write it back. */
|
||||
private fun readRow(table: ProviderTable, id: Long): Map<String, Any?> {
|
||||
val columns = table.columns.map { it.first }
|
||||
|
||||
+625
-5
@@ -211,7 +211,8 @@ class RoomTasksDataSourceTest {
|
||||
@Test
|
||||
fun completingOneOccurrenceLeavesTheRestOfTheSeriesOpen() {
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, now)
|
||||
// Overdue occurrences before it, so it is not the first and forks an override.
|
||||
makeRecurring(id, now - 14.days)
|
||||
val open = { source.tasks(TaskQuery(listId = listId)).filter { it.taskId == id } }
|
||||
val before = open()
|
||||
val target = before.first { it.distanceFromCurrent == 0 }
|
||||
@@ -237,7 +238,8 @@ class RoomTasksDataSourceTest {
|
||||
@Test
|
||||
fun reopeningACompletedOccurrenceReusesItsOverride() {
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, now)
|
||||
// Overdue occurrences before it, so it is not the first and forks an override.
|
||||
makeRecurring(id, now - 14.days)
|
||||
val target = source.tasks(TaskQuery(listId = listId))
|
||||
.first { it.taskId == id && it.distanceFromCurrent == 0 }
|
||||
|
||||
@@ -254,7 +256,8 @@ class RoomTasksDataSourceTest {
|
||||
@Test
|
||||
fun cancellingOneOccurrenceLeavesTheRestOfTheSeriesOpen() {
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, now)
|
||||
// Overdue occurrences before it, so it is not the first and forks an override.
|
||||
makeRecurring(id, now - 14.days)
|
||||
val target = source.tasks(TaskQuery(listId = listId))
|
||||
.first { it.taskId == id && it.distanceFromCurrent == 0 }
|
||||
|
||||
@@ -269,6 +272,621 @@ class RoomTasksDataSourceTest {
|
||||
assertThat(db.tasks().override(id, target.occurrenceStart)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun completingTheFirstOccurrenceMovesTheSeriesOnAndKeepsACopy() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=4")
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
val master = db.tasks().entity(id)!!
|
||||
assertThat(master.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(master.dtstart).isEqualTo(at + 7.days)
|
||||
assertThat(master.due).isEqualTo(at + 8.days)
|
||||
assertThat(master.rrule).isEqualTo("FREQ=WEEKLY;COUNT=3")
|
||||
assertThat(master.isDirty).isTrue()
|
||||
assertThat(db.tasks().overrides(id)).isEmpty()
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
assertThat(copy.status).isEqualTo(TaskStatus.COMPLETED)
|
||||
assertThat(copy.uid).isNotEqualTo(master.uid)
|
||||
assertThat(copy.rrule).isNull()
|
||||
assertThat(copy.masterId).isNull()
|
||||
assertThat(copy.dtstart).isEqualTo(at)
|
||||
assertThat(copy.title).isEqualTo("Water the plants")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningTheOccurrenceMovesTheSeriesBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=4")
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
val master = db.tasks().entity(id)!!
|
||||
assertThat(master.dtstart).isEqualTo(at)
|
||||
assertThat(master.rrule).isEqualTo("FREQ=WEEKLY;COUNT=4")
|
||||
assertThat(db.tasks().allIn(listId).filter { !it.isDeleted }.map { it.id }).containsExactly(id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun completingAnEditedFirstOccurrenceKeepsItsEdits() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, at)
|
||||
source.updateInstance(id, at, TaskForm(title = "Water the cactus", listId = listId, start = at, due = at + 1.days), reminders = null)
|
||||
val override = db.tasks().override(id, at)!!
|
||||
|
||||
source.setCompletedInstance(override.id, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().overrides(id)).isEmpty()
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
assertThat(copy.title).isEqualTo("Water the cactus")
|
||||
assertThat(copy.status).isEqualTo(TaskStatus.COMPLETED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun completingTheLastOccurrenceClosesTheSeries() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=1")
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.status).isEqualTo(TaskStatus.COMPLETED)
|
||||
assertThat(db.tasks().allIn(listId).map { it.id }).containsExactly(id)
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cancellingTheFirstOccurrenceMovesTheSeriesOn() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Water the plants"))
|
||||
makeRecurring(id, at)
|
||||
|
||||
source.setCancelledInstance(id, at, cancelled = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
assertThat(db.tasks().allIn(listId).single { it.id != id }.status).isEqualTo(TaskStatus.CANCELLED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesWhoseStartWasDeletedMovesPastTheTickedOne() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.deleteOccurrence(id, at)
|
||||
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 14.days)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun countSpendsExcludedOccurrencesAndReopeningRestoresThem() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Daily"))
|
||||
makeRecurring(id, at, rule = "FREQ=DAILY;COUNT=4")
|
||||
source.deleteOccurrence(id, at + 1.days)
|
||||
val before = db.tasks().entity(id)!!
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
val moved = db.tasks().entity(id)!!
|
||||
assertThat(moved.dtstart).isEqualTo(at + 2.days)
|
||||
assertThat(moved.rrule).isEqualTo("FREQ=DAILY;COUNT=2")
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
val back = db.tasks().entity(id)!!
|
||||
assertThat(back.dtstart).isEqualTo(before.dtstart)
|
||||
assertThat(back.rrule).isEqualTo(before.rrule)
|
||||
assertThat(back.exdate).isEqualTo(before.exdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningTheCopyItselfMovesTheSeriesBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
|
||||
source.setCompleted(copy.id, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
assertThat(db.tasks().allIn(listId).filter { !it.isDeleted }.map { it.id }).containsExactly(id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun undoingAnEditedOccurrenceBringsItsOverrideBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.updateInstance(id, at, TaskForm(title = "Just this once", listId = listId, start = at, due = at + 1.days), reminders = null)
|
||||
val override = db.tasks().override(id, at)!!
|
||||
source.setCompletedInstance(override.id, at, completed = true)
|
||||
|
||||
source.setCompletedInstance(override.id, at, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
val back = db.tasks().override(id, at)!!
|
||||
assertThat(back.title).isEqualTo("Just this once")
|
||||
assertThat(back.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aStaleTickOfAnOccurrenceMovedPastForksNothing() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().overrides(id)).isEmpty()
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun occurrencesClosedBeforeTheUpdateNoLongerHoldTheSeriesBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
db.tasks().insert(
|
||||
master.copy(id = 0, masterId = id, recurrenceId = at, rrule = null, status = TaskStatus.COMPLETED, completedAt = at),
|
||||
)
|
||||
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 14.days)
|
||||
assertThat(db.tasks().overrides(id)).isEmpty()
|
||||
assertThat(db.tasks().allIn(listId).count { it.id != id && it.status == TaskStatus.COMPLETED }).isEqualTo(2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTickedOccurrenceStillResolvesToItsCopy() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val occurrence = source.task(id, at)!!.occurrenceStart!!
|
||||
|
||||
source.setCompletedInstance(id, occurrence, completed = true)
|
||||
|
||||
val found = source.task(id, occurrence)!!
|
||||
assertThat(found.taskId).isNotEqualTo(id)
|
||||
assertThat(found.isCompleted).isTrue()
|
||||
assertThat(found.occurrenceStart).isEqualTo(occurrence)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theNextOccurrenceStartsWithoutTheLastOnesProgress() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(status = TaskStatus.IN_PROCESS, percentComplete = 60))
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
val master = db.tasks().entity(id)!!
|
||||
assertThat(master.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(master.percentComplete).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theCopyOfAnEditedOccurrenceKeepsItsOwnProperties() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
val override = db.tasks().insert(
|
||||
master.copy(id = 0, masterId = id, recurrenceId = at, rrule = null, unknownProperties = "COMMENT:only this one"),
|
||||
)
|
||||
|
||||
source.setCompletedInstance(override, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(override)!!.unknownProperties!!.lines()).contains("COMMENT:only this one")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuleWithAGapOfMoreThanTenYearsKeepsGoing() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Rare"))
|
||||
makeRecurring(id, at, rule = "FREQ=YEARLY;INTERVAL=11")
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
val master = db.tasks().entity(id)!!
|
||||
assertThat(master.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(master.dtstart!!).isGreaterThan(at + (366 * 10).days)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningKeepsWhatChangedOnTheSeriesSince() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
source.deleteOccurrence(id, at + 28.days)
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
val master = db.tasks().entity(id)!!
|
||||
assertThat(master.dtstart).isEqualTo(at)
|
||||
assertThat(master.exdate).isNotNull()
|
||||
assertThat(source.tasks(TaskQuery(listId = listId)).map { it.occurrenceStart?.epochSeconds })
|
||||
.doesNotContain((at + 28.days).epochSeconds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesWithExtraDatesKeepsTheOverrideModel() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(rdate = "20991231T090000Z"))
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
assertThat(db.tasks().overrides(id).single().status).isEqualTo(TaskStatus.COMPLETED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDeletedSeriesIsNotBroughtBackByItsCopy() {
|
||||
val at = now
|
||||
val work = syncedList()
|
||||
val id = source.insertTask(form(title = "Weekly").copy(listId = work))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(work).single { it.id != id }
|
||||
source.deleteWithSubtasks(id)
|
||||
|
||||
source.setCompleted(copy.id, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(copy.id)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(db.tasks().entity(copy.id)!!.isDeleted).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesEndedOnItsLastOpenOccurrenceReopens() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Three"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=3")
|
||||
val master = db.tasks().entity(id)!!
|
||||
listOf(at, at + 7.days).forEach { done ->
|
||||
db.tasks().insert(master.copy(id = 0, masterId = id, recurrenceId = done, rrule = null, status = TaskStatus.COMPLETED))
|
||||
}
|
||||
|
||||
source.setCompletedInstance(id, at + 14.days, completed = true)
|
||||
assertThat(db.tasks().entity(id)!!.status).isEqualTo(TaskStatus.COMPLETED)
|
||||
// Nothing to move past: the closed occurrences stay the series' own.
|
||||
assertThat(db.tasks().overrides(id)).hasSize(2)
|
||||
|
||||
source.setCompletedInstance(id, at + 14.days, completed = false)
|
||||
assertThat(db.tasks().entity(id)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningAnOlderCopyReopensItOnItsOwn() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 14.days)
|
||||
val reopened = db.tasks().allIn(listId).single { it.id != id && it.dtstart == at }
|
||||
assertThat(reopened.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(db.advancedOccurrences().forCopy(reopened.id)!!.undoable).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesMovesPastOccurrencesAlreadyClosedAfterIt() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
db.tasks().insert(master.copy(id = 0, masterId = id, recurrenceId = at + 7.days, rrule = null, status = TaskStatus.COMPLETED))
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 14.days)
|
||||
assertThat(db.tasks().overrides(id)).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDetachedOccurrenceDeletedSinceStaysExcluded() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
val earlier = db.tasks().insert(master.copy(id = 0, masterId = id, recurrenceId = at, rrule = null, status = TaskStatus.COMPLETED))
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
source.deleteTask(earlier)
|
||||
|
||||
source.setCompletedInstance(id, at + 7.days, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
assertThat(source.tasks(TaskQuery(listId = listId)).map { it.occurrenceStart?.epochSeconds })
|
||||
.doesNotContain(at.epochSeconds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aNestedComponentKeepsItsOwnUid() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
val override = db.tasks().insert(
|
||||
master.copy(
|
||||
id = 0, masterId = id, recurrenceId = at, rrule = null,
|
||||
unknownProperties = "BEGIN:VALARM\r\nUID:alarm-1\r\nACTION:AUDIO\r\nEND:VALARM",
|
||||
),
|
||||
)
|
||||
|
||||
source.setCompletedInstance(override, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(override)!!.unknownProperties!!.lines()).contains("UID:alarm-1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningTheCopyInTheEditorMovesTheSeriesBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
|
||||
source.updateTask(
|
||||
copy.id,
|
||||
TaskForm(title = copy.title.orEmpty(), listId = listId, start = copy.dtstart, due = copy.due, percentComplete = 0),
|
||||
reminders = null,
|
||||
)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anEditedCopyReopensAsATaskOfItsOwn() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
db.tasks().update(copy.copy(description = "notes"))
|
||||
source.updateTask(copy.id, TaskForm(title = "Renamed", listId = listId, start = copy.dtstart, due = copy.due, percentComplete = 100), null)
|
||||
|
||||
source.setCompleted(copy.id, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
assertThat(db.tasks().entity(copy.id)!!.title).isEqualTo("Renamed")
|
||||
assertThat(db.tasks().entity(copy.id)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aCopyWithASubtaskReopensOnItsOwn() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
source.insertTask(form(title = "Part").copy(parentId = copy.id))
|
||||
|
||||
source.setCompleted(copy.id, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
assertThat(db.tasks().entity(copy.id)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRecurringSubtaskKeepsTheOverrideModel() {
|
||||
val at = now
|
||||
val parent = source.insertTask(form(title = "Parent"))
|
||||
val id = source.insertTask(form(title = "Daily part").copy(parentId = parent))
|
||||
makeRecurring(id, at, rule = "FREQ=DAILY")
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
assertThat(db.tasks().overrides(id)).hasSize(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSeriesReshapedSinceIsNotMovedBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Ten"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=10")
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(rrule = "FREQ=DAILY;COUNT=5"))
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
assertThat(db.tasks().entity(id)!!.rrule).isEqualTo("FREQ=DAILY;COUNT=5")
|
||||
assertThat(db.tasks().allIn(listId).single { it.id != id }.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tickingTheSameOccurrenceAgainKeepsOneRecord() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
|
||||
assertThat(db.advancedOccurrences().forMaster(id)).hasSize(1)
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anEditedCopyStillStandsForItsOccurrence() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
|
||||
db.tasks().update(copy.copy(title = "Watered"))
|
||||
|
||||
assertThat(source.task(id, at)!!.taskId).isEqualTo(copy.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDetachedOccurrenceWithALifeOfItsOwnStaysOut() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
val earlier = db.tasks().insert(master.copy(id = 0, masterId = id, recurrenceId = at, rrule = null, status = TaskStatus.COMPLETED))
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
source.insertTask(form(title = "Follow-up").copy(parentId = earlier))
|
||||
|
||||
source.setCompletedInstance(id, at + 7.days, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(earlier)!!.masterId).isNull()
|
||||
assertThat(source.tasks(TaskQuery(listId = listId)).map { it.occurrenceStart?.epochSeconds })
|
||||
.doesNotContain(at.epochSeconds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningAnotherOverrideOfAFinishedSeriesLeavesItsLastOccurrenceClosed() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Three"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=3")
|
||||
val master = db.tasks().entity(id)!!
|
||||
val last = db.tasks().insert(master.copy(id = 0, masterId = id, recurrenceId = at + 14.days, rrule = null, status = TaskStatus.COMPLETED))
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
assertThat(db.tasks().entity(id)!!.status).isEqualTo(TaskStatus.COMPLETED)
|
||||
|
||||
source.setCompletedInstance(last, at + 14.days, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(last)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(db.tasks().entity(id)!!.status).isEqualTo(TaskStatus.COMPLETED)
|
||||
assertThat(source.task(id, at + 7.days)!!.isClosed).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningTheCopyWithNewRemindersKeepsThem() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
|
||||
source.updateTask(
|
||||
copy.id,
|
||||
TaskForm(title = copy.title.orEmpty(), listId = listId, start = copy.dtstart, due = copy.due, percentComplete = 0),
|
||||
reminders = listOf(TaskReminder(minutesBefore = 30)),
|
||||
)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at + 7.days)
|
||||
assertThat(db.tasks().entity(copy.id)!!.status).isEqualTo(TaskStatus.NEEDS_ACTION)
|
||||
assertThat(db.alarms().forTask(copy.id)).hasSize(1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDetachedOccurrenceReopenedSinceStaysOut() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
val master = db.tasks().entity(id)!!
|
||||
val earlier = db.tasks().insert(master.copy(id = 0, masterId = id, recurrenceId = at, rrule = null, status = TaskStatus.COMPLETED))
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
source.setCompleted(earlier, completed = false)
|
||||
|
||||
source.setCompletedInstance(id, at + 7.days, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
assertThat(db.tasks().entity(earlier)!!.masterId).isNull()
|
||||
assertThat(source.tasks(TaskQuery(listId = listId)).filter { it.taskId == id }.map { it.occurrenceStart?.epochSeconds })
|
||||
.doesNotContain(at.epochSeconds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anOccurrenceWhoseCopyIsGoneReadsAsNothing() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
source.deleteTask(db.tasks().allIn(listId).single { it.id != id }.id)
|
||||
|
||||
assertThat(source.task(id, at)).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun catchingUpOnAnOverdueSeriesKeepsEachTickUndoable() {
|
||||
val at = now - 56.days
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val first = db.tasks().allIn(listId).single { it.id != id }
|
||||
source.setCompletedInstance(id, at + 7.days, completed = true)
|
||||
|
||||
assertThat(db.advancedOccurrences().forCopy(first.id)).isNotNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuleTheServerReorderedStillMovesBack() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Ten"))
|
||||
makeRecurring(id, at, rule = "FREQ=WEEKLY;COUNT=10")
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(rrule = "count=9;FREQ=WEEKLY"))
|
||||
|
||||
source.setCompletedInstance(id, at, completed = false)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reopeningWithProgressKeepsIt() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
|
||||
source.updateTask(
|
||||
copy.id,
|
||||
TaskForm(title = copy.title.orEmpty(), listId = listId, start = copy.dtstart, due = copy.due, percentComplete = 40),
|
||||
reminders = null,
|
||||
)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
assertThat(db.tasks().override(id, at)!!.percentComplete).isEqualTo(40)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theEditorsTidyingDoesNotCountAsAnEdit() {
|
||||
val at = now
|
||||
val id = source.insertTask(form(title = "Weekly"))
|
||||
makeRecurring(id, at)
|
||||
db.tasks().update(db.tasks().entity(id)!!.copy(description = "From the server\n"))
|
||||
source.setCompletedInstance(id, at, completed = true)
|
||||
val copy = db.tasks().allIn(listId).single { it.id != id }
|
||||
|
||||
source.updateTask(
|
||||
copy.id,
|
||||
TaskForm(title = copy.title.orEmpty(), listId = listId, description = copy.description, start = copy.dtstart, due = copy.due, percentComplete = 0),
|
||||
reminders = null,
|
||||
)
|
||||
|
||||
assertThat(db.tasks().entity(id)!!.dtstart).isEqualTo(at)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun completingANonRecurringTaskThroughTheInstancePathWritesTheRowItself() {
|
||||
val id = source.insertTask(form(title = "Buy milk", due = now + 1.days))
|
||||
@@ -657,10 +1275,12 @@ class RoomTasksDataSourceTest {
|
||||
val outOfWindow = db.tasks().insert(
|
||||
TaskEntity(listId = listId, uid = "old", title = "old", dtstart = longAgo, rrule = "FREQ=DAILY;COUNT=2", parentId = parent),
|
||||
)
|
||||
val at = now
|
||||
val series = db.tasks().insert(
|
||||
TaskEntity(listId = listId, uid = "s", title = "s", dtstart = now, rrule = "FREQ=DAILY;COUNT=3", parentId = parent),
|
||||
TaskEntity(listId = listId, uid = "s", title = "s", dtstart = at, rrule = "FREQ=DAILY;COUNT=3", parentId = parent),
|
||||
)
|
||||
source.setCompletedInstance(series, now, true)
|
||||
// Not the first occurrence, so it forks an override rather than a copy.
|
||||
source.setCompletedInstance(series, at + 1.days, true)
|
||||
val plain = source.insertTask(form("plain").copy(parentId = parent))
|
||||
|
||||
assertThat(source.subtaskIds(parent)).containsExactly(outOfWindow, series, plain)
|
||||
|
||||
+12
@@ -162,6 +162,18 @@ class TasksDatabaseMigrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addsTheAdvancedOccurrencesTable() {
|
||||
helper.createDatabase(TEST_DB, 4).close()
|
||||
|
||||
helper.runMigrationsAndValidate(TEST_DB, 5, true, TasksDatabase.MIGRATION_4_5).use { db ->
|
||||
db.query("SELECT COUNT(*) FROM advanced_occurrences").use { c ->
|
||||
assertThat(c.moveToFirst()).isTrue()
|
||||
assertThat(c.getInt(0)).isEqualTo(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TEST_DB = "migration-test.db"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user