package guitests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

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

//@@author A0150120H
public class UndoCommandTest extends TaskManagerGuiTest {

    @Test
    public void undo() {
        //nothing to undo
        commandBox.runCommand("clear");
        commandBox.runCommand(UndoCommand.COMMAND_WORD);
        assertResultMessage(UndoCommand.MESSAGE_EMPTY_HISTORY);

        //add one task
        TestTask[] currentList = new TestTask[0];
        TestTask taskToAdd = td.getFit;
        commandBox.runCommand(taskToAdd.getAddCommand());
        assertUndoSuccess(currentList);

        //TODO: Add undo cases for other commands
    }

    //@@author A0142255M
    @Test
    public void undo_shortCommand_success() {
        commandBox.runCommand("edit 1; name Pay David 15 for cab");
        commandBox.runCommand(UndoCommand.SHORT_COMMAND_WORD + " ");
        assertUndoSuccess(td.getTypicalTasks());
    }

    @Test
    public void undo_additionalParameters_success() {
        commandBox.runCommand("delete 2");
        commandBox.runCommand(UndoCommand.SHORT_COMMAND_WORD + " delete");
        assertUndoSuccess(td.getTypicalTasks());
    }

    @Test
    public void undo_invalidCommand_failure() {
        commandBox.runCommand(td.findGirlfriend.getAddCommand());
        commandBox.runCommand("undoodifbshvh");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        assertFalse(taskListPanel.getNumberOfTasks() == td.getTypicalTasks().length);
    }
    //@@author

    private void assertUndoSuccess(TestTask... originalList) {
        commandBox.runCommand(UndoCommand.COMMAND_WORD);

        //confirm the list now contains the previous tasks
        assertTrue(taskListPanel.isListMatching(originalList));
    }
}

@@ -166,16 +166,112 @@
 ssages;%0A
+import seedu.tache.logic.commands.DeleteCommand;%0Aimport seedu.tache.logic.commands.EditCommand;%0A
 import s
@@ -462,76 +462,438 @@
 undo
-() %7B%0A        //nothing to undo%0A        commandBox.runCommand(%22clear%22
+_addCommand_success() %7B%0A        //add one task%0A        TestTask%5B%5D currentList = td.getTypicalTasks();%0A        TestTask taskToAdd = td.getFit;%0A        commandBox.runCommand(taskToAdd.getAddCommand());%0A        assertUndoSuccess(currentList);%0A%0A        //TODO: Add undo cases for other commands%0A    %7D%0A%0A    @Test%0A    public void undo_deleteCommand_success() %7B%0A        //add one task%0A        TestTask%5B%5D currentList = td.getTypicalTasks(
 );%0A 
@@ -913,36 +913,38 @@
 dBox.runCommand(
-Undo
+Delete
 Command.COMMAND_
@@ -947,16 +947,23 @@
 AND_WORD
+ + %22 1%22
 );%0A     
@@ -975,320 +975,513 @@
 sert
-ResultMessage(UndoCommand.MESSAGE_EMPTY_HISTORY);%0A%0A        //add one task%0A        TestTask%5B%5D currentList = new TestTask%5B0%5D;%0A        TestTask taskToAdd = td.getFit;%0A        commandBox.runCommand(taskToAdd.getAddCommand());%0A        assertUndoSuccess(currentList);%0A%0A        //TODO: Add undo cases for other commands
+UndoSuccess(currentList);%0A    %7D%0A%0A    @Test%0A    public void undo_editCommand_success() %7B%0A        //add one task%0A        TestTask%5B%5D currentList = td.getTypicalTasks();%0A        commandBox.runCommand(EditCommand.COMMAND_WORD + %22 5 change ed to 5th November%22);%0A        assertUndoSuccess(currentList);%0A    %7D%0A%0A    @Test%0A    public void undo_emptyHistory_failure() %7B%0A        //nothing to undo%0A        commandBox.runCommand(UndoCommand.COMMAND_WORD);%0A        assertResultMessage(UndoCommand.MESSAGE_EMPTY_HISTORY);
 %0A   

Update Test case for UndoCommand