diff --git a/app/src/androidTest/java/org/tasks/data/ManualGoogleTaskQueryTest.kt b/app/src/androidTest/java/org/tasks/data/ManualGoogleTaskQueryTest.kt new file mode 100644 index 000000000..2f93b25e2 --- /dev/null +++ b/app/src/androidTest/java/org/tasks/data/ManualGoogleTaskQueryTest.kt @@ -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 = taskDao.fetchTasks { + TaskListQuery.getQuery(preferences, filter, it) + } + + override fun inject(component: TestComponent) = component.inject(this) +} \ No newline at end of file diff --git a/app/src/androidTest/java/org/tasks/injection/TestComponent.kt b/app/src/androidTest/java/org/tasks/injection/TestComponent.kt index 492b09729..acd32b05b 100644 --- a/app/src/androidTest/java/org/tasks/injection/TestComponent.kt +++ b/app/src/androidTest/java/org/tasks/injection/TestComponent.kt @@ -42,4 +42,5 @@ interface TestComponent : ApplicationComponent { fun inject(tests: LocationDaoTest) fun inject(tests: GoogleTaskListDaoTest) fun inject(tests: CaldavTaskAdapterTest) + fun inject(tests: ManualGoogleTaskQueryTest) } \ No newline at end of file diff --git a/app/src/commonTest/java/org/tasks/makers/GoogleTaskMaker.kt b/app/src/commonTest/java/org/tasks/makers/GoogleTaskMaker.kt index b09869466..5123c4300 100644 --- a/app/src/commonTest/java/org/tasks/makers/GoogleTaskMaker.kt +++ b/app/src/commonTest/java/org/tasks/makers/GoogleTaskMaker.kt @@ -10,17 +10,17 @@ import org.tasks.makers.Maker.make object GoogleTaskMaker { val LIST: Property = newProperty() - val ORDER: Property = newProperty() + val ORDER: Property = newProperty() val REMOTE_ID: Property = newProperty() - val TASK: Property = newProperty() + val TASK: Property = newProperty() val PARENT: Property = newProperty() private val instantiator = Instantiator { val task = GoogleTask() 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.task = it.valueOf(TASK, 1).toLong() + task.task = it.valueOf(TASK, 1) task.parent = it.valueOf(PARENT, 0L) task } diff --git a/app/src/commonTest/java/org/tasks/makers/TaskMaker.kt b/app/src/commonTest/java/org/tasks/makers/TaskMaker.kt index 1cc3ccaf4..20540169e 100644 --- a/app/src/commonTest/java/org/tasks/makers/TaskMaker.kt +++ b/app/src/commonTest/java/org/tasks/makers/TaskMaker.kt @@ -7,6 +7,7 @@ import com.natpryce.makeiteasy.Property.newProperty import com.natpryce.makeiteasy.PropertyLookup import com.natpryce.makeiteasy.PropertyValue import com.todoroo.astrid.data.Task +import com.todoroo.astrid.data.Task.Companion.NO_UUID import org.tasks.Strings import org.tasks.date.DateTimeUtils import org.tasks.makers.Maker.make @@ -29,6 +30,7 @@ object TaskMaker { private val TITLE: Property = newProperty() private val PRIORITY: Property = newProperty() val PARENT: Property = newProperty() + val UUID: Property = newProperty() private val instantiator = Instantiator { lookup: PropertyLookup -> val task = Task() @@ -84,6 +86,7 @@ object TaskMaker { if (rrule != null) { task.setRecurrence(rrule, lookup.valueOf(AFTER_COMPLETE, false)) } + task.uuid = lookup.valueOf(UUID, NO_UUID) val creationTime = lookup.valueOf(CREATION_TIME, DateTimeUtils.newDateTime()) task.creationDate = creationTime.millis task.parent = lookup.valueOf(PARENT, 0L)