Skip to content

Commit

Permalink
Merge pull request #261 from ashpa/master
Browse files Browse the repository at this point in the history
complete some gui tests + down arrow key added function
  • Loading branch information
luishengjie authored Jul 18, 2017
2 parents 5f27c19 + 9337280 commit 1869e2e
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 236 deletions.
3 changes: 3 additions & 0 deletions src/main/java/seedu/whatsnext/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public CommandBox(Logic logic) {
if ((logic.getHistory().size() - (i + 1)) >= 0) {
i++;
commandTextField.setText(logic.getHistory().get(logic.getHistory().size() - i));
commandTextField.end();
}
break;

case DOWN:
if ((i - 1) > 0) {
i--;
commandTextField.setText(logic.getHistory().get(logic.getHistory().size() - i));
} else if ((i - 1) == 0) {
commandTextField.setText("");
}
break;

Expand Down
64 changes: 36 additions & 28 deletions src/test/java/guitests/AddCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,71 +1,79 @@
package guitests;

import static org.junit.Assert.assertEquals;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

import guitests.guihandles.DeadlineTaskCardHandle;
import guitests.guihandles.EventTaskCardHandle;
import guitests.guihandles.FloatingTaskCardHandle;
import seedu.whatsnext.commons.exceptions.IllegalValueException;
import seedu.whatsnext.logic.commands.AddCommand;
import seedu.whatsnext.model.tag.Tag;
import seedu.whatsnext.model.task.BasicTask;
import seedu.whatsnext.model.task.BasicTaskFeatures;
import seedu.whatsnext.model.task.DateTime;
import seedu.whatsnext.model.task.TaskDescription;
import seedu.whatsnext.model.task.TaskName;

public class AddCommandTest extends TaskManagerGuiTest {

// @@author A0154987J
@Test
public void add() throws IllegalValueException {

commandBox.pressEnter();
//add floating task
commandBox.runCommand("add Buy a country m/to rule");
BasicTask floatToAdd = new BasicTask(new TaskName("Buy a country"),
commandBox.runCommand("list all");
//add one floating task
BasicTask taskToAdd = new BasicTask(new TaskName("Buy a country"),
new TaskDescription("to rule"), getTagSet());
assertResultMessage(floatToAdd.getTaskDetails());
BasicTaskFeatures selectedFloatingTask = floatingListPanel.getSelectedTasks().get(0).getKey();
assertEquals(floatToAdd, selectedFloatingTask);
commandBox.runCommand("add Buy a country m/to rule");
assertAddSuccess(taskToAdd);
//add duplicate floating task
commandBox.runCommand("add Buy a country m/to rule");
assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
commandBox.runCommand("undo");
commandBox.runCommand("undo");

//add deadline task
commandBox.runCommand("add Buy Present For Gf m/What She Likes e/next Monday t/gf");
BasicTask deadlineToAdd = new BasicTask(new TaskName("Buy Present For Gf"),
//add one deadline task
taskToAdd = new BasicTask(new TaskName("Buy Present For Gf"),
new TaskDescription("What She Likes"),
new DateTime("next Monday"), getTagSet("gf"));
assertResultMessage(deadlineToAdd.getTaskDetails());
BasicTaskFeatures selectedDeadlineTask = deadlineListPanel.getSelectedTasks().get(0).getKey();
assertEquals(deadlineToAdd, selectedDeadlineTask);
commandBox.runCommand("add Buy Present For Gf m/What She Likes e/next Monday t/gf");
assertAddSuccess(taskToAdd);
//add duplicate deadline task
commandBox.runCommand("add Buy Present For Gf m/What She Likes e/next Monday t/gf");
assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
commandBox.runCommand("undo");
commandBox.runCommand("undo");

//add event task
commandBox.runCommand("add Watch Csgo Major m/Fun stuffs s/4 september e/5 september t/overlapping");
BasicTask eventToAdd = new BasicTask(new TaskName("Watch Csgo Major"), new TaskDescription("Fun stuffs"),
taskToAdd = new BasicTask(new TaskName("Watch Csgo Major"), new TaskDescription("Fun stuffs"),
new DateTime("4 september"), new DateTime("5 september"), getTagSet("overlapping"));
assertResultMessage(eventToAdd.getTaskDetails());
BasicTaskFeatures selectedEventTask = eventListPanel.getSelectedTasks().get(0).getKey();
assertEquals(eventToAdd, selectedEventTask);
assertAddSuccess(taskToAdd);
//add duplicate event task
commandBox.runCommand("add Watch Csgo Major m/Fun stuffs s/4 september e/5 september t/overlapping");
assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
commandBox.runCommand("undo");
commandBox.runCommand("undo");
}

private void assertAddSuccess(BasicTask taskToAdd) {
// confirm the new card contains the right data
if (taskToAdd.getTaskType().equals("event")) {
EventTaskCardHandle addedCard = eventListPanel.navigateToEventTask(taskToAdd.getName().toString());
assertMatching(taskToAdd, addedCard);
} else {
if (taskToAdd.getTaskType().equals("deadline")) {
DeadlineTaskCardHandle addedCard = deadlineListPanel
.navigateToDeadlineTask(taskToAdd.getName().toString());
assertMatching(taskToAdd, addedCard);
} else {
if (taskToAdd.getTaskType().equals("floating")) {
FloatingTaskCardHandle addedCard = floatingListPanel
.navigateToFloatingTask(taskToAdd.getName().toString());
assertMatching(taskToAdd, addedCard);
}
}
}
}


/**
* Returns a tag set containing the list of strings given.
*/
public static Set<Tag> getTagSet(String... strings) throws IllegalValueException {
HashSet<Tag> tags = new HashSet<>();
for (String s : strings) {
Expand Down
111 changes: 76 additions & 35 deletions src/test/java/guitests/ClearCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,76 @@
//package guitests;
//
//import static org.junit.Assert.assertTrue;
//
//import org.junit.Test;
//
//import seedu.whatsnext.logic.commands.ClearCommand;
//import seedu.whatsnext.logic.commands.DeleteCommand;
//import seedu.whatsnext.testutil.BasicTaskUtil;
//
//public class ClearCommandTest extends AddressBookGuiTest {
//
// @Test
// public void clear() {
//
// //verify a non-empty list can be cleared
// assertTrue(personListPanel.isListMatching(td.getTypicalPersons()));
// assertClearCommandSuccess();
//
// //verify other commands can work after a clear command
// commandBox.runCommand(BasicTaskUtil.getAddCommand(td.hoon));
// assertTrue(personListPanel.isListMatching(td.hoon));
// commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");
// assertListSize(0);
//
// //verify clear command works when the list is empty
// assertClearCommandSuccess();
// }
//
// private void assertClearCommandSuccess() {
// commandBox.runCommand(ClearCommand.COMMAND_WORD);
// assertListSize(0);
// assertResultMessage("Address book has been cleared!");
// }
//}
package guitests;

import org.junit.Test;

import seedu.whatsnext.logic.commands.ClearCommand;
import seedu.whatsnext.logic.commands.DeleteCommand;

public class ClearCommandTest extends TaskManagerGuiTest {

@Test
public void clearAll() {

commandBox.pressEnter();
commandBox.runCommand("list all");
assertClearCommandSuccess();

//verify other commands can work after a clear command
commandBox.runCommand("add Buy a country m/to rule");
assertListSize(1);
commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");
assertListSize(0);

//verify clear command works when the list is empty
assertClearCommandSuccess();
}

@Test
public void clearIncomplete() {

commandBox.pressEnter();
assertClearIncompleteCommandSuccess();

//verify other commands can work after a clear command
commandBox.runCommand("list completed");
assertListSize(1);
commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1");
assertListSize(0);

//verify clear command works when the list is empty
assertClearCommandSuccess();
}

@Test
public void clearCompleted() {

commandBox.pressEnter();
commandBox.runCommand("list completed");
assertClearCompletedCommandSuccess();

//verify other commands can work after a clear command
assertListSize(0);
commandBox.runCommand("list all");
assertListSize(6);

//verify clear command works when the list is empty
assertClearCommandSuccess();
}

private void assertClearCommandSuccess() {
commandBox.runCommand(ClearCommand.COMMAND_WORD + " all");
assertListSize(0);
assertResultMessage("Task List has been cleared!");
}

private void assertClearIncompleteCommandSuccess() {
commandBox.runCommand(ClearCommand.COMMAND_WORD + " incomplete");
assertListSize(0);
assertResultMessage("Task List has been cleared!");
}

private void assertClearCompletedCommandSuccess() {
commandBox.runCommand(ClearCommand.COMMAND_WORD + " completed");
assertListSize(0);
assertResultMessage("Task List has been cleared!");
}
}
154 changes: 78 additions & 76 deletions src/test/java/guitests/CommandBoxTest.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,78 @@
//package guitests;
//
//import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertFalse;
//import static org.junit.Assert.assertTrue;
//
//import java.util.ArrayList;
//
//import org.junit.Before;
//import org.junit.Test;
//
//import seedu.whatsnext.logic.commands.SelectCommand;
//import seedu.whatsnext.ui.CommandBox;
//
//public class CommandBoxTest extends AddressBookGuiTest {
//
// private static final String COMMAND_THAT_SUCCEEDS = SelectCommand.COMMAND_WORD + " 3";
// private static final String COMMAND_THAT_FAILS = "invalid command";
//
// private ArrayList<String> defaultStyleOfCommandBox;
// private ArrayList<String> errorStyleOfCommandBox;
//
// @Before
// public void setUp() {
// defaultStyleOfCommandBox = new ArrayList<>(commandBox.getStyleClass());
// assertFalse("CommandBox default style classes should not contain error style class.",
// defaultStyleOfCommandBox.contains(CommandBox.ERROR_STYLE_CLASS));
//
// // build style class for error
// errorStyleOfCommandBox = new ArrayList<>(defaultStyleOfCommandBox);
// errorStyleOfCommandBox.add(CommandBox.ERROR_STYLE_CLASS);
// }
//
// @Test
// public void commandBox_startingWithSuccessfulCommand() {
// assertBehaviorForSuccessfulCommand();
// assertBehaviorForFailedCommand();
// }
//
// @Test
// public void commandBox_startingWithFailedCommand() {
// assertBehaviorForFailedCommand();
// assertBehaviorForSuccessfulCommand();
//
// // verify that style is changed correctly even after multiple consecutive successful/failed commands
// assertBehaviorForSuccessfulCommand();
// assertBehaviorForFailedCommand();
// assertBehaviorForFailedCommand();
// assertBehaviorForSuccessfulCommand();
// }
//
// /**
// * Runs a command that fails, then verifies that
// * - the return value of runCommand(...) is false,
// * - the text remains,
// * - the command box has only one ERROR_STYLE_CLASS, with other style classes untouched.
// */
// private void assertBehaviorForFailedCommand() {
// assertFalse(commandBox.runCommand(COMMAND_THAT_FAILS));
// assertEquals(COMMAND_THAT_FAILS, commandBox.getCommandInput());
// assertEquals(errorStyleOfCommandBox, commandBox.getStyleClass());
// }
//
// /**
// * Runs a command that succeeds, then verifies that
// * - the return value of runCommand(...) is true,
// * - the text is cleared,
// * - the command box does not have any ERROR_STYLE_CLASS, with style classes the same as default.
// */
// private void assertBehaviorForSuccessfulCommand() {
// assertTrue(commandBox.runCommand(COMMAND_THAT_SUCCEEDS));
// assertEquals("", commandBox.getCommandInput());
// assertEquals(defaultStyleOfCommandBox, commandBox.getStyleClass());
// }
//
//}
package guitests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

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

import seedu.whatsnext.logic.commands.SelectCommand;
import seedu.whatsnext.ui.CommandBox;

public class CommandBoxTest extends TaskManagerGuiTest {

private static final String COMMAND_THAT_SUCCEEDS = SelectCommand.COMMAND_WORD + " 1";
private static final String COMMAND_THAT_FAILS = "invalid command";

private ArrayList<String> defaultStyleOfCommandBox;
private ArrayList<String> errorStyleOfCommandBox;

@Before
public void setUp() {
defaultStyleOfCommandBox = new ArrayList<>(commandBox.getStyleClass());
assertFalse("CommandBox default style classes should not contain error style class.",
defaultStyleOfCommandBox.contains(CommandBox.ERROR_STYLE_CLASS));

// build style class for error
errorStyleOfCommandBox = new ArrayList<>(defaultStyleOfCommandBox);
errorStyleOfCommandBox.add(CommandBox.ERROR_STYLE_CLASS);
}

@Test
public void commandBox_startingWithSuccessfulCommand() {
commandBox.pressEnter();
assertBehaviorForSuccessfulCommand();
assertBehaviorForFailedCommand();
}

@Test
public void commandBox_startingWithFailedCommand() {
commandBox.pressEnter();
assertBehaviorForFailedCommand();
assertBehaviorForSuccessfulCommand();

// verify that style is changed correctly even after multiple consecutive successful/failed commands
assertBehaviorForSuccessfulCommand();
assertBehaviorForFailedCommand();
assertBehaviorForFailedCommand();
assertBehaviorForSuccessfulCommand();
}

/**
* Runs a command that fails, then verifies that
* - the return value of runCommand(...) is false,
* - the text remains,
* - the command box has only one ERROR_STYLE_CLASS, with other style classes untouched.
*/
private void assertBehaviorForFailedCommand() {
assertFalse(commandBox.runCommand(COMMAND_THAT_FAILS));
assertEquals(COMMAND_THAT_FAILS, commandBox.getCommandInput());
assertEquals(errorStyleOfCommandBox, commandBox.getStyleClass());
}

/**
* Runs a command that succeeds, then verifies that
* - the return value of runCommand(...) is true,
* - the text is cleared,
* - the command box does not have any ERROR_STYLE_CLASS, with style classes the same as default.
*/
private void assertBehaviorForSuccessfulCommand() {
assertTrue(commandBox.runCommand(COMMAND_THAT_SUCCEEDS));
assertEquals("", commandBox.getCommandInput());
assertEquals(defaultStyleOfCommandBox, commandBox.getStyleClass());
}

}
Loading

0 comments on commit 1869e2e

Please sign in to comment.