package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.testutil.TestTask;
import seedu.address.testutil.TestUtil;

public class RedoCommandTest extends TaskManagerGuiTest {

    TestTask[] expectedList = td.getTypicalTasks();
    TestTask[] currentList = expectedList;


    public void redo() {
        redoAdd();
        redoDelete();
    }

    /**
     * Tries to redo an add command
     */
    @Test
    public void redoAdd() {
        TestTask taskToAdd = td.alice;
        commandBox.runCommand(taskToAdd.getAddCommand());
        commandBox.runCommand(UndoCommand.COMMAND_WORD);
        expectedList = TestUtil.addTasksToList(expectedList, taskToAdd);
        assertRedoSuccess(currentList, expectedList);
    }

    /**
     * Tries to redo a delete command
     */
    @Test
    public void redoDelete() {
        int targetIndex = 1;
        commandBox.runCommand(DeleteCommand.COMMAND_WORD + " " + targetIndex);
        commandBox.runCommand(UndoCommand.COMMAND_WORD);
        expectedList = TestUtil.removeTaskFromList(expectedList, targetIndex);
        assertRedoSuccess(currentList, expectedList);
    }

    /**
     * Runs redo command and checks whether the current list matches the expected list
     * @param currentList list before redo command is carried out
     * @param expectedList list after redo command is carried out
     */
    private void assertRedoSuccess(TestTask[] currentList, TestTask[] expectedList) {
        commandBox.runCommand(RedoCommand.COMMAND_WORD);
        assertTrue(taskListPanel.isListMatching(expectedList));
        assertResultMessage(String.format(RedoCommand.MESSAGE_SUCCESS));
    }
}

@@ -80,16 +80,66 @@
 .Test;%0A%0A
+import seedu.address.logic.commands.ClearCommand;%0A
 import s
@@ -173,32 +173,32 @@
 .DeleteCommand;%0A
-
 import seedu.add
@@ -475,52 +475,8 @@
 ();%0A
-    TestTask%5B%5D currentList = expectedList;%0A%0A
 %0A   
@@ -512,24 +512,25 @@
  redoAdd();%0A
+%0A
         redo
@@ -538,16 +538,38 @@
 elete();
+%0A%0A        redoClear();
 %0A    %7D%0A%0A
@@ -907,37 +907,24 @@
 RedoSuccess(
-currentList, 
 expectedList
@@ -1298,29 +1298,503 @@
 Success(
-currentList, 
+expectedList);%0A    %7D%0A%0A    /**%0A     * Tries to redo a clear command%0A     */%0A    @Test%0A    public void redoClear() %7B%0A        commandBox.runCommand(%22mark 1%22);%0A        commandBox.runCommand(%22mark 2%22);%0A        commandBox.runCommand(ClearCommand.COMMAND_WORD + %22 done%22);%0A        commandBox.runCommand(UndoCommand.COMMAND_WORD);%0A%0A        expectedList = TestUtil.removeTaskFromList(expectedList, 1);%0A        expectedList = TestUtil.removeTaskFromList(expectedList, 1);%0A        assertRedoSuccess(
 expected
@@ -2038,24 +2038,24 @@
 out%0A     */%0A
+
     private 
@@ -2091,32 +2091,8 @@
 sk%5B%5D
- currentList, TestTask%5B%5D
  exp

Add test for redo clear command