package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import guitests.guihandles.TaskCardHandle;
import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.AddCommand;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class AddCommandTest extends TaskManagerGuiTest {

    @Test
    public void add() {
        //add task by name only
    		TestTask[] currentList = td.getTypicalTasks();
        TestTask taskToAdd = td.assignment;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add another task
        taskToAdd = td.date;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add duplicate task
        commandBox.runCommand(td.date.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));

        //add to empty list
        commandBox.runCommand("clear");
        assertAddSuccess(td.gym);

        //invalid command
        commandBox.runCommand("adds homework");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        commandBox.runCommand("add p/important homework");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
        commandBox.runCommand(taskToAdd.getAddCommand());

        //confirm the new card contains the right data
        TaskCardHandle addedCard = taskListPanel.navigateToTask(taskToAdd.getName().fullName);
        assertMatching(taskToAdd, addedCard);

        //confirm the list now contains all previous persons plus the new person
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));
    }

}

@@ -1147,15 +1147,15 @@
   //
-invalid
+unknown
  com
@@ -1266,24 +1266,265 @@
 N_COMMAND);%0A
+       %0A        //invalid command, task must have a name%0A        commandBox.runCommand(%22add p/important%22);%0A        assertResultMessage(Messages.MESSAGE_INVALID_COMMAND_FORMAT);%0A      //invalid command, name should be the first field entered%0A
         comm
@@ -1611,39 +1611,39 @@
 ges.MESSAGE_
-UNKNOWN
+INVALID
 _COMMAND
 );%0A    %7D%0A%0A  
@@ -1626,24 +1626,31 @@
 ALID_COMMAND
+_FORMAT
 );%0A    %7D%0A%0A  
@@ -2218,11 +2218,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Modify addCommandTest