package guitests;

import guitests.guihandles.FloatingTaskCardHandle;
import org.junit.Test;

import seedu.jimi.commons.core.Messages;
import seedu.jimi.logic.commands.AddCommand;
import seedu.jimi.testutil.TestFloatingTask;
import seedu.jimi.testutil.TestUtil;
import seedu.jimi.testutil.TypicalTestFloatingTasks;

import static org.junit.Assert.assertTrue;

public class AddCommandTest extends AddressBookGuiTest {

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

        //add another task
        taskToAdd = TypicalTestFloatingTasks.night;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

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

        //add to empty list
        commandBox.runCommand("clear");
        assertAddSuccess(TypicalTestFloatingTasks.beach);

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

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

        //confirm the new card contains the right data
        FloatingTaskCardHandle addedCard = taskListPanel.navigateToTask(taskToAdd.getName().fullName);
        assertMatching(taskToAdd, addedCard);

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

}

@@ -173,16 +173,104 @@
 ommand;%0A
+import seedu.jimi.model.task.ReadOnlyTask;%0Aimport seedu.jimi.testutil.TestDeadlineTask;%0A
 import s
@@ -343,16 +343,69 @@
 stUtil;%0A
+import seedu.jimi.testutil.TypicalTestDeadlineTasks;%0A
 import s
@@ -598,43 +598,16 @@
     
-//add one task%0A        TestFloating
+ReadOnly
 Task
@@ -645,16 +645,48 @@
 asks();%0A
+        %0A        //add one task%0A
         
@@ -1300,24 +1300,286 @@
 rentList));%0A
+        %0A        //add deadline task%0A        TestDeadlineTask deadlineTaskToAdd = TypicalTestDeadlineTasks.homework;%0A        assertAddSuccess(deadlineTaskToAdd, currentList);%0A        currentList = TestUtil.addTasksToList(currentList, deadlineTaskToAdd);%0A        
 %0A        //a
@@ -1898,28 +1898,24 @@
 kToAdd, 
-TestFloating
+ReadOnly
 Task... 
@@ -2274,36 +2274,32 @@
 ask%0A        
-TestFloating
+ReadOnly
 Task%5B%5D expec
@@ -2427,11 +2427,296 @@
 ;%0A    %7D%0A
+    %0A    //@@author A0143471L%0A    private void assertAddSuccess(TestDeadlineTask taskToAdd, ReadOnlyTask... currentList) %7B%0A        commandBox.runCommand(taskToAdd.getAddCommand());%0A%0A        assertResultMessage(String.format(AddCommand.MESSAGE_SUCCESS, taskToAdd));%0A    %7D%0A    //@@author
 %0A%7D%0A

Implement deadlinetask in AddCommandTest