package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

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

public class AddCommandTest extends DoistGUITest {

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

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

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

        //add duplicate task
        commandBox.runCommand(td.email.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_PERSON);
        assertTrue(personListPanel.isListMatching(currentList));

        // add a task without description (invalid)
        commandBox.runCommand("do \\as important");
        assertResultMessage(AddCommand.MESSAGE_NO_DESC);

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

        //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 = personListPanel.navigateToPerson(taskToAdd.getDescription().desc);
        assertMatching(taskToAdd, addedCard);

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

}

@@ -1542,13 +1542,17 @@
 dds 
-Johnn
+Do laundr
 y%22);
@@ -1614,16 +1614,758 @@
 OMMAND);
+%0A%0A        //invalid command since %5Cfrom and %5Cby are used together%0A        commandBox.runCommand(%22add Do laundry %5C%5Cfrom today %5C%5Cby tomorrow%22);%0A        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));%0A%0A        //invalid command since %5Cto and %5Cby are used together%0A        commandBox.runCommand(%22add Do laundry %5C%5Cto today %5C%5Cby tomorrow%22);%0A        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));%0A%0A        //invalid command since %5Cfrom and %5Cto aren't used together%0A        commandBox.runCommand(%22add Do laundry %5C%5Cfrom today %22);%0A        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
 %0A    %7D%0A%0A

Add test cases for AddCommand Class