//@@author A0147996E
package guitests;

import static org.junit.Assert.assertTrue;

import static seedu.address.logic.commands.UndoCommand.MESSAGE_SUCCESS;
import static seedu.address.logic.commands.UndoCommand.MESSAGE_UNSUCCESS;

import org.junit.Test;

import seedu.address.logic.commands.CommandFormatter;
import seedu.address.testutil.TestEvent;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class UndoCommandTest extends TaskManagerGuiTest {
    private TestTask[] currentList = td.getTypicalTasks();
    private String commandToUndo;
    private String commandWord;

    @Test
    public void undo_ableUndoCommands_undoSuccess() {
        TestEvent eventToAdd = te.assignment;
        commandToUndo = eventToAdd.getAddCommand();
        commandWord = "add";
        assertUndoSuccess(currentList, commandToUndo, commandWord);

        commandToUndo = "delete 1";
        commandWord = "delete";
        assertUndoSuccess(currentList, commandToUndo, commandWord);

        commandToUndo = "finish 1";
        commandWord = "finish";
        assertUndoSuccess(currentList, commandToUndo, commandWord);

        commandToUndo = "load data/dueue.xml";
        commandWord = "load";
        assertUndoSuccess(currentList, commandToUndo, commandWord);

        String detailsToEdit = " n/assignment2 dueT/18:30";
        commandToUndo = "edit 2 " + detailsToEdit;
        commandWord = "edit";
        assertUndoSuccess(currentList, commandToUndo, commandWord);
    }
    @Test
    public void undo_noMoreCommandToUndo_undoUnsuccess() {
        commandBox.runCommand("list all"); //list is not ableUndoCommand
        commandBox.runCommand("undo");
        assertResultMessage(MESSAGE_UNSUCCESS);
    }

    @Test
    public void undo_stackOfAbleUndoCommands_undoSuccess() {
        commandBox.runCommand("finish 1");
        TestTask finishedTask = currentList[0];
        currentList = TestUtil.removeTaskFromList(currentList, 1);

        assertUndoSuccess(currentList, "clear", "clear");
        currentList = TestUtil.addTasksToList(currentList, finishedTask);

        commandWord = "finish";
        commandBox.runCommand("undo");
        assertTrue(taskListPanel.isListMatching(currentList));
        assertResultMessage(CommandFormatter.undoMessageFormatter(MESSAGE_SUCCESS,
                (commandWord + " command")));
    }

    private void assertUndoSuccess(final TestTask[] currentList,
            String commandToUndo, String commandWord) {
        commandBox.runCommand(commandToUndo);
        commandBox.runCommand("undo");
        assertTrue(taskListPanel.isListMatching(currentList));
        assertResultMessage(CommandFormatter.undoMessageFormatter(MESSAGE_SUCCESS,
                (commandWord + " command")));
    }
}

@@ -248,16 +248,79 @@
 .Test;%0A%0A
+import seedu.address.commons.exceptions.IllegalValueException;%0A
 import s
@@ -406,16 +406,65 @@
 tEvent;%0A
+import seedu.address.testutil.TestRecurringTask;%0A
 import s
@@ -1432,17 +1432,16 @@
 Edit = %22
- 
 n/assign
@@ -1614,16 +1614,1271 @@
 ;%0A    %7D%0A
+%0A    @Test%0A    public void undo_editNext_undoSuccess() throws IllegalValueException %7B%0A        TestRecurringTask recurringTaskToAdd = tr.gym;%0A        commandBox.runCommand(%22clear%22);%0A        commandBox.runCommand(recurringTaskToAdd.getAddCommand());%0A%0A        String detailsToEdit = %22d/test%22;%0A        commandBox.runCommand(%22edit %22 + 1 + %22 once/t %22 + detailsToEdit);%0A        TestTask typicalTaskToAdd = new TestTask(tr.gym);%0A        typicalTaskToAdd.setDescription(%22test%22);%0A        recurringTaskToAdd.setDate(%2227/12/2017%22);%0A%0A        // confirm the new typical and recurring task is added to the current list%0A        assertTrue(taskListPanel.navigateToTask(typicalTaskToAdd));%0A        assertTrue(taskListPanel.navigateToTask(recurringTaskToAdd));%0A%0A        // confirm the list now contains no task except the Tasks with updated details%0A        TestTask%5B%5D expectedTasksList = new TestTask%5B2%5D;%0A        expectedTasksList%5B0%5D = typicalTaskToAdd;%0A        expectedTasksList%5B1%5D = recurringTaskToAdd;%0A        assertTrue(taskListPanel.isListMatching(expectedTasksList));%0A%0A        commandBox.runCommand(%22undo%22);%0A        expectedTasksList = new TestTask%5B1%5D;%0A        expectedTasksList%5B0%5D = tr.gym;%0A        assertTrue(taskListPanel.isListMatching(expectedTasksList));%0A    %7D%0A%0A
     @Tes

Add testcase for undo editNext