|
|
|
@ -1,47 +1,43 @@
|
|
|
|
package com.todoroo.astrid.gtasks;
|
|
|
|
package com.todoroo.astrid.gtasks;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
import com.todoroo.astrid.api.AstridApiConstants;
|
|
|
|
|
|
|
|
import com.todoroo.astrid.core.PluginServices;
|
|
|
|
import com.todoroo.astrid.core.PluginServices;
|
|
|
|
import com.todoroo.astrid.data.Metadata;
|
|
|
|
import com.todoroo.astrid.data.Metadata;
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
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.astrid.test.DatabaseTestCase;
|
|
|
|
import com.todoroo.gtasks.GoogleTaskListInfo;
|
|
|
|
import com.todoroo.gtasks.GoogleTaskListInfo;
|
|
|
|
|
|
|
|
|
|
|
|
public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
public class GtasksTaskMovingTest extends DatabaseTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired private GtasksListService gtasksListService;
|
|
|
|
@Autowired private GtasksListService gtasksListService;
|
|
|
|
@Autowired private GtasksMetadataService gtasksMetadataService;
|
|
|
|
@Autowired private GtasksMetadataService gtasksMetadataService;
|
|
|
|
|
|
|
|
@Autowired private GtasksTaskListUpdater gtasksTaskListUpdater;
|
|
|
|
|
|
|
|
|
|
|
|
private Task A, B, C, D, E, F;
|
|
|
|
private Task A, B, C, D, E, F;
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveUpFromListTop() {
|
|
|
|
/* Starting State:
|
|
|
|
givenTasksABCDEF();
|
|
|
|
*
|
|
|
|
|
|
|
|
* A
|
|
|
|
whenTrigger(A, new GtasksMoveUpAction());
|
|
|
|
* B
|
|
|
|
|
|
|
|
* C
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
* D
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 1, 1);
|
|
|
|
* E
|
|
|
|
}
|
|
|
|
* F
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveDownFromListBottom() {
|
|
|
|
public void testMoveDownFromListBottom() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(F, new GtasksMoveDownAction());
|
|
|
|
whenTriggerMove(F, null);
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 4, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 4, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 5, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 5, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveDownSimple() {
|
|
|
|
public void testMoveDownToListbottom() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(E, new GtasksMoveDownAction());
|
|
|
|
whenTriggerMove(E, null);
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 5, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 5, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 4, 00);
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 4, 00);
|
|
|
|
@ -50,7 +46,7 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
public void testMoveUpSimple() {
|
|
|
|
public void testMoveUpSimple() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(F, new GtasksMoveUpAction());
|
|
|
|
whenTriggerMove(F, E);
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 5, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 5, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 4, 00);
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 4, 00);
|
|
|
|
@ -59,7 +55,7 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
public void testMoveWithSubtasks() {
|
|
|
|
public void testMoveWithSubtasks() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(C, new GtasksMoveUpAction());
|
|
|
|
whenTriggerMove(C, B);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* A
|
|
|
|
* A
|
|
|
|
@ -72,44 +68,39 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 3, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 3, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 1, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 1, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 2, 2);
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 2, 2);
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(C, new GtasksMoveDownAction());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectOriginalIndentAndOrder();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveThroughSubtasks() {
|
|
|
|
public void testMoveThroughSubtasks() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(B, new GtasksMoveDownAction());
|
|
|
|
whenTriggerMove(B, E);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* A
|
|
|
|
* A
|
|
|
|
* C
|
|
|
|
* C
|
|
|
|
* D
|
|
|
|
* D
|
|
|
|
* B
|
|
|
|
* B
|
|
|
|
|
|
|
|
* E
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 3, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 3, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 1, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 1, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 2, 2);
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 2, 2);
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(B, new GtasksMoveUpAction());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectOriginalIndentAndOrder();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveUpAboveParent() {
|
|
|
|
public void testMoveUpAboveParent() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(B, new GtasksMoveUpAction());
|
|
|
|
whenTriggerMove(B, A);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* B
|
|
|
|
* B
|
|
|
|
* A
|
|
|
|
* A
|
|
|
|
* C
|
|
|
|
* C
|
|
|
|
* D
|
|
|
|
* D
|
|
|
|
|
|
|
|
* E
|
|
|
|
|
|
|
|
* F
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 1, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 1, 0);
|
|
|
|
@ -117,10 +108,10 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 2, 1);
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 2, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveDownFromChildren() {
|
|
|
|
public void testMoveDownWithChildren() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(C, new GtasksMoveDownAction());
|
|
|
|
whenTriggerMove(C, F);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* A
|
|
|
|
* A
|
|
|
|
@ -128,6 +119,7 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
* E
|
|
|
|
* E
|
|
|
|
* C
|
|
|
|
* C
|
|
|
|
* D
|
|
|
|
* D
|
|
|
|
|
|
|
|
* F
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
@ -140,7 +132,7 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
public void testMoveDownIndentingTwice() {
|
|
|
|
public void testMoveDownIndentingTwice() {
|
|
|
|
givenTasksABCDEF();
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
whenTrigger(D, new GtasksMoveDownAction());
|
|
|
|
whenTriggerMove(D, F);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* A
|
|
|
|
* A
|
|
|
|
@ -157,13 +149,72 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 3, 0);
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 3, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveUpMultiple() {
|
|
|
|
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
whenTriggerMove(C, A);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* C
|
|
|
|
|
|
|
|
* D
|
|
|
|
|
|
|
|
* A
|
|
|
|
|
|
|
|
* B
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 2, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 3, 1);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 0, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 1, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveUpIntoSublist() {
|
|
|
|
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
whenTriggerMove(F, D);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* A
|
|
|
|
|
|
|
|
* B
|
|
|
|
|
|
|
|
* C
|
|
|
|
|
|
|
|
* F
|
|
|
|
|
|
|
|
* D
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 1, 1);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 2, 1);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 4, 2);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 5, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 3, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testMoveDownMultiple() {
|
|
|
|
|
|
|
|
givenTasksABCDEF();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
whenTriggerMove(B, F);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* A
|
|
|
|
|
|
|
|
* C
|
|
|
|
|
|
|
|
* D
|
|
|
|
|
|
|
|
* E
|
|
|
|
|
|
|
|
* B
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(A, 0, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(B, 4, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(C, 1, 1);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(D, 2, 2);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(E, 3, 0);
|
|
|
|
|
|
|
|
thenExpectMetadataIndentAndOrder(F, 5, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- helpers
|
|
|
|
// --- helpers
|
|
|
|
|
|
|
|
|
|
|
|
private void whenTrigger(Task task, BroadcastReceiver action) {
|
|
|
|
/** moveTo = null => move to end */
|
|
|
|
Intent intent = new Intent(AstridApiConstants.ACTION_TASK_CONTEXT_MENU);
|
|
|
|
private void whenTriggerMove(Task target, Task moveTo) {
|
|
|
|
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
|
|
|
|
gtasksTaskListUpdater.moveTo("1", target.getId(), moveTo == null ? -1 : moveTo.getId());
|
|
|
|
action.onReceive(getContext(), intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void thenExpectMetadataIndentAndOrder(Task task, int order, int indent) {
|
|
|
|
private void thenExpectMetadataIndentAndOrder(Task task, int order, int indent) {
|
|
|
|
@ -173,15 +224,6 @@ public class GtasksOrderActionTest extends DatabaseTestCase {
|
|
|
|
assertEquals("indentation", indent, (int)metadata.getValue(GtasksMetadata.INDENT));
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
super.setUp();
|