package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import seedu.doist.testutil.TestTask;
import seedu.doist.testutil.TestUtil;

public class UndoRedoCommandTest extends DoistGUITest {
    @Test
    public void testUndoAndRedoOneAddCommand() {  // test undoing and redoing one mutating command
        TestTask[] currentList = td.getTypicalTasks();

        TestTask taskToAdd = td.email;
        commandBox.runCommand(taskToAdd.getAddCommand());
        TestTask[] newList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(personListPanel.isListMatching(newList));

        commandBox.runCommand("undo");
        assertTrue(personListPanel.isListMatching(currentList));
        commandBox.runCommand("redo");
        assertTrue(personListPanel.isListMatching(newList));
    }

    @Test
    public void testUndoAddAndClearCommand() {  // test undoing and redoing multiple mutating command
        TestTask[] currentList = td.getTypicalTasks();

        TestTask taskToAdd = td.exercise;

        commandBox.runCommand(taskToAdd.getAddCommand());
        TestTask[] newList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(personListPanel.isListMatching(newList));

        commandBox.runCommand("clear");
        assertTrue(personListPanel.isListMatching(new TestTask[0]));

        commandBox.runCommand("undo");
        assertTrue(personListPanel.isListMatching(newList));
        commandBox.runCommand("undo");
        assertTrue(personListPanel.isListMatching(currentList));

        commandBox.runCommand("redo");
        assertTrue(personListPanel.isListMatching(newList));
        commandBox.runCommand("redo");
        assertTrue(personListPanel.isListMatching(new TestTask[0]));
    }

    @Test
    public void testUndoAndRedoMoreThanHistory() {  // execute one mutating command, but undo twice
        TestTask[] currentList = td.getTypicalTasks();

        TestTask taskToAdd = td.email;
        commandBox.runCommand(taskToAdd.getAddCommand());
        TestTask[] newList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertTrue(personListPanel.isListMatching(newList));

        commandBox.runCommand("undo");
        assertTrue(personListPanel.isListMatching(currentList));
        commandBox.runCommand("undo");
        assertTrue(personListPanel.isListMatching(currentList));

        commandBox.runCommand("redo");
        assertTrue(personListPanel.isListMatching(newList));
        commandBox.runCommand("redo");
        assertTrue(personListPanel.isListMatching(newList));
    }
}










@@ -1955,37 +1955,38 @@
  taskToAdd = td.
-email
+chores
 ;%0A        comman
@@ -2509,32 +2509,32 @@
 ommand(%22redo%22);%0A
-
         assertTr
@@ -2583,16 +2583,1293 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testNewBranchHistory() %7B  // undo then execute a command, which create a new history branch%0A        TestTask%5B%5D currentList = td.getTypicalTasks();%0A%0A        TestTask taskToAdd = td.chores;%0A        commandBox.runCommand(taskToAdd.getAddCommand());%0A        TestTask%5B%5D newList = TestUtil.addTasksToList(currentList, taskToAdd);%0A        assertTrue(personListPanel.isListMatching(newList));%0A%0A        taskToAdd = td.email;%0A        commandBox.runCommand(taskToAdd.getAddCommand());%0A        TestTask%5B%5D newList2 = TestUtil.addTasksToList(newList, taskToAdd);%0A        assertTrue(personListPanel.isListMatching(newList2));%0A%0A        commandBox.runCommand(%22undo%22);%0A        assertTrue(personListPanel.isListMatching(newList));%0A%0A        taskToAdd = td.exercise;%0A        commandBox.runCommand(taskToAdd.getAddCommand());%0A        TestTask%5B%5D newList3 = TestUtil.addTasksToList(newList, taskToAdd);%0A        assertTrue(personListPanel.isListMatching(newList3));%0A%0A        commandBox.runCommand(%22redo%22);%0A        assertTrue(personListPanel.isListMatching(newList3));%0A        commandBox.runCommand(%22undo%22);%0A        assertTrue(personListPanel.isListMatching(newList));%0A        commandBox.runCommand(%22redo%22);%0A        assertTrue(personListPanel.isListMatching(newList3));%0A    %7D
 %0A%7D%0A%0A%0A%0A%0A%0A

add test cases for new branch of history