//@@author A0147996E
package guitests;

import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.AddCommand.COMMAND_ADD;
import static seedu.address.logic.commands.AddCommand.MESSAGE_SUCCESS;

import org.junit.Before;
import org.junit.Test;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CommandFormatter;
import seedu.address.testutil.TestEvent;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class AddCommandTest extends TaskManagerGuiTest {
    private TestTask[] currentList = {};

    @Before
    public void setUp() {
        String initCommand = "clear";
        commandBox.runCommand(initCommand);
    }

    @Test
    public void add_addTypicalTasks_addSuccess() {
        //add a floating task with name only
        TestTask taskToAdd = td.shopping2;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add a task with all fields specified
        taskToAdd = td.date;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);
    }

    @Test
    public void add_addInvalidDuplicate_failure() {
        //duplicate task tests
        commandBox.runCommand(td.date.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));
    }

    @Test
    public void add_addValidDuplicates_success() {
        TestTask taskToAdd = td.date2;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        taskToAdd = td.date3;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        taskToAdd = td.date4;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);
    }

    @Test
    public void add_addEventsWithSomeDuplicateFields_success() {
        TestEvent eventToAdd = te.date;
        assertAddSuccess(eventToAdd, currentList);
        currentList = (TestUtil.addEventsToList(currentList, eventToAdd));

        eventToAdd = te.date2;
        assertAddSuccess(eventToAdd, currentList);
        currentList = (TestUtil.addEventsToList(currentList, eventToAdd));

        eventToAdd = te.date3;
        assertAddSuccess(eventToAdd, currentList);
        currentList = (TestUtil.addEventsToList(currentList, eventToAdd));
    }
    @Test
    public void add_addRecurringTask_success() {
        //TODO: set up typical recurring tests
    }

    @Test
    public void addCommand_invalidCommandFormat_failure () {
        commandBox.runCommand("adds homework");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);

        commandBox.runCommand("add p/important");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));

        commandBox.runCommand("add p/important homework");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
    }

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

        //AssertTrue if can navigate to the task card in current list view that matches the taskToAdd
        assertTrue(taskListPanel.navigateToTask(taskToAdd));

        //confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(taskListPanel.isListMatching(expectedList));
        assertResultMessage(CommandFormatter.undoFormatter(
                String.format(MESSAGE_SUCCESS, taskToAdd.getName()), COMMAND_ADD));
    }
}

@@ -451,16 +451,65 @@
 tEvent;%0A
+import seedu.address.testutil.TestRecurringTask;%0A
 import s
@@ -844,20 +844,20 @@
 _add
-Typical
+Floating
 Task
-s
 _add
@@ -872,53 +872,8 @@
 ) %7B%0A
-        //add a floating task with name only%0A
     
@@ -1024,33 +1024,111 @@
 st, taskToAdd);%0A
-%0A
+    %7D%0A%0A    @Test%0A    public void add_addInvalidDuplicate_duplicateFailure() %7B%0A 
         //add a 
@@ -1157,16 +1157,22 @@
 pecified
+ first
 %0A       
@@ -1164,32 +1164,41 @@
 d first%0A        
+TestTask 
 taskToAdd = td.d
@@ -1327,76 +1327,8 @@
 d);%0A
-    %7D%0A%0A    @Test%0A    public void add_addInvalidDuplicate_failure() %7B
 %0A   
@@ -2711,30 +2711,25 @@
     
-//TODO: set up typical
+TestRecurringTask
  rec
@@ -2734,22 +2734,23 @@
 ecurring
- tests
+Task = 
 %0A    %7D%0A%0A

Fix add test