Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HelpController test #183

Merged
merged 4 commits into from
Nov 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/seedu/todo/controllers/HelpController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void process(String input) {
UiManager.updateConsoleMessage(MESSAGE_HELP_SUCCESS);
}

private CommandDefinition[] getAllCommandDefinitions() {
public CommandDefinition[] getAllCommandDefinitions() {
return new CommandDefinition[] { new HelpController().getCommandDefinition(),
new AddController().getCommandDefinition(),
new ListController().getCommandDefinition(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/ui/components/HelpCommandItem.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?import javafx.scene.text.Text?>

<!-- @@author A0139812A -->
<VBox maxHeight="Infinity" maxWidth="Infinity" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seedu.todo.ui.components.HelpCommandItem">
<VBox fx:id="helpCommandItem" maxHeight="Infinity" maxWidth="Infinity" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seedu.todo.ui.components.HelpCommandItem">
<children>
<Text fx:id="commandNameText" styleClass="font-300, commandtext-name">
<VBox.margin>
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/seedu/todo/guitests/GuiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import seedu.todo.commons.util.DateUtil;
import seedu.todo.guitests.guihandles.AliasViewHandle;
import seedu.todo.guitests.guihandles.ConsoleHandle;
import seedu.todo.guitests.guihandles.HelpViewHandle;
import seedu.todo.guitests.guihandles.MainGuiHandle;
import seedu.todo.guitests.guihandles.TaskListDateItemHandle;
import seedu.todo.guitests.guihandles.TaskListEventItemHandle;
Expand All @@ -45,6 +46,7 @@ public abstract class GuiTest {
protected ConsoleHandle console;
protected TaskListHandle taskList;
protected AliasViewHandle aliasView;
protected HelpViewHandle helpView;

private Stage stage;

Expand All @@ -65,6 +67,7 @@ public void setup() throws Exception {
console = mainGui.getConsole();
taskList = mainGui.getTaskList();
aliasView = mainGui.getAliasView();
helpView = mainGui.getHelpView();
// TODO: create handles for other components
this.stage = stage;
});
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/seedu/todo/guitests/HelpCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package seedu.todo.guitests;

import static org.junit.Assert.*;

import org.junit.Test;

import seedu.todo.controllers.CommandDefinition;
import seedu.todo.controllers.HelpController;
import seedu.todo.guitests.guihandles.HelpItemHandle;

public class HelpCommandTest extends GuiTest {

@Test
public void help_show_success() {
console.runCommand("help");
assertTrue(helpView.hasLoaded());

// Make sure all command items have loaded
for (CommandDefinition commandDefinition : new HelpController().getAllCommandDefinitions()) {
HelpItemHandle helpItem = helpView.getHelpItem(commandDefinition);
assertNotNull(helpItem);
}
}

@Test
public void help_extraArguments_noDifference() {
console.runCommand("help me i'm drowning");
assertTrue(helpView.hasLoaded());

// Make sure all command items have loaded
for (CommandDefinition commandDefinition : new HelpController().getAllCommandDefinitions()) {
HelpItemHandle helpItem = helpView.getHelpItem(commandDefinition);
assertNotNull(helpItem);
}
}

}
38 changes: 38 additions & 0 deletions src/test/java/seedu/todo/guitests/guihandles/HelpItemHandle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seedu.todo.guitests.guihandles;

import javafx.scene.Node;
import javafx.stage.Stage;
import seedu.todo.controllers.CommandDefinition;
import seedu.todo.guitests.GuiRobot;

public class HelpItemHandle extends GuiHandle {

private static final String COMMAND_NAME_TEXT_ID = "#commandNameText";
private static final String COMMAND_SYNTAX_TEXT_ID = "#commandSyntaxText";
private static final String COMMAND_DESC_TEXT_ID = "#commandDescriptionText";
private Node node;

public HelpItemHandle(GuiRobot guiRobot, Stage primaryStage, Node node){
super(guiRobot, primaryStage, null);
this.node = node;
}

public String getCommandName() {
return getStringFromText(COMMAND_NAME_TEXT_ID, node);
}

public String getCommandSyntax() {
return getStringFromText(COMMAND_SYNTAX_TEXT_ID, node);
}

public String getCommandDescription() {
return getStringFromText(COMMAND_DESC_TEXT_ID, node);
}

public boolean isEqualsTo(CommandDefinition commandDefinition) {
return getCommandName().equals(commandDefinition.getCommandName())
&& getCommandSyntax().equals(commandDefinition.getCommandSyntax())
&& getCommandDescription().equals(commandDefinition.getCommandDescription());
}

}
38 changes: 38 additions & 0 deletions src/test/java/seedu/todo/guitests/guihandles/HelpViewHandle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seedu.todo.guitests.guihandles;

import java.util.Optional;

import javafx.scene.Node;
import javafx.stage.Stage;
import seedu.todo.controllers.CommandDefinition;
import seedu.todo.guitests.GuiRobot;

//@@author A0139812A
public class HelpViewHandle extends GuiHandle {

private static final String HELPVIEW_PLACEHOLDER_ID = "#helpCommandsPlaceholder";
private static final String HELP_ITEM_ID = "#helpCommandItem";

public HelpViewHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) {
super(guiRobot, primaryStage, stageTitle);
}

/**
* Checks for the existence of a child element to determine if the view has loaded correctly.
*/
public boolean hasLoaded() {
return guiRobot.lookup(HELPVIEW_PLACEHOLDER_ID).queryAll().size() > 0;
}

public HelpItemHandle getHelpItem(CommandDefinition commandDefinition) {
Optional<Node> itemNode = guiRobot.lookup(HELP_ITEM_ID).queryAll().stream()
.filter(node -> new HelpItemHandle(guiRobot, primaryStage, node).isEqualsTo(commandDefinition))
.findFirst();

if (itemNode.isPresent()) {
return new HelpItemHandle(guiRobot, primaryStage, itemNode.get());
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public AliasViewHandle getAliasView() {
return new AliasViewHandle(guiRobot, primaryStage, TestApp.APP_TITLE);
}

public HelpViewHandle getHelpView() {
return new HelpViewHandle(guiRobot, primaryStage, TestApp.APP_TITLE);
}

public TaskListHandle getTaskList() {
return new TaskListHandle(guiRobot, primaryStage, TestApp.APP_TITLE);
}
Expand Down