mirror of https://github.com/tasks/tasks
Wrote test for subtasks migration
parent
b230e45491
commit
4146038c77
@ -0,0 +1,55 @@
|
||||
package com.todoroo.astrid.subtasks;
|
||||
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.core.PluginServices;
|
||||
import com.todoroo.astrid.data.Metadata;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SubtasksMigrationTest extends SubtasksTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
Preferences.clear(SubtasksUpdater.ACTIVE_TASKS_ORDER);
|
||||
createLegacyMetadata();
|
||||
}
|
||||
|
||||
/* Starting State (see SubtasksTestCase):
|
||||
*
|
||||
* A
|
||||
* B
|
||||
* C
|
||||
* D
|
||||
* E
|
||||
* F
|
||||
*/
|
||||
private void createLegacyMetadata() {
|
||||
createSubtasksMetadata(1, 1, 0);
|
||||
createSubtasksMetadata(2, 2, 1);
|
||||
createSubtasksMetadata(3, 3, 1);
|
||||
createSubtasksMetadata(4, 4, 2);
|
||||
createSubtasksMetadata(5, 5, 0);
|
||||
createSubtasksMetadata(6, 6, 0);
|
||||
}
|
||||
|
||||
private void createSubtasksMetadata(long taskId, long order, int indent) {
|
||||
Metadata m = new Metadata();
|
||||
m.setValue(Metadata.KEY, SubtasksMetadata.METADATA_KEY);
|
||||
m.setValue(Metadata.TASK, taskId);
|
||||
m.setValue(SubtasksMetadata.TAG, SubtasksMetadata.LIST_ACTIVE_TASKS);
|
||||
m.setValue(SubtasksMetadata.ORDER, order);
|
||||
m.setValue(SubtasksMetadata.INDENT, indent);
|
||||
PluginServices.getMetadataService().save(m);
|
||||
}
|
||||
|
||||
public void testMigration() {
|
||||
SubtasksMetadataMigration migrator = new SubtasksMetadataMigration();
|
||||
migrator.performMigration();
|
||||
|
||||
String newSerializedTree = Preferences.getStringValue(SubtasksUpdater.ACTIVE_TASKS_ORDER).replaceAll("\\s", "");
|
||||
String expectedSerializedTree = DEFAULT_SERIALIZED_TREE.replaceAll("\\s", "");
|
||||
|
||||
assertEquals(expectedSerializedTree, newSerializedTree);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.todoroo.astrid.subtasks;
|
||||
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.api.Filter;
|
||||
import com.todoroo.astrid.core.CoreFilterExposer;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.subtasks.AstridOrderedListUpdater.Node;
|
||||
import com.todoroo.astrid.test.DatabaseTestCase;
|
||||
|
||||
/**
|
||||
* Contains useful methods common to all subtasks tests
|
||||
* @author Sam
|
||||
*
|
||||
*/
|
||||
public class SubtasksTestCase extends DatabaseTestCase {
|
||||
|
||||
protected SubtasksUpdater updater;
|
||||
protected Filter filter;
|
||||
|
||||
/* Starting State:
|
||||
*
|
||||
* A
|
||||
* B
|
||||
* C
|
||||
* D
|
||||
* E
|
||||
* F
|
||||
*/
|
||||
public static final String DEFAULT_SERIALIZED_TREE =
|
||||
"[{\"1\":[{\"2\":[]}, {\"3\":[{\"4\":[]}]}]}, {\"5\":[]}, {\"6\":[]}]";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
filter = CoreFilterExposer.buildInboxFilter(getContext().getResources());
|
||||
Preferences.clear(SubtasksUpdater.ACTIVE_TASKS_ORDER);
|
||||
updater = new SubtasksUpdater();
|
||||
}
|
||||
|
||||
protected void expectParentAndPosition(Task task, Task parent, int positionInParent) {
|
||||
long parentId = (parent == null ? -1 : parent.getId());
|
||||
Node n = updater.findNodeForTask(task.getId());
|
||||
assertNotNull("No node found for task " + task.getValue(Task.TITLE), n);
|
||||
assertEquals("Parent mismatch", parentId, n.parent.taskId);
|
||||
assertEquals("Position mismatch", positionInParent, n.parent.children.indexOf(n));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue