package guitests;

import java.util.ArrayList;

import org.junit.Test;

import seedu.taskell.logic.commands.ViewHistoryCommand;
import seedu.taskell.model.HistoryManager;
import seedu.taskell.ui.DisplayPanel;

public class ViewHistoryCommandTest extends TaskManagerGuiTest {
    
    @Test
    public void viewHistory() {
        String expectedMessage = ViewHistoryCommand.MESSAGE_SUCCESS;
        
        commandBox.runCommand("add smth by tmr");
        commandBox.runCommand("history");
        assertResultMessage(expectedMessage);
        String text = displayPanel.getText();
        assertListMatch(text, HistoryManager.getInstance().getListCommandText());
        
        commandBox.runCommand("edit-desc 1 find socks");
        commandBox.runCommand("hist");
        assertResultMessage(expectedMessage);
        text = displayPanel.getText();
        assertListMatch(text, HistoryManager.getInstance().getListCommandText());
    }

    private void assertListMatch(String result, ArrayList<String> list) {
        String expected = DisplayPanel.MESSAGE_DISPLAY_HISTORY;
        
        for (int i=0; i<list.size(); i++) {
            int index = i+1;
            expected = expected + index + ". " + list.get(i) + "\n";
        }
        
        assert expected.equals(result);
    }
}

@@ -311,24 +311,79 @@
 History() %7B%0A
+        HistoryManager.getInstance().clear();%0A        %0A
         Stri
@@ -982,24 +982,79 @@
 andText());%0A
+        %0A        HistoryManager.getInstance().clear();%0A
     %7D%0A%0A    p

clear history in test