package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

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

public class AddCommandTest extends ToDoAppGuiTest {

    @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 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);
    }

    //@@author A0114395E
    @Test
    public void add_deadlineBeforeStart_failure() throws Exception {
        commandBox.runCommand("add Buy a zebra s/Wed Jul 12 12:43:24 2017 d/Mon Jul 10 12:43:24 2017 "
                + "t/animal p/3 n/find a poacher");

        assertResultMessage(AddCommand.MESSAGE_INVALID_START_END);
    }

    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));
    }

}

@@ -215,16 +215,59 @@
 ommand;%0A
+import seedu.todoapp.testutil.TaskBuilder;%0A
 import s
@@ -1327,16 +1327,534 @@
 114395E%0A
+    @Test%0A    public void add_barebones_success() throws Exception %7B%0A        final String bareboneTaskName = %22Buy tofu%22;%0A        //add an only-name task%0A        TestTask%5B%5D currentList = td.getTypicalTasks();%0A        TestTask barebonesTask = new TaskBuilder().withName(bareboneTaskName).build();%0A%0A        commandBox.runCommand(%22add %22.concat(bareboneTaskName));%0A        TestTask%5B%5D expectedList = TestUtil.addTasksToList(currentList, barebonesTask);%0A        assertTrue(taskListPanel.isListMatching(expectedList));%0A    %7D%0A%0A
     @Tes

Add barebones add command test