package guitests;

import guitests.guihandles.TaskCardHandle;
import org.junit.Test;
import seedu.address.commons.core.Messages;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

import static org.junit.Assert.assertTrue;

//@@author A0142325R
public class AddCommandTest extends TaskManagerGuiTest {

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

        // add another person
        taskToAdd = td.workshop;
        // currentList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertAddSuccess(taskToAdd, currentList);

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

        // add project to current list with flexi command
        taskToAdd = td.project;
        assertFlexiAddSuccess(taskToAdd, td.friend);

        // invalid command
        commandBox.runCommand("adds Johnny");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

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

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

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

    private void assertFlexiAddSuccess(TestTask personToAdd, TestTask... currentList) {
        commandBox.runCommand(personToAdd.getFlexiAddCommand());

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

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

}

@@ -251,28 +251,119 @@
 e;%0A%0A
-//@@author A0142325R
+import org.junit.Before;%0A%0A//@@author A0142325R%0A%0A/**%0A * test for add command in gui%0A * @author LiXiaowei%0A *%0A */%0A
 %0Apub
@@ -420,87 +420,119 @@
 t %7B%0A
+    
 %0A    
-@
 Test
-%0A    public void add() %7B%0A        // add one person%0A        TestTask%5B%5D
+Task%5B%5D currentList;%0A    TestTask taskToAdd;%0A    %0A    @Before%0A    public void setUpLists()%7B%0A       
  cur
@@ -539,19 +539,17 @@
 rentList
- = 
+=
 td.getTy
@@ -566,28 +566,221 @@
 ();%0A    
+%7D%0A
     
-TestTask
+%0A    //------------------------------valid cases---------------------------------------------%0A    %0A    //add event to list%0A    %0A    @Test%0A    public void addEventToList_successful()%7B%0A        %0A       
  taskToA
@@ -921,38 +921,102 @@
 d);%0A
+    %7D
 %0A    
+%0A
     //
- 
 add a
-nother person
+ task to list%0A    %0A    @Test%0A    public void addTaskToList_successful()%7B
 %0A   
@@ -1173,26 +1173,48 @@
 t);%0A
-%0A
     
+    %0A    %7D%0A    %0A
     //
- 
 add 
-to
+item to an
  emp
@@ -1217,24 +1217,84 @@
  empty list%0A
+    %0A    @Test%0A    public void addToEmptyList_successful()%7B%0A
         comm
@@ -1362,66 +1362,131 @@
 d);%0A
-%0A
      
+   %0A    %7D%0A    %0A
    
+ 
 //
- add project to current list with f
+use flexi add command%0A    %0A    @Test%0A    public void addF
 lexi
- c
+C
 ommand
+Format_successful()%7B%0A        
 %0A   
@@ -1571,150 +1571,478 @@
 d);%0A
+    %7D
 %0A    
+%0A
     //
- invalid command%0A        commandBox.runCommand(%22adds Johnny%22);%0A        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);%0A    %7D
+-----------------------------invalid cases--------------------------------------------%0A    %0A    //invalid command%0A    %0A    @Test%0A    public void addInvalidArgsFormat_fail()%7B%0A        %0A        commandBox.runCommand(%22adds Johnny%22);%0A        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);%0A    %7D%0A    %0A    %0A    /**%0A     * assert add success for general addCommand with correct argument order%0A     * @param personToAdd%0A     * @param currentList%0A     */%0A
 %0A%0A  
@@ -2632,16 +2632,172 @@
 );%0A    %7D
+%0A    %0A    /**%0A     * assert add success for flexi add command with arguments in any random order%0A     * @param personToAdd%0A     * @param currentList%0A     */
 %0A%0A    pr

refactor add command test in guitest