package guitests.working;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import utask.logic.commands.ClearCommand;
import utask.logic.commands.DeleteCommand;
import utask.logic.commands.RedoCommand;
import utask.logic.commands.UndoCommand;
import utask.model.task.ReadOnlyTask;

public class ReversibleCommandTest extends UTaskGuiTest {

    @Before
    public void clear() {
        commandBox.runCommand(ClearCommand.COMMAND_WORD);
//        raise(new UTaskChangedEvent());
    }

    @After
    public void cleanup() {
        commandBox.runCommand(ClearCommand.COMMAND_WORD);
    }

    @Test
    public void addCanUndoAndRedo() {
        commandBox.runCommand(td.dueTask.getAddCommand());
        //Undo
        commandBox.runCommand(UndoCommand.COMMAND_WORD);
        assertListIsEmpty();

        //Redo
        commandBox.runCommand(RedoCommand.COMMAND_WORD);
        assertListIsNotEmpty();
    }

    @Test
    public void deleteCanUndoAndRedo() {
        ReadOnlyTask toAdd = td.dueTask;

        commandBox.runCommand(td.dueTask.getAddCommand());
        commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");

        //Undo
        commandBox.runCommand(UndoCommand.COMMAND_WORD);
        // assertTaskNotInList(toAdd); //TESTFX BUGGY
       //assertListIsEmpty();

        //Redo
        commandBox.runCommand(RedoCommand.COMMAND_WORD);
        //assertListIsNotEmpty();
    }

//    @Test
//    public void updateCanUndoAndRedo() {
//        commandBox.runCommand(td.dueTask.getAddCommand());
//        commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");
//
//        //Undo
//        commandBox.runCommand(UndoCommand.COMMAND_WORD);
//        assertListIsEmpty();
//
//        //Redo
//        commandBox.runCommand(RedoCommand.COMMAND_WORD);
//        assertListIsNotEmpty();
//    }


//    private void assertTaskNotInList(ReadOnlyTask task) {
//        assert(listPanel.getDueListView().getItems().contains(task));
//    }

    private void assertListIsEmpty() {
        assert(listPanel.getDueListView().getItems().isEmpty());
    }

    private void assertListIsNotEmpty() {
        assert(listPanel.getDueListView().getItems().size() > 0);
    }

}

@@ -93,16 +93,52 @@
 .Test;%0A%0A
+import utask.commons.core.Messages;%0A
 import u
@@ -2006,24 +2006,372 @@
 );%0A//    %7D%0A%0A
+    @Test%0A    public void undoRangeGreaterThanActual() %7B%0A        commandBox.runCommand(%22undo 1000%22);%0A        assertResultMessage(Messages.MESSAGE_INVALID_UNDO_RANGE);%0A    %7D%0A%0A    @Test%0A    public void redoRangeGreaterThanActual() %7B%0A        commandBox.runCommand(%22redo 1000%22);%0A        assertResultMessage(Messages.MESSAGE_INVALID_REDO_RANGE);%0A    %7D%0A%0A
     private 

Add undo redo range test