package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

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

public class AddCommandTest extends TaskBossGuiTest {

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

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

        //add another task using short command
        commandBox.runCommand(td.kelvin.getShortAddCommand());
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(currentList));

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

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

        //invalid command
        commandBox.runCommand("adds Johnny");
        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 tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));
    }

}

@@ -522,32 +522,39 @@
 ssertAddSuccess(
+false, 
 taskToAdd, curre
@@ -554,32 +554,32 @@
 , currentList);%0A
-
         currentL
@@ -714,16 +714,23 @@
 Success(
+false, 
 taskToAd
@@ -877,60 +877,84 @@
     
-commandBox.runCommand(td.kelvin.getShortAddCommand()
+taskToAdd = td.kelvin;%0A        assertAddSuccess(true, taskToAdd, currentList
 );%0A 
@@ -1026,71 +1026,8 @@
 dd);
-%0A        assertTrue(taskListPanel.isListMatching(currentList));
 %0A%0A  
@@ -1330,16 +1330,23 @@
 Success(
+false, 
 td.alice
@@ -1525,16 +1525,40 @@
 Success(
+boolean isShortCommand, 
 TestTask
@@ -1592,24 +1592,58 @@
 rentList) %7B%0A
+        if (isShortCommand) %7B%0A    
         comm
@@ -1669,24 +1669,29 @@
 askToAdd.get
+Short
 AddCommand()
@@ -1692,16 +1692,105 @@
 mand());
+%0A        %7D else %7B%0A            commandBox.runCommand(taskToAdd.getAddCommand());%0A        %7D
 %0A%0A      

Fix and improve AddCommandTest