package guitests;

import static org.junit.Assert.assertTrue;
import static seedu.task.logic.commands.DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS;

import org.junit.Test;

//import org.junit.Test;

import seedu.task.testutil.TestTask;
import seedu.task.testutil.TestUtil;

public class DeleteCommandTest extends TaskManagerGuiTest {

    @Test
    public void delete() {
        try {
            setup();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // delete the first in the list
        TestTask[] currentList = td.getTypicalTasks();
        /*
         * commandBox.runCommand("clear"); String toAdd; for (TestTask t :
         * currentList) { toAdd = "add "; toAdd += t.getTaskName().fullTaskName;
         * if (t.getTaskDate() != null) { toAdd += " d/" +
         * t.getTaskDate().toString(); } if (t.getTaskStartTime() != null) {
         * toAdd += " s/" + t.getTaskStartTime().toString(); } if
         * (t.getTaskEndTime() != null) { toAdd += " e/" +
         * t.getTaskEndTime().toString(); } if (t.getTaskDescription() != null)
         * { toAdd += " m/" + t.getTaskDescription(); }
         * commandBox.runCommand(toAdd); }
         */
        int targetIndex = 1;
        //assertDeleteSuccess(targetIndex, currentList);

        // delete the last in the list
        currentList = TestUtil.removeTaskFromList(currentList, targetIndex);
        targetIndex = currentList.length;
        //assertDeleteSuccess(targetIndex, currentList);

        // delete from the middle of the list
        currentList = TestUtil.removeTaskFromList(currentList, targetIndex);
        targetIndex = currentList.length / 2;
        //assertDeleteSuccess(targetIndex, currentList);

        // invalid index
        commandBox.runCommand("delete " + currentList.length + 1);
        //assertResultMessage("The task index provided is invalid");

    }

    /**
     * Runs the delete command to delete the task at specified index and
     * confirms the result is correct.
     *
     * @param targetIndexOneIndexed
     *            e.g. index 1 to delete the first task in the list,
     * @param currentList
     *            A copy of the current list of tasks (before deletion).
     */
    private void assertDeleteSuccess(int targetIndexOneIndexed, final TestTask[] currentList) {
        TestTask taskToDelete = currentList[targetIndexOneIndexed - 1]; // -1 as
        // array
        // uses
        // zero
        // indexing
        TestTask[] expectedRemainder = TestUtil.removeTaskFromList(currentList, targetIndexOneIndexed);

        commandBox.runCommand("delete " + targetIndexOneIndexed);

        // confirm the list now contains all previous persons except the deleted
        // person
        assertTrue(taskListPanel.isListMatching(expectedRemainder));

        // confirm the result message is correct
        assertResultMessage(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
    }

}

@@ -627,18 +627,36 @@
     
-/*
+int targetIndex = 1;
 %0A       
   * 
@@ -643,35 +643,32 @@
 dex = 1;%0A       
-  *
  commandBox.runC
@@ -687,526 +687,66 @@
 r%22);
- String toAdd; for (TestTask t :%0A         * currentList) %7B toAdd = %22add %22; toAdd += t.getTaskName().fullTaskName;%0A         * if (t.getTaskDate() != null) %7B toAdd += %22 d/%22 +%0A         * t.getTaskDate().toString(); %7D if (t.getTaskStartTime() != null) %7B%0A         * toAdd += %22 s/%22 + t.getTaskStartTime().toString(); %7D if%0A         * (t.getTaskEndTime() != null) %7B toAdd += %22 e/%22 +%0A         * t.getTaskEndTime().toString(); %7D if (t.getTaskDescription() != null)%0A         * %7B toAdd += %22 m/%22 + t.getTaskDescription(); %7D
+%0A        for(int i = 0; i%3CcurrentList.length; i++)
 %0A       
   * 
@@ -741,19 +741,16 @@
 %0A       
-  *
  command
@@ -768,17 +768,40 @@
 and(
-toAdd); %7D
+currentList%5Bi%5D.getAddCommand());
 %0A   
@@ -801,27 +801,24 @@
 ));%0A        
- */
 %0A        int
@@ -818,39 +818,8 @@
     
-int targetIndex = 1;%0A        //
 asse
@@ -1020,34 +1020,32 @@
 length;%0A        
-//
 assertDeleteSucc
@@ -1249,26 +1249,24 @@
  2;%0A        
-//
 assertDelete
@@ -1401,18 +1401,16 @@
         
-//
 assertRe
@@ -1548,23 +1548,16 @@
 ndex and
-%0A     *
  confirm
@@ -1571,16 +1571,23 @@
 esult is
+%0A     *
  correct
@@ -1978,86 +1978,8 @@
  1%5D;
- // -1 as%0A        // array%0A        // uses%0A        // zero%0A        // indexing
 %0A   
@@ -2046,32 +2046,48 @@
 ist(currentList,
+%0A               
  targetIndexOneI
@@ -2243,16 +2243,21 @@
  deleted
+ task
 %0A       
@@ -2263,24 +2263,8 @@
   //
- person%0A        
 asse
@@ -2453,16 +2453,48 @@
 ToDelete
+.getTaskName().fullTaskName+'%5Cn'
 ));%0A    

delete pass