Add google task manual sorting tests

pull/996/head
Alex Baker 5 years ago
parent 0c0d4a79e7
commit cad430dfdf

@ -0,0 +1,101 @@
package org.tasks.data
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.natpryce.makeiteasy.MakeItEasy.with
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.helper.UUIDHelper
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.tasks.R
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.TestComponent
import org.tasks.makers.GoogleTaskListMaker.REMOTE_ID
import org.tasks.makers.GoogleTaskListMaker.newGoogleTaskList
import org.tasks.makers.GoogleTaskMaker.LIST
import org.tasks.makers.GoogleTaskMaker.ORDER
import org.tasks.makers.GoogleTaskMaker.PARENT
import org.tasks.makers.GoogleTaskMaker.TASK
import org.tasks.makers.GoogleTaskMaker.newGoogleTask
import org.tasks.makers.TaskMaker
import org.tasks.makers.TaskMaker.ID
import org.tasks.makers.TaskMaker.UUID
import org.tasks.preferences.Preferences
import javax.inject.Inject
@RunWith(AndroidJUnit4::class)
class ManualGoogleTaskQueryTest : InjectingTestCase() {
@Inject lateinit var googleTaskDao: GoogleTaskDao
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var preferences: Preferences
private lateinit var filter: GtasksFilter
@Before
override fun setUp() {
super.setUp()
filter = GtasksFilter(newGoogleTaskList(with(REMOTE_ID, "1234")))
filter.setFilterQueryOverride(GtasksFilter.toManualOrder(filter.getSqlQuery()))
preferences.clear()
preferences.setBoolean(R.string.p_manual_sort, true)
}
@Test
fun setIndentOnSubtask() {
newTask(1, 0, 0)
newTask(2, 0, 1)
val subtask = query()[1]
assertEquals(1, subtask.indent)
}
@Test
fun setParentOnSubtask() {
newTask(2, 0, 0)
newTask(1, 0, 2)
val subtask = query()[1]
assertEquals(2, subtask.parent)
}
@Test
fun querySetsPrimarySort() {
newTask(1, 0, 0)
newTask(2, 1, 0)
newTask(3, 0, 2)
val subtasks = query()
assertEquals(0, subtasks[0].primarySort)
assertEquals(1, subtasks[1].primarySort)
assertEquals(1, subtasks[2].primarySort)
}
@Test
fun querySetsSecondarySortOnSubtasks() {
newTask(1, 0, 0)
newTask(2, 0, 1)
newTask(3, 1, 1)
val subtasks = query()
assertEquals(0, subtasks[0].secondarySort)
assertEquals(0, subtasks[1].secondarySort)
assertEquals(1, subtasks[2].secondarySort)
}
private fun newTask(id: Long, order: Long, parent: Long = 0) {
taskDao.insert(TaskMaker.newTask(with(ID, id), with(UUID, UUIDHelper.newUUID())))
googleTaskDao.insert(newGoogleTask(with(LIST, filter.list.remoteId), with(TASK, id), with(PARENT, parent), with(ORDER, order)))
}
private fun query(): List<TaskContainer> = taskDao.fetchTasks {
TaskListQuery.getQuery(preferences, filter, it)
}
override fun inject(component: TestComponent) = component.inject(this)
}

@ -42,4 +42,5 @@ interface TestComponent : ApplicationComponent {
fun inject(tests: LocationDaoTest) fun inject(tests: LocationDaoTest)
fun inject(tests: GoogleTaskListDaoTest) fun inject(tests: GoogleTaskListDaoTest)
fun inject(tests: CaldavTaskAdapterTest) fun inject(tests: CaldavTaskAdapterTest)
fun inject(tests: ManualGoogleTaskQueryTest)
} }

@ -10,17 +10,17 @@ import org.tasks.makers.Maker.make
object GoogleTaskMaker { object GoogleTaskMaker {
val LIST: Property<GoogleTask, String> = newProperty() val LIST: Property<GoogleTask, String> = newProperty()
val ORDER: Property<GoogleTask, Int> = newProperty() val ORDER: Property<GoogleTask, Long> = newProperty()
val REMOTE_ID: Property<GoogleTask, String> = newProperty() val REMOTE_ID: Property<GoogleTask, String> = newProperty()
val TASK: Property<GoogleTask, Int> = newProperty() val TASK: Property<GoogleTask, Long> = newProperty()
val PARENT: Property<GoogleTask, Long> = newProperty() val PARENT: Property<GoogleTask, Long> = newProperty()
private val instantiator = Instantiator<GoogleTask> { private val instantiator = Instantiator<GoogleTask> {
val task = GoogleTask() val task = GoogleTask()
task.listId = it.valueOf(LIST, "1") task.listId = it.valueOf(LIST, "1")
task.order = it.valueOf(ORDER, 0).toLong() task.order = it.valueOf(ORDER, 0)
task.remoteId = it.valueOf(REMOTE_ID, UUIDHelper.newUUID()) task.remoteId = it.valueOf(REMOTE_ID, UUIDHelper.newUUID())
task.task = it.valueOf(TASK, 1).toLong() task.task = it.valueOf(TASK, 1)
task.parent = it.valueOf(PARENT, 0L) task.parent = it.valueOf(PARENT, 0L)
task task
} }

@ -7,6 +7,7 @@ import com.natpryce.makeiteasy.Property.newProperty
import com.natpryce.makeiteasy.PropertyLookup import com.natpryce.makeiteasy.PropertyLookup
import com.natpryce.makeiteasy.PropertyValue import com.natpryce.makeiteasy.PropertyValue
import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task
import com.todoroo.astrid.data.Task.Companion.NO_UUID
import org.tasks.Strings import org.tasks.Strings
import org.tasks.date.DateTimeUtils import org.tasks.date.DateTimeUtils
import org.tasks.makers.Maker.make import org.tasks.makers.Maker.make
@ -29,6 +30,7 @@ object TaskMaker {
private val TITLE: Property<Task, String?> = newProperty() private val TITLE: Property<Task, String?> = newProperty()
private val PRIORITY: Property<Task, Int> = newProperty() private val PRIORITY: Property<Task, Int> = newProperty()
val PARENT: Property<Task, Long> = newProperty() val PARENT: Property<Task, Long> = newProperty()
val UUID: Property<Task, String> = newProperty()
private val instantiator = Instantiator { lookup: PropertyLookup<Task> -> private val instantiator = Instantiator { lookup: PropertyLookup<Task> ->
val task = Task() val task = Task()
@ -84,6 +86,7 @@ object TaskMaker {
if (rrule != null) { if (rrule != null) {
task.setRecurrence(rrule, lookup.valueOf(AFTER_COMPLETE, false)) task.setRecurrence(rrule, lookup.valueOf(AFTER_COMPLETE, false))
} }
task.uuid = lookup.valueOf(UUID, NO_UUID)
val creationTime = lookup.valueOf(CREATION_TIME, DateTimeUtils.newDateTime()) val creationTime = lookup.valueOf(CREATION_TIME, DateTimeUtils.newDateTime())
task.creationDate = creationTime.millis task.creationDate = creationTime.millis
task.parent = lookup.valueOf(PARENT, 0L) task.parent = lookup.valueOf(PARENT, 0L)

Loading…
Cancel
Save