package guitests;

import static org.junit.Assert.assertTrue;

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

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

//@@author A0127686R
public class AddCommandTest extends FlexiTrackGuiTest {

    TestTask[] currentList = td.getTypicalSortedTasks();
    TestTask taskToAdd;
    
    @Test
    public void addAnEvent() {
        TestTask[] currentList = td.getTypicalSortedTasks();
        taskToAdd = TypicalTestTasks.basketball;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);
    }
    
    @Test
    public void addADeadLineTask() {
        taskToAdd = TypicalTestTasks.lecture;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);
    }
    
    @Test
    public void addAFloatingTask() {
        taskToAdd = TypicalTestTasks.job;
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

    }
    @Test
    public void addADuplicateTask() {
        commandBox.runCommand(TypicalTestTasks.soccer.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertTrue(taskListPanel.isListMatching(currentList));
    }

    @Test
    public void addToAnEmptyList() {
        commandBox.runCommand("clear");
        assertAddSuccess(TypicalTestTasks.homework1);

    }
    
    @Test
    public void invalidAddCommand () {
        commandBox.runCommand("adds cs tutorial");
        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 = taskListPanel.navigateToTask(taskToAdd.getName().toString());
        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));
    }

}

@@ -223,33 +223,145 @@
 ack.
-logic.commands.AddCommand
+commons.exceptions.IllegalValueException;%0Aimport seedu.flexitrack.logic.commands.AddCommand;%0Aimport seedu.flexitrack.testutil.TaskBuilder
 ;%0Aim
@@ -2533,11 +2533,1366 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void assertAddRecursiveEventSuccess() throws IllegalValueException %7B%0A        commandBox.runCommand(%22add Attend PC1222 lecture fr/3 ty/week from/Fri 3pm to/Fri 5pm%22);%0A        %0A        for (int i = 0; i %3C 3; i++) %7B%0A            TestTask recursiveEvent = new TaskBuilder().withName(%22Attend PC1222 lecture%22).withStartTime(%22Nov %22 + (4 + (i*7)) +%22 2016 15:00%22)%0A                    .withEndTime(%22Nov %22 + (4 + (i*7)) +%22 2016 17:00%22).withDueDate(%22Feb 29 2000 00:00%22).build();%0A            %0A            currentList = TestUtil.addTasksToList(currentList, recursiveEvent);%0A            %0A        %7D%0A        assertTrue(taskListPanel.isListMatching(0, currentList));%0A    %7D%0A    %0A    @Test%0A    public void assertAddRecursiveTaskSuccess() throws IllegalValueException %7B%0A        commandBox.runCommand(%22add Submit PC1222 Lab Assignment fr/3 ty/week by/Nov 1 2016 17:00%22);%0A        %0A        for (int i = 0; i %3C 3; i++) %7B%0A            TestTask recursiveTask = new TaskBuilder().withName(%22Submit PC1222 Lab Assignment%22).withStartTime(%22Feb 29 2000 00:00%22)%0A                    .withEndTime(%22Feb 29 2000 00:00%22).withDueDate(%22Nov %22 + (1 +(i*7)) + %22 2016 17:00%22).build();%0A            %0A            currentList = TestUtil.addTasksToList(currentList, recursiveTask);%0A            %0A        %7D%0A        assertTrue(taskListPanel.isListMatching(0, currentList));%0A    %7D%0A    
 %0A%7D%0A

add test case for recurring event and task