package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.ezdo.commons.core.Messages;
import seedu.ezdo.logic.commands.UndoCommand;
import seedu.ezdo.testutil.TestTask;
import seedu.ezdo.testutil.TestUtil;

public class UndoCommandTest extends EzDoGuiTest {

    @Test
    public void undo() {

        //undo without anything to undo
        commandBox.runCommand("undo");
        assertResultMessage(UndoCommand.MESSAGE_NO_PREV_COMMAND);

        //invalid command
        commandBox.runCommand("undoo");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);

        //undo an add
        TestTask taskToAdd = td.hoon;
        TestTask[] currentList = td.getTypicalTasks();
        commandBox.runCommand(taskToAdd.getAddCommand(false));
        assertUndoSuccess(currentList);

        //undo a clear
        currentList = td.getTypicalTasks();
        commandBox.runCommand("clear");
        assertUndoSuccess(currentList);

        //undo two things
        currentList = td.getTypicalTasks();
        commandBox.runCommand(taskToAdd.getAddCommand(false));
        TestTask[] currentListTwo = TestUtil.addTasksToList(currentList, taskToAdd);
        commandBox.runCommand("clear");
        assertUndoSuccess(currentListTwo);
        assertUndoSuccess(currentList);

    }

    private void assertUndoSuccess(TestTask[] expectedList) {
        commandBox.runCommand("undo");
        assertTrue(taskListPanel.isListMatching(expectedList));
        assertResultMessage(UndoCommand.MESSAGE_SUCCESS);
    }
}

@@ -328,14 +328,20 @@
 undo
+_noPrev
 () %7B%0A
-%0A
     
@@ -473,32 +473,88 @@
 _PREV_COMMAND);%0A
+    %7D%0A%0A    @Test%0A    public void undo_invalidCommand() %7B
 %0A        //inval
@@ -667,16 +667,61 @@
 MMAND);%0A
+    %7D%0A%0A    @Test%0A    public void undo_add() %7B
 %0A       
@@ -923,32 +923,79 @@
 s(currentList);%0A
+    %7D%0A%0A    @Test%0A    public void undo_clear() %7B
 %0A        //undo 
@@ -1002,32 +1002,42 @@
 a clear%0A        
+TestTask%5B%5D
 currentList = td
@@ -1132,24 +1132,75 @@
 rrentList);%0A
+    %7D%0A%0A    @Test%0A    public void undo_twoThings() %7B
 %0A        //u
@@ -1221,16 +1221,27 @@
 %0A       
+ TestTask%5B%5D
  current
@@ -1261,32 +1261,70 @@
 TypicalTasks();%0A
+        TestTask taskToAdd = td.hoon;%0A
         commandB
@@ -1578,17 +1578,16 @@
 tList);%0A
-%0A
     %7D%0A%0A 

Break up UndoCommandTest into multiple smaller tests