Wrote gtasks order action test, added new indent action tests, and fixed detail exposer test

pull/14/head
Tim Su 14 years ago
parent de8bff5b81
commit 515b3dcf07

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata;
@ -115,6 +116,7 @@ public class GtasksDetailExposerTest extends DatabaseTestCase {
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
detail = null;
new GtasksDetailExposer().onReceive(getContext(), intent);
AndroidUtilities.sleepDeep(500);
}
private void givenLoggedInStatus(boolean status) {

@ -26,8 +26,17 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(1);
}
public void testIndentWithMetadataButNoOtherTasks() {
givenTask(taskWithMetadata(0, 0));
whenTrigger(new GtasksIncreaseIndentAction());
thenExpectIndentationLevel(0);
}
public void testIndentWithMetadata() {
givenTask(taskWithMetadata(0));
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
whenTrigger(new GtasksIncreaseIndentAction());
@ -35,7 +44,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
}
public void testDeindentWithMetadata() {
givenTask(taskWithMetadata(1));
givenTask(taskWithMetadata(0, 1));
whenTrigger(new GtasksDecreaseIndentAction());
@ -51,20 +60,67 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
}
public void testDeindentWhenAlreadyZero() {
givenTask(taskWithMetadata(0));
givenTask(taskWithMetadata(0, 0));
whenTrigger(new GtasksDecreaseIndentAction());
thenExpectIndentationLevel(0);
}
public void testIndentWithChildren() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
Task child = taskWithMetadata(2, 1);
whenTrigger(new GtasksIncreaseIndentAction());
thenExpectIndentationLevel(1);
thenExpectIndentationLevel(child, 2);
}
public void testDeindentWithChildren() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 1));
Task child = taskWithMetadata(2, 2);
whenTrigger(new GtasksDecreaseIndentAction());
thenExpectIndentationLevel(0);
thenExpectIndentationLevel(child, 1);
}
public void testIndentWithSiblings() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 1));
Task sibling = taskWithMetadata(2, 1);
whenTrigger(new GtasksIncreaseIndentAction());
thenExpectIndentationLevel(2);
thenExpectIndentationLevel(sibling, 1);
}
public void testIndentWithChildrensChildren() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
Task child = taskWithMetadata(2, 1);
Task grandchild = taskWithMetadata(3, 2);
whenTrigger(new GtasksIncreaseIndentAction());
thenExpectIndentationLevel(1);
thenExpectIndentationLevel(child, 2);
thenExpectIndentationLevel(grandchild, 3);
}
// --- helpers
private Task taskWithMetadata(int indentation) {
private Task taskWithMetadata(int order, int indentation) {
Task task = new Task();
PluginServices.getTaskService().save(task);
Metadata metadata = GtasksMetadata.createEmptyMetadata(task.getId());
metadata.setValue(GtasksMetadata.INDENT, indentation);
metadata.setValue(GtasksMetadata.ORDER, order);
metadata.setValue(GtasksMetadata.LIST_ID, "list");
metadata.setValue(Metadata.TASK, task.getId());
PluginServices.getMetadataService().save(metadata);
@ -72,14 +128,17 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
}
private void thenExpectIndentationLevel(int expected) {
Metadata metadata = gtasksMetadataService.getTaskMetadata(task.getId());
thenExpectIndentationLevel(task, expected);
}
private void thenExpectIndentationLevel(Task targetTask, int expected) {
Metadata metadata = gtasksMetadataService.getTaskMetadata(targetTask.getId());
assertNotNull("task has metadata", metadata);
int indentation = metadata.getValue(GtasksMetadata.INDENT);
assertTrue("indentation: " + indentation,
indentation == expected);
}
private void whenTrigger(BroadcastReceiver action) {
Intent intent = new Intent(AstridApiConstants.ACTION_TASK_CONTEXT_MENU);
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());

@ -0,0 +1,228 @@
package com.todoroo.astrid.gtasks;
import android.content.BroadcastReceiver;
import android.content.Intent;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksOrderAction.GtasksMoveDownAction;
import com.todoroo.astrid.gtasks.GtasksOrderAction.GtasksMoveUpAction;
import com.todoroo.astrid.test.DatabaseTestCase;
import com.todoroo.gtasks.GoogleTaskListInfo;
public class GtasksOrderActionTest extends DatabaseTestCase {
@Autowired private GtasksListService gtasksListService;
@Autowired private GtasksMetadataService gtasksMetadataService;
private Task A, B, C, D, E, F;
public void testMoveUpFromListTop() {
givenTasksABCDEF();
whenTrigger(A, new GtasksMoveUpAction());
thenExpectMetadataIndentAndOrder(A, 0, 0);
thenExpectMetadataIndentAndOrder(B, 1, 1);
}
public void testMoveDownFromListBottom() {
givenTasksABCDEF();
whenTrigger(F, new GtasksMoveDownAction());
thenExpectMetadataIndentAndOrder(E, 4, 0);
thenExpectMetadataIndentAndOrder(F, 5, 0);
}
public void testMoveDownSimple() {
givenTasksABCDEF();
whenTrigger(E, new GtasksMoveDownAction());
thenExpectMetadataIndentAndOrder(E, 5, 0);
thenExpectMetadataIndentAndOrder(F, 4, 00);
}
public void testMoveUpSimple() {
givenTasksABCDEF();
whenTrigger(F, new GtasksMoveUpAction());
thenExpectMetadataIndentAndOrder(E, 5, 0);
thenExpectMetadataIndentAndOrder(F, 4, 00);
}
public void testMoveWithSubtasks() {
givenTasksABCDEF();
whenTrigger(C, new GtasksMoveUpAction());
/*
* A
* C
* D
* B
*/
thenExpectMetadataIndentAndOrder(A, 0, 0);
thenExpectMetadataIndentAndOrder(B, 3, 1);
thenExpectMetadataIndentAndOrder(C, 1, 1);
thenExpectMetadataIndentAndOrder(D, 2, 2);
whenTrigger(C, new GtasksMoveDownAction());
thenExpectOriginalIndentAndOrder();
}
public void testMoveDownThroughSubtasks() {
givenTasksABCDEF();
whenTrigger(B, new GtasksMoveDownAction());
/*
* A
* C
* D
* B
*/
thenExpectMetadataIndentAndOrder(A, 0, 0);
thenExpectMetadataIndentAndOrder(B, 3, 1);
thenExpectMetadataIndentAndOrder(C, 1, 1);
thenExpectMetadataIndentAndOrder(D, 2, 2);
whenTrigger(B, new GtasksMoveUpAction());
thenExpectOriginalIndentAndOrder();
}
public void testMoveAboveParent() {
givenTasksABCDEF();
whenTrigger(B, new GtasksMoveUpAction());
/*
* B
* A
* C
* D
*/
thenExpectMetadataIndentAndOrder(A, 1, 0);
thenExpectMetadataIndentAndOrder(B, 0, 0);
thenExpectMetadataIndentAndOrder(C, 2, 1);
}
public void testMoveDownFromChildren() {
givenTasksABCDEF();
whenTrigger(C, new GtasksMoveDownAction());
/*
* A
* B
* E
* C
* D
*/
thenExpectMetadataIndentAndOrder(A, 0, 0);
thenExpectMetadataIndentAndOrder(B, 1, 1);
thenExpectMetadataIndentAndOrder(C, 3, 0);
thenExpectMetadataIndentAndOrder(D, 4, 1);
thenExpectMetadataIndentAndOrder(E, 2, 0);
}
public void testMoveDownIndentingTwice() {
givenTasksABCDEF();
whenTrigger(D, new GtasksMoveDownAction());
/*
* A
* B
* C
* E
* D
*/
thenExpectMetadataIndentAndOrder(A, 0, 0);
thenExpectMetadataIndentAndOrder(B, 1, 1);
thenExpectMetadataIndentAndOrder(C, 2, 1);
thenExpectMetadataIndentAndOrder(D, 4, 0);
thenExpectMetadataIndentAndOrder(E, 3, 0);
}
// --- helpers
private void whenTrigger(Task task, BroadcastReceiver action) {
Intent intent = new Intent(AstridApiConstants.ACTION_TASK_CONTEXT_MENU);
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
action.onReceive(getContext(), intent);
}
private void thenExpectMetadataIndentAndOrder(Task task, int order, int indent) {
Metadata metadata = gtasksMetadataService.getTaskMetadata(task.getId());
assertNotNull("metadata was found", metadata);
assertEquals("order", order, (int)metadata.getValue(GtasksMetadata.ORDER));
assertEquals("indentation", indent, (int)metadata.getValue(GtasksMetadata.INDENT));
}
private void thenExpectOriginalIndentAndOrder() {
thenExpectMetadataIndentAndOrder(A, 0, 0);
thenExpectMetadataIndentAndOrder(B, 1, 1);
thenExpectMetadataIndentAndOrder(C, 2, 1);
thenExpectMetadataIndentAndOrder(D, 3, 2);
thenExpectMetadataIndentAndOrder(E, 4, 0);
thenExpectMetadataIndentAndOrder(F, 5, 0);
}
@Override
protected void setUp() throws Exception {
super.setUp();
GoogleTaskListInfo[] lists = new GoogleTaskListInfo[1];
GoogleTaskListInfo list = new GoogleTaskListInfo("1", "Tim's Tasks");
lists[0] = list;
gtasksListService.updateLists(lists);
}
/**
* A
* B
* C
* D
* E
* F
*/
private Task[] givenTasksABCDEF() {
return new Task[] {
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),
};
}
private Task createTask(String title, int order, int indent) {
Task task = new Task();
task.setValue(Task.TITLE, title);
PluginServices.getTaskService().save(task);
Metadata metadata = GtasksMetadata.createEmptyMetadata(task.getId());
metadata.setValue(GtasksMetadata.LIST_ID, "1");
if(order != GtasksMetadata.VALUE_UNSET)
metadata.setValue(GtasksMetadata.ORDER, order);
if(indent != GtasksMetadata.VALUE_UNSET)
metadata.setValue(GtasksMetadata.INDENT, indent);
PluginServices.getMetadataService().save(metadata);
return task;
}
}
Loading…
Cancel
Save