package guitests;

import static org.junit.Assert.*;

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("d");
        assertEditSuccess(taskToEdit, targetIndex, "d", currentList);

        //edit another task
        taskToEdit = td.deadline;
        targetIndex = currentList.size("e");
        assertEditSuccess(taskToEdit, targetIndex, "e", currentList);
        
        //edit another task
        taskToEdit = td.event;
        targetIndex = currentList.size("t");
        assertEditSuccess(taskToEdit, targetIndex, "t", 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);
    }

    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));
    }

}

@@ -630,17 +630,17 @@
 t.size(%22
-d
+t
 %22);%0A    
@@ -687,17 +687,17 @@
 Index, %22
-d
+t
 %22, curre
@@ -808,17 +808,17 @@
 t.size(%22
-e
+d
 %22);%0A    
@@ -865,17 +865,17 @@
 Index, %22
-e
+d
 %22, curre
@@ -983,33 +983,33 @@
 rrentList.size(%22
-t
+e
 %22);%0A        asse
@@ -1040,33 +1040,33 @@
 , targetIndex, %22
-t
+e
 %22, currentList);
@@ -1185,17 +1185,17 @@
 x - 1, %22
-e
+d
 %22));%0A   

Fix typo in EditCommandTest