package guitests;

import org.junit.Test;
import seedu.address.commons.core.Messages;
import seedu.address.testutil.*;
import static org.junit.Assert.assertTrue;

//@@author A0125097A
public class UndoCommandTest extends AddressBookGuiTest {

    @Test
    public void undo_addCommand() {
        TestActivity[] currentList = td.getTypicalActivities();
        TestActivity activityToAdd = td.findHoon;
        assertUndoAddResult(activityToAdd,currentList);
        
    }
    
    @Test
    public void undo_deleteCommand() {
        TestActivity[] currentList = td.getTypicalActivities();
        int index = 2;
        assertUndoDeleteResult(index,currentList);
    }
    
    @Test
    public void undo_doneCommand() {
        TestActivity[] currentList = td.getTypicalActivities();
        int index = 4;
        assertUndoDoneResult(index,currentList);
    }

    @Test
    public void undo_editCommand() {
        TestActivity[] currentList = td.getTypicalActivities();
        int index = 1;
        String newName = "new name";
        String newReminder = "29-12-2021 2200";
        TestActivity activityBeforeEdit = new TestActivity(currentList[index-1]);
        TestActivity activityAfterEdit = new TestActivity(currentList[index-1]);
        activityAfterEdit.setName(newName);
        activityAfterEdit.setReminder(newReminder);
        String editCommand = "edit " + index + " n/" + newName + " r/" + newReminder;
        assertUndoEditResult(editCommand,activityBeforeEdit,activityAfterEdit,currentList);
    }
    
    
    private void assertUndoEditResult(String command, TestActivity activityAfterUndo, TestActivity activityBeforeUndo, TestActivity[] currentList) {
        commandBox.runCommand(command);
        commandBox.runCommand("undo"); 
        assertResultMessage(String.format("Undo: Editting task from: %1$s\nto: %2$s",
                activityAfterUndo.getAsText(),activityBeforeUndo.getAsText()));
        assertTrue(activityListPanel.isListMatching(currentList));
  
        
    }

    private void assertUndoAddResult(TestActivity activity,TestActivity... currentList){
        commandBox.runCommand(activity.getAddCommand());
        commandBox.runCommand("undo");
        assertResultMessage(String.format("Undo: Adding of new task: %1$s",activity.getAsText()));
        assertTrue(activityListPanel.isListMatching(currentList));
        
    }
    
    private void assertUndoDeleteResult(int index,TestActivity... currentList){
        TestActivity activityToDelete = currentList[index-1];
        
        commandBox.runCommand("delete " + index);
        commandBox.runCommand("undo");
        assertResultMessage(String.format("Undo: Deleting task: %1$s",activityToDelete.getAsText()));
        assertTrue(activityListPanel.isListMatching(currentList));
    }
    
    private void assertUndoDoneResult(int index,TestActivity... currentList){
        TestActivity activityToDone = currentList[index-1];
        
        commandBox.runCommand("done " + index);
        commandBox.runCommand("undo");
        assertResultMessage(String.format("Undo: Marked task as Completed: %1$s",activityToDone.getAsText()));
        assertTrue(activityListPanel.isListMatching(currentList));
        
    }
    
}

@@ -895,23 +895,24 @@
 ndo_edit
-Command
+Activity
 () %7B%0A   
@@ -994,32 +994,227 @@
 dex = 1;%0A       
+%0A        %0A        assertUndoEditActivityResult(index,currentList);%0A    %7D%0A    %0A    %0A    %0A    %0A    %0A    %0A    private void assertUndoEditActivityResult(int index, TestActivity%5B%5D currentList) %7B%0A    %09
  String newName 
@@ -1231,24 +1231,25 @@
 e%22;%0A        
+ 
 String newRe
@@ -1276,16 +1276,17 @@
  2200%22;%0A
+ 
         
@@ -1351,32 +1351,33 @@
 List%5Bindex-1%5D);%0A
+ 
         TestActi
@@ -1441,32 +1441,33 @@
 ex-1%5D);%0A        
+ 
 activityAfterEdi
@@ -1486,16 +1486,17 @@
 wName);%0A
+ 
         
@@ -1543,24 +1543,25 @@
 r);%0A        
+ 
 String editC
@@ -1626,28 +1626,31 @@
 minder;%0A    
+%09%0A
     
+%09
 assertUndoEd
@@ -1721,36 +1721,24 @@
 tList);%0A
-    %7D%0A    %0A    %0A    
+%09%09%0A%09%7D%0A%0A%09
 private 

Refactor UndoCommandTest