package guitests;

import org.junit.Test;
import seedu.manager.testutil.TestTask;
import seedu.manager.testutil.TestUtil;

import static org.junit.Assert.assertTrue;

public class UndoCommandTest  extends TaskManagerGuiTest  {

	@Test
	public void test() {
		// Test undo add command.
		TestTask[] currentList = td.getTypicalTasks();
		commandBox.runCommand("add abc");
		
		assertUndoSuccess(currentList);
		
		// Test undo delete command.
		commandBox.runCommand("delete 1");
		
		TestTask toDelete = currentList[0];
		
		currentList = TestUtil.removeTaskFromList(currentList, 1);
		currentList = TestUtil.addTasksToList(currentList, toDelete);
		
		assertUndoSuccess(currentList);
		
		// Test undo edit command.
		commandBox.runCommand("edit 1 venue Utown");
		
		TestTask toEdit = currentList[0];
		
		currentList = TestUtil.removeTaskFromList(currentList, 1);
		currentList = TestUtil.addTasksToList(currentList, toEdit);
		
		assertUndoSuccess(currentList);
		
		// Test undo done command.
		commandBox.runCommand("done 1");
		
		TestTask toDone = currentList[0];
		
		currentList = TestUtil.removeTaskFromList(currentList, 1);
		currentList = TestUtil.addTasksToList(currentList, toDone);
		
		assertUndoSuccess(currentList);
		
		// Test undo sort command.
		commandBox.runCommand("sort");
		
		assertUndoSuccess(currentList);
	}
	
	private void assertUndoSuccess(TestTask[] expectedList) {
	    commandBox.runCommand("undo");
	    
	    assertTrue(taskListPanel.isListMatching(expectedList));
	    }

}

@@ -34,16 +34,65 @@
 it.Test;
+%0A%0Aimport seedu.manager.logic.commands.AddCommand;
 %0Aimport 
@@ -408,27 +408,24 @@
 %22add abc%22);%0A
-%09%09%0A
 %09%09assertUndo
@@ -513,27 +513,24 @@
 delete 1%22);%0A
-%09%09%0A
 %09%09TestTask t
@@ -547,35 +547,32 @@
 currentList%5B0%5D;%0A
-%09%09%0A
 %09%09currentList = 
@@ -676,27 +676,24 @@
  toDelete);%0A
-%09%09%0A
 %09%09assertUndo
@@ -789,27 +789,24 @@
 ue Utown%22);%0A
-%09%09%0A
 %09%09TestTask t
@@ -821,35 +821,32 @@
 currentList%5B0%5D;%0A
-%09%09%0A
 %09%09currentList = 
@@ -952,19 +952,16 @@
 oEdit);%0A
-%09%09%0A
 %09%09assert
@@ -1053,19 +1053,16 @@
 ne 1%22);%0A
-%09%09%0A
 %09%09TestTa
@@ -1089,19 +1089,16 @@
 ist%5B0%5D;%0A
-%09%09%0A
 %09%09curren
@@ -1212,19 +1212,16 @@
 oDone);%0A
-%09%09%0A
 %09%09assert
@@ -1311,19 +1311,16 @@
 sort%22);%0A
-%09%09%0A
 %09%09assert
@@ -1345,16 +1345,305 @@
 tList);%0A
+%09%09%0A%09%09// Test undo alias command%0A%09%09commandBox.runCommand(%22alias add +%22);%0A%09%09commandBox.runCommand(%22undo%22);%0A%09%09%0A%09%09TestTask taskToAdd = td.juliet;%0A%09%09commandBox.runCommand(taskToAdd.getAddCommand());%0A%09%09assertResultMessage(String.format(AddCommand.MESSAGE_SUCCESS, taskToAdd.getAsPrettyText()));%0A
 %09%7D%0A%09%0A%09pr
@@ -1733,18 +1733,16 @@
 %22undo%22);
-%0A%09
     %0A%09  
@@ -1799,17 +1799,16 @@
 List));%0A
-%09
     %7D%0A%0A%7D

Add test for alias undo