Rewrote subtasks moving tests for the new subtasks scheme

pull/14/head
Sam Bosley 13 years ago
parent cb5c89fece
commit 4cc3838d03

@ -23,7 +23,7 @@ public class SubtasksUpdater extends AstridOrderedListUpdater<TagData> {
public static final String ACTIVE_TASKS_ORDER = "active_tasks_order"; //$NON-NLS-1$ public static final String ACTIVE_TASKS_ORDER = "active_tasks_order"; //$NON-NLS-1$
@Override @Override
protected void initialize(TagData list, Filter filter) { public void initialize(TagData list, Filter filter) {
super.initialize(list, filter); super.initialize(list, filter);
applyToFilter(filter); applyToFilter(filter);
} }

@ -1,160 +1,122 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.subtasks; package com.todoroo.astrid.subtasks;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.CoreFilterExposer; import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.subtasks.AstridOrderedListUpdater.Node;
import com.todoroo.astrid.test.DatabaseTestCase; import com.todoroo.astrid.test.DatabaseTestCase;
@SuppressWarnings("nls")
public class SubtasksMovingTest extends DatabaseTestCase { public class SubtasksMovingTest extends DatabaseTestCase {
private SubtasksUpdater updater; private SubtasksUpdater updater;
private Filter filter; private Filter filter;
private Task A, B, C, D, E, F; private Task A, B, C, D, E, F;
private final String list = SubtasksMetadata.LIST_ACTIVE_TASKS;
/* Starting State:
*
* A
* B
* C
* D
* E
* F
*/
public void testMoveBeforeIntoSelf() {
givenTasksABCDEF();
whenTriggerMoveBefore(A, B); @Override
protected void setUp() throws Exception {
super.setUp();
/* filter = CoreFilterExposer.buildInboxFilter(getContext().getResources());
* A updater = new SubtasksUpdater();
* B createTasks();
* C updater.initializeFromSerializedTree(null, filter, getSerializedTree());
* D
* E
*/
thenExpectMetadataOrderAndIndent(A, 0, 0);
thenExpectMetadataOrderAndIndent(B, 1, 1);
thenExpectMetadataOrderAndIndent(C, 2, 1);
thenExpectMetadataOrderAndIndent(D, 3, 2);
thenExpectMetadataOrderAndIndent(E, 4, 0);
} }
public void testMoveIntoChild() { private void createTasks() {
givenTasksABCDEF(); A = createTask("A");
B = createTask("B");
whenTriggerMoveBefore(A, C); C = createTask("C");
D = createTask("D");
/* E = createTask("E");
* A F = createTask("F");
* B
* C
* D
* E
*/
thenExpectMetadataOrderAndIndent(A, 0, 0);
thenExpectMetadataOrderAndIndent(B, 1, 1);
thenExpectMetadataOrderAndIndent(C, 2, 1);
thenExpectMetadataOrderAndIndent(D, 3, 2);
thenExpectMetadataOrderAndIndent(E, 4, 0);
} }
public void testMoveEndOfChildren() { private Task createTask(String title) {
givenTasksABCDEF(); Task task = new Task();
task.setValue(Task.TITLE, title);
PluginServices.getTaskService().save(task);
return task;
}
whenTriggerMoveBefore(A, E); private void whenTriggerMoveBefore(Task target, Task before) {
long beforeId = (before == null ? -1 : before.getId());
updater.moveTo(null, filter, target.getId(), beforeId);
}
/* private void thenExpectParentAndPosition(Task task, Task parent, int positionInParent) {
* A long parentId = (parent == null ? -1 : parent.getId());
* B Node n = updater.findNodeForTask(task.getId());
* C assertNotNull("No node found for task " + task.getValue(Task.TITLE), n);
* D assertEquals("Parent mismatch", parentId, n.parent.taskId);
* E assertEquals("Position mismatch", positionInParent, n.parent.children.indexOf(n));
*/
thenExpectMetadataOrderAndIndent(A, 0, 0);
thenExpectMetadataOrderAndIndent(B, 1, 1);
thenExpectMetadataOrderAndIndent(C, 2, 1);
thenExpectMetadataOrderAndIndent(D, 3, 2);
thenExpectMetadataOrderAndIndent(E, 4, 0);
} }
public void testMoveAfterChildren() { /* Starting State:
givenTasksABCDEF(); *
* A
* B
* C
* D
* E
* F
*/
private String getSerializedTree() {
return "[{\"1\":[{\"2\":[]}, {\"3\":[{\"4\":[]}]}]}, {\"5\":[]}, {\"6\":[]}]";
}
whenTriggerMoveBefore(A, F); public void testMoveBeforeIntoSelf() { // Should have no effect
whenTriggerMoveBefore(A, B);
/* thenExpectParentAndPosition(A, null, 0);
* E thenExpectParentAndPosition(B, A, 0);
* A thenExpectParentAndPosition(C, A, 1);
* B thenExpectParentAndPosition(D, C, 0);
* C thenExpectParentAndPosition(E, null, 1);
* D thenExpectParentAndPosition(F, null, 2);
*/
thenExpectMetadataOrderAndIndent(E, 0, 0);
thenExpectMetadataOrderAndIndent(A, 1, 0);
thenExpectMetadataOrderAndIndent(B, 2, 1);
thenExpectMetadataOrderAndIndent(C, 3, 1);
thenExpectMetadataOrderAndIndent(D, 4, 2);
} }
// --- helpers public void testMoveIntoDescendant() { // Should have no effect
whenTriggerMoveBefore(A, C);
/** moveTo = null => move to end */ thenExpectParentAndPosition(A, null, 0);
private void whenTriggerMoveBefore(Task target, Task moveTo) { thenExpectParentAndPosition(B, A, 0);
System.err.println("CAN I GET A WITNESS?"); thenExpectParentAndPosition(C, A, 1);
updater.debugPrint(filter, list); thenExpectParentAndPosition(D, C, 0);
updater.moveTo(filter, list, target.getId(), moveTo == null ? -1 : moveTo.getId()); thenExpectParentAndPosition(E, null, 1);
updater.debugPrint(filter, list); thenExpectParentAndPosition(F, null, 2);
} }
private void thenExpectMetadataOrderAndIndent(Task task, long order, int indent) { public void testMoveToEndOfChildren() { // Should have no effect
Metadata metadata = updater.getTaskMetadata(list, task.getId()); whenTriggerMoveBefore(A, E);
assertNotNull("metadata was found", metadata);
assertEquals("order", order, metadata.getValue(SubtasksMetadata.ORDER).longValue()); thenExpectParentAndPosition(A, null, 0);
assertEquals("indentation", indent, (int)metadata.getValue(SubtasksMetadata.INDENT)); thenExpectParentAndPosition(B, A, 0);
thenExpectParentAndPosition(C, A, 1);
thenExpectParentAndPosition(D, C, 0);
thenExpectParentAndPosition(E, null, 1);
thenExpectParentAndPosition(F, null, 2);
} }
@Override public void testStandardMove() {
protected void setUp() throws Exception { whenTriggerMoveBefore(A, F);
super.setUp();
updater = new SubtasksUpdater(); thenExpectParentAndPosition(A, null, 1);
filter = CoreFilterExposer.buildInboxFilter(getContext().getResources()); thenExpectParentAndPosition(B, A, 0);
updater.applySubtasksToFilter(filter, list); thenExpectParentAndPosition(C, A, 1);
thenExpectParentAndPosition(D, C, 0);
thenExpectParentAndPosition(E, null, 0);
thenExpectParentAndPosition(F, null, 2);
} }
private Task[] givenTasksABCDEF() { public void testMoveToEndOfList() {
Task[] tasks = new Task[] { whenTriggerMoveBefore(A, null);
A = createTask("A", 0, 0),
B = createTask("B", 1, 1),
C = createTask("C", 2, 1),
D = createTask("D", 3, 2),
E = createTask("E", 4, 0),
F = createTask("F", 5, 0),
};
return tasks;
}
private Task createTask(String title, long order, int indent) { thenExpectParentAndPosition(A, null, 2);
Task task = new Task(); thenExpectParentAndPosition(B, A, 0);
task.setValue(Task.TITLE, title); thenExpectParentAndPosition(C, A, 1);
PluginServices.getTaskService().save(task); thenExpectParentAndPosition(D, C, 0);
Metadata metadata = updater.createEmptyMetadata(list, task.getId()); thenExpectParentAndPosition(E, null, 0);
metadata.setValue(SubtasksMetadata.ORDER, order); thenExpectParentAndPosition(F, null, 1);
metadata.setValue(SubtasksMetadata.INDENT, indent);
PluginServices.getMetadataService().save(metadata);
return task;
} }
} }

Loading…
Cancel
Save