Skip to content

Commit

Permalink
Merge branch 'undo-redo-tests-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
louietyj committed Nov 5, 2016
2 parents 28ace40 + 24a2762 commit 7e11eb8
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/test/java/seedu/todo/guitests/UndoRedoCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package seedu.todo.guitests;

import static org.junit.Assert.*;

import java.time.LocalDateTime;

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

import seedu.todo.commons.util.DateUtil;
import seedu.todo.models.Task;
import seedu.todo.models.TodoListDB;

/**
* @@author A0093907W
*/
public class UndoRedoCommandTest extends GuiTest {

private final LocalDateTime oneDayFromNow = LocalDateTime.now().plusDays(1);
private final String oneDayFromNowString = DateUtil.formatDate(oneDayFromNow);
private final String oneDayFromNowIsoString = DateUtil.formatIsoDate(oneDayFromNow);
private final LocalDateTime twoDaysFromNow = LocalDateTime.now().plusDays(2);
private final String twoDaysFromNowString = DateUtil.formatDate(twoDaysFromNow);
private final String twoDaysFromNowIsoString = DateUtil.formatIsoDate(twoDaysFromNow);

String commandAdd1 = String.format("add task Buy KOI by \"%s 8pm\"", oneDayFromNowString);
Task task1 = new Task();
String commandAdd2 = String.format("add task Buy Milk by \"%s 9pm\"", twoDaysFromNowString);
Task task2 = new Task();

public UndoRedoCommandTest() {
task1.setName("Buy KOI");
task1.setCalendarDateTime(DateUtil.parseDateTime(String.format("%s 20:00:00", oneDayFromNowIsoString)));
task2.setName("Buy Milk");
task2.setDueDate(DateUtil.parseDateTime(String.format("%s 21:00:00", twoDaysFromNowIsoString)));
}

@Before
public void resetDB() {
TodoListDB db = TodoListDB.getInstance();
db.destroyAllEvent();
db.destroyAllTask();
}

@Test
public void undo_single() {
console.runCommand("clear");
assertTaskVisibleAfterCmd(commandAdd1, task1);
assertTaskVisibleAfterCmd(commandAdd2, task2);
assertTaskNotVisibleAfterCmd("undo", task2);
}

@Test
public void undo_multiple() {
console.runCommand("clear");
assertTaskVisibleAfterCmd(commandAdd1, task1);
assertTaskVisibleAfterCmd(commandAdd2, task2);
assertTaskNotVisibleAfterCmd("undo 2", task1);
assertTaskNotVisibleAfterCmd("list", task2); // A li'l hacky but oh well
}

@Test
public void undo_notavailable() {
console.runCommand("clear");
assertTaskVisibleAfterCmd(commandAdd1, task1);
assertTaskNotVisibleAfterCmd("undo", task1);
console.runCommand("undo");
console.runCommand("undo");
assertEquals(console.getConsoleTextArea(), "There is no command to undo!");
}

@Test
public void undo_multiple_notavailable() {
console.runCommand("clear");
console.runCommand("undo 2");
assertEquals(console.getConsoleTextArea(), "We cannot undo 2 commands! At most, you can undo 1 command.");
}

@Test
public void redo_single() {
console.runCommand("clear");
assertTaskVisibleAfterCmd(commandAdd1, task1);
assertTaskNotVisibleAfterCmd("undo", task1);
assertTaskVisibleAfterCmd("redo", task1);
}

@Test
public void redo_multiple() {
console.runCommand("clear");
assertTaskVisibleAfterCmd(commandAdd1, task1);
assertTaskVisibleAfterCmd(commandAdd2, task2);
assertTaskNotVisibleAfterCmd("undo 2", task1);
assertTaskNotVisibleAfterCmd("list", task2);
assertTaskVisibleAfterCmd("redo 2", task1);
assertTaskVisibleAfterCmd("list", task2);
}

@Test
public void redo_notavailable() {
console.runCommand("clear");
console.runCommand("redo");
assertEquals(console.getConsoleTextArea(), "There is no command to redo!");
}

@Test
public void redo_multiple_notavailable() {
console.runCommand("clear");
console.runCommand("undo");
console.runCommand("redo 2");
assertEquals(console.getConsoleTextArea(), "We cannot redo 2 commands! At most, you can redo 1 command.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class ConsoleHandle extends GuiHandle {

private static final String CONSOLE_INPUT_ID = "#consoleInputTextField";
private static final String CONSOLE_TEXT_ID = "#consoleTextArea";
private static final int COMMAND_WAIT_TIME = 500;

public ConsoleHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) {
Expand All @@ -19,6 +20,10 @@ public String getConsoleInputText() {
return getTextFieldText(CONSOLE_INPUT_ID);
}

public String getConsoleTextArea() {
return getTextAreaText(CONSOLE_TEXT_ID);
}

public void enterCommand(String command) {
setTextField(CONSOLE_INPUT_ID, command);
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/seedu/todo/guitests/guihandles/GuiHandle.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.todo.guitests.guihandles;

import javafx.scene.Node;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.text.Text;
Expand Down Expand Up @@ -59,6 +60,10 @@ protected Node getNode(String query) {
protected String getTextFieldText(String filedName) {
return ((TextField) getNode(filedName)).getText();
}

protected String getTextAreaText(String filedName) {
return ((TextArea) getNode(filedName)).getText();
}

protected void setTextField(String textFieldId, String newText) {
guiRobot.clickOn(textFieldId);
Expand Down

0 comments on commit 7e11eb8

Please sign in to comment.