package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

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

public class AddCommandTest extends TaskManagerGuiTest {

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

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

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

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

        //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().name);
        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));
    }

}

@@ -391,24 +391,57 @@
 dd one task%0A
+        System.err.println(%221%22);%0A
         Test
@@ -483,16 +483,16 @@
 asks();%0A
-
         
@@ -639,32 +639,65 @@
 ist, taskToAdd);
+%0A        System.err.println(%222%22);
 %0A%0A        //add 
@@ -863,16 +863,49 @@
 kToAdd);
+%0A        System.err.println(%223%22);
 %0A%0A      
@@ -1115,16 +1115,49 @@
 tList));
+%0A        System.err.println(%224%22);
 %0A%0A      
@@ -1260,16 +1260,49 @@
 tation);
+%0A        System.err.println(%225%22);
 %0A%0A      
@@ -1430,16 +1430,49 @@
 MMAND);%0A
+        System.err.println(%226%22);%0A
     %7D%0A%0A 
@@ -1550,16 +1550,50 @@
 tList) %7B
+%0A%0A        System.err.println(%22a%22);
 %0A       
@@ -1640,24 +1640,58 @@
 ommand());%0A%0A
+%0A        System.err.println(%22b%22);%0A
         //co
@@ -1867,24 +1867,58 @@
 ddedCard);%0A%0A
+        System.err.println(%22c%22);%0A%0A
         //co
@@ -2057,32 +2057,32 @@
 st, taskToAdd);%0A
-
         assertTr
@@ -2124,22 +2124,56 @@
 ectedList));
+%0A%0A        System.err.println(%22d%22);
 %0A    %7D%0A%0A%7D%0A

test travis