package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.tasklist.commons.exceptions.IllegalValueException;
import seedu.tasklist.logic.commands.RedoCommand;
import seedu.tasklist.logic.commands.UndoCommand;
import seedu.tasklist.model.task.Name;
import seedu.tasklist.testutil.TestTask;
import seedu.tasklist.testutil.TestUtil;


//@@author A0139747N
public class UndoRedoCommandTest extends TaskListGuiTest {

    @Test
    public void assertUndoRedoAddSuccess() {
        TestTask taskToBeAdded = td.internship;
        commandBox.runCommand(taskToBeAdded.getAddCommand());
        commandBox.runCommand("undo");
        TestTask[] expectedTaskList = td.getTypicalTasks();
        assertTrue(taskListPanel.isListMatching(expectedTaskList));
        assertResultMessage(String.format(UndoCommand.MESSAGE_UNDO_SUCCESS));

        //redo
        commandBox.runCommand("redo");
        TestTask[] currentList = TestUtil.addTasksToList(td.getTypicalTasks(), td.internship);
        assertTrue(taskListPanel.isListMatching(currentList));
        assertResultMessage(String.format(RedoCommand.MESSAGE_REDO_SUCCESS));
    }

    /**
     * Test to edit the name. Beyond MVP can edit all other parameters for more coverage.
     * @throws IllegalValueException
     */

    @Test
    public void assertUndoRedoEditSuccess() throws IllegalValueException {
        commandBox.runCommand("edit 1 Evalution Report");
        commandBox.runCommand("undo");
        TestTask[] expectedTaskList = td.getTypicalTasks();
        assertTrue(taskListPanel.isListMatching(expectedTaskList));
        assertResultMessage(String.format(UndoCommand.MESSAGE_UNDO_SUCCESS));

        //redo
        commandBox.runCommand("redo");
        expectedTaskList[0].setName(new Name("Evalution Report"));
        assertTrue(taskListPanel.isListMatching(expectedTaskList));
        assertResultMessage(String.format(RedoCommand.MESSAGE_REDO_SUCCESS));
    }

    @Test
    public void assertUndoRedoDeleteSuccess() {
        TestTask[] currentList = TestUtil.removeTaskFromList(td.getTypicalTasks(), 6);
        commandBox.runCommand("delete 6");
        commandBox.runCommand("undo");
        TestTask[] expectedTaskList = td.getTypicalTasks();
        assertTrue(taskListPanel.isListMatching(expectedTaskList));
        assertResultMessage(String.format(UndoCommand.MESSAGE_UNDO_SUCCESS));

        //redo
        commandBox.runCommand("redo");
        currentList = TestUtil.removeTaskFromList(td.getTypicalTasks(), 6);
        assertTrue(taskListPanel.isListMatching(currentList));
        assertResultMessage(String.format(RedoCommand.MESSAGE_REDO_SUCCESS));

    }

    /**
     * Test for events where multiple undo/redo commands are entered, and go over the stack limit.
     */
    @Test
    public void assertUndoRedoFail() {
        TestTask taskToBeAdded = td.internship;
        commandBox.runCommand(taskToBeAdded.getAddCommand());
        commandBox.runCommand("undo");
        assertResultMessage(UndoCommand.MESSAGE_UNDO_SUCCESS);
        commandBox.runCommand("undo");
        assertResultMessage(UndoCommand.MESSAGE_UNDO_FAILED);

        commandBox.runCommand("redo");
        assertResultMessage(String.format(RedoCommand.MESSAGE_REDO_SUCCESS));
        commandBox.runCommand("redo");
        assertResultMessage(String.format(RedoCommand.MESSAGE_REDO_FAILED));

    }

    @Test
    public void assertUndoRedoClearSuccess() {
        commandBox.runCommand("clear");
        commandBox.runCommand("undo");
        assertResultMessage(UndoCommand.MESSAGE_UNDO_SUCCESS);
        TestTask[] expectedTaskList = td.getTypicalTasks();
        assertTrue(taskListPanel.isListMatching(expectedTaskList));

        commandBox.runCommand("redo");
        assertResultMessage(RedoCommand.MESSAGE_REDO_SUCCESS);
        assertTrue(taskListPanel.isListMatching());
    }
}



@@ -846,36 +846,68 @@
 AGE_UNDO_SUCCESS
+ + taskToBeAdded.getAddCommand()
 ));%0A
-
 %0A        //redo%0A
@@ -1169,32 +1169,64 @@
 AGE_REDO_SUCCESS
+ + taskToBeAdded.getAddCommand()
 ));%0A    %7D%0A%0A    /
@@ -1740,32 +1740,60 @@
 AGE_UNDO_SUCCESS
+ + %22edit 1 Evalution Report%22
 ));%0A%0A        //r
@@ -2036,32 +2036,60 @@
 AGE_REDO_SUCCESS
+ + %22edit 1 Evalution Report%22
 ));%0A    %7D%0A%0A    @
@@ -2504,32 +2504,45 @@
 AGE_UNDO_SUCCESS
+ + %22delete 6%22
 ));%0A%0A        //r
@@ -2793,24 +2793,37 @@
 REDO_SUCCESS
+ + %22delete 6%22
 ));%0A%0A    %7D%0A%0A
@@ -3187,32 +3187,64 @@
 AGE_UNDO_SUCCESS
+ + taskToBeAdded.getAddCommand()
 );%0A        comma
@@ -3445,16 +3445,48 @@
 _SUCCESS
+ + taskToBeAdded.getAddCommand()
 ));%0A    
@@ -3793,32 +3793,42 @@
 AGE_UNDO_SUCCESS
+ + %22clear%22
 );%0A        TestT
@@ -3974,32 +3974,32 @@
 ommand(%22redo%22);%0A
-
         assertRe
@@ -4042,16 +4042,26 @@
 _SUCCESS
+ + %22clear%22
 );%0A     

fix test cases