package guitests;

import static org.junit.Assert.*;
import static seedu.taskitty.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import org.junit.Test;

import guitests.guihandles.TaskCardHandle;
import seedu.taskitty.commons.core.Messages;
import seedu.taskitty.logic.commands.AddCommand;
import seedu.taskitty.logic.commands.EditCommand;
import seedu.taskitty.testutil.TestTask;
import seedu.taskitty.testutil.TestTaskList;

public class EditCommandTest extends TaskManagerGuiTest {

    @Test
    public void edit() {
        //edit one task
        TestTaskList currentList = new TestTaskList(td.getTypicalTasks());
        
        TestTask taskToEdit = td.todo;
        int targetIndex = currentList.size("t");
        assertEditSuccess(taskToEdit, targetIndex, "t", currentList);

        //edit another task
        taskToEdit = td.deadline;
        targetIndex = currentList.size("d");
        assertEditSuccess(taskToEdit, targetIndex, "d", currentList);
        
        //edit another task
        taskToEdit = td.event;
        targetIndex = currentList.size("e");
        assertEditSuccess(taskToEdit, targetIndex, "e", currentList);
        
        //edit into duplicate task
        commandBox.runCommand(td.deadline.getEditCommand(targetIndex - 1, "e"));
        assertResultMessage(EditCommand.MESSAGE_DUPLICATE_TASK);
        assertTrue(currentList.isListMatching(taskListPanel));

        //invalid command
        commandBox.runCommand("edits party");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        
        commandBox.runCommand("edit 1");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
        
        commandBox.runCommand("edit 1 deadline 09/09/2016 5pm");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
        
        commandBox.runCommand("edit d deadline 09/09/2016 5pm");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
        
        //invalid index
        targetIndex = currentList.size("t") + 1;
        commandBox.runCommand(td.todo.getEditCommand(targetIndex, "t"));
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        assertTrue(currentList.isListMatching(taskListPanel));
    }

    private void assertEditSuccess(TestTask taskToEdit, int index, String category, TestTaskList currentList) {
        commandBox.runCommand(taskToEdit.getEditCommand(index, category));

        //confirm the new card contains the right data
        TaskCardHandle editedCard = taskListPanel.navigateToTask(taskToEdit.getName().fullName, taskToEdit.getPeriod().getNumArgs());
        assertMatching(taskToEdit, editedCard);

        //confirm the list now contains all previous persons plus the new person
        currentList.editTaskFromList(index - 1, category, taskToEdit);
        assertTrue(currentList.isListMatching(taskListPanel));
    }

}

@@ -246,57 +246,8 @@
 es;%0A
-import seedu.taskitty.logic.commands.AddCommand;%0A
 impo
@@ -485,23 +485,8 @@
     
-//edit one task
 %0A   
@@ -558,32 +558,153 @@
 ks());%0A        %0A
+        //Tests for edits that remove or add parameters - change between categories%0A        //edit from deadline to todo%0A
         TestTask
@@ -770,17 +770,17 @@
 t.size(%22
-t
+d
 %22);%0A    
@@ -827,17 +827,17 @@
 Index, %22
-t
+d
 %22, curre
@@ -857,36 +857,46 @@
      //edit 
-another task
+from event to deadline
 %0A        tas
@@ -950,33 +950,33 @@
 rrentList.size(%22
-d
+e
 %22);%0A        asse
@@ -1007,33 +1007,33 @@
 , targetIndex, %22
-d
+e
 %22, currentList);
@@ -1061,20 +1061,26 @@
 dit 
-another task
+from todo to event
 %0A   
@@ -1139,33 +1139,33 @@
 rrentList.size(%22
-e
+t
 %22);%0A        asse
@@ -1196,33 +1196,33 @@
 , targetIndex, %22
-e
+t
 %22, currentList);
@@ -3066,11 +3066,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Update EditTest cases