forked from nus-cs2103-AY1617S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
231 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package seedu.todo.guitests; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.todo.TestApp; | ||
import seedu.todo.commons.core.ConfigCenter; | ||
import seedu.todo.commons.core.ConfigDefinition; | ||
import seedu.todo.controllers.ConfigController; | ||
|
||
public class ConfigCommandTest extends GuiTest { | ||
|
||
@Test | ||
public void config_showAll_success() { | ||
console.runCommand("config"); | ||
for (ConfigDefinition configDefinition : ConfigCenter.getInstance().getConfig().getDefinitions()) { | ||
assertNotNull(configView.getConfigItem(configDefinition)); | ||
} | ||
} | ||
|
||
@Test | ||
public void config_invalidConfigName_disambig() { | ||
console.runCommand("config invalidConfigName someValue"); | ||
assertEquals(ConfigController.TEMPLATE_SET_CONFIG, console.getConsoleInputText()); | ||
} | ||
|
||
@Test | ||
public void config_tooLittleArgs_disambig() { | ||
console.runCommand("config appTitle"); | ||
assertEquals(ConfigController.TEMPLATE_SET_CONFIG, console.getConsoleInputText()); | ||
} | ||
|
||
@Test | ||
public void config_setAppTitle_success() { | ||
console.runCommand("config appTitle Pokemon Center"); | ||
assertEquals("Pokemon Center", header.getAppTitle()); | ||
assertEquals("Pokemon Center", ConfigCenter.getInstance().getConfig().getAppTitle()); | ||
} | ||
|
||
@Test | ||
public void config_setDatabaseFilePath_success() { | ||
console.runCommand("config databaseFilePath databaseMoved.json"); | ||
assertEquals("databaseMoved.json", ConfigCenter.getInstance().getConfig().getDatabaseFilePath()); | ||
|
||
boolean isFileExists = new File("databaseMoved.json").exists(); | ||
if (isFileExists) { | ||
new File("databaseMoved.json").delete(); | ||
} | ||
|
||
assertTrue(isFileExists); | ||
} | ||
|
||
@Test | ||
public void configDatabaseFilePath_noJsonExtension_error() { | ||
console.runCommand("config databaseFilePath databaseMoved.txt"); | ||
assertEquals(TestApp.SAVE_LOCATION_FOR_TESTING, ConfigCenter.getInstance().getConfig().getDatabaseFilePath()); | ||
assertEquals(String.format(ConfigController.MESSAGE_FAILURE, String.format(ConfigController.MESSAGE_WRONG_EXTENSION, ".json")), | ||
console.getConsoleTextArea()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/java/seedu/todo/guitests/guihandles/ConfigItemHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package seedu.todo.guitests.guihandles; | ||
|
||
import javafx.scene.Node; | ||
import javafx.stage.Stage; | ||
import seedu.todo.commons.core.ConfigDefinition; | ||
import seedu.todo.guitests.GuiRobot; | ||
|
||
// @@author A0139812A | ||
public class ConfigItemHandle extends GuiHandle { | ||
|
||
private static final String CONFIG_NAME_TEXT_ID = "#configName"; | ||
private static final String CONFIG_DESC_TEXT_ID = "#configDescription"; | ||
private static final String CONFIG_VALUE_TEXT_ID = "#configValue"; | ||
private Node node; | ||
|
||
public ConfigItemHandle(GuiRobot guiRobot, Stage primaryStage, Node node){ | ||
super(guiRobot, primaryStage, null); | ||
this.node = node; | ||
} | ||
|
||
public String getConfigName() { | ||
return getStringFromText(CONFIG_NAME_TEXT_ID, node); | ||
} | ||
|
||
public String getConfigDescription() { | ||
return getStringFromText(CONFIG_DESC_TEXT_ID, node); | ||
} | ||
|
||
public String getConfigValue() { | ||
return getStringFromText(CONFIG_VALUE_TEXT_ID, node); | ||
} | ||
|
||
public boolean isEqualsTo(ConfigDefinition configDefinition) { | ||
return getConfigName().equals(configDefinition.getConfigName()) | ||
&& getConfigDescription().equals(configDefinition.getConfigDescription()) | ||
&& getConfigValue().equals(configDefinition.getConfigValue()); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/seedu/todo/guitests/guihandles/ConfigViewHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
package seedu.todo.guitests.guihandles; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.scene.Node; | ||
import javafx.stage.Stage; | ||
import seedu.todo.commons.core.ConfigDefinition; | ||
import seedu.todo.guitests.GuiRobot; | ||
|
||
// @@author A0139812A | ||
public class ConfigViewHandle extends GuiHandle { | ||
|
||
private static final String CONFIGVIEW_TEXT_ID = "#configInstructionsText"; | ||
private static final String CONFIG_ITEM_ID = "#configItem"; | ||
|
||
public ConfigViewHandle(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(CONFIGVIEW_TEXT_ID).queryAll().size() > 0; | ||
} | ||
|
||
public ConfigItemHandle getConfigItem(ConfigDefinition configDefinition) { | ||
Optional<Node> itemNode = guiRobot.lookup(CONFIG_ITEM_ID).queryAll().stream() | ||
.filter(node -> new ConfigItemHandle(guiRobot, primaryStage, node).isEqualsTo(configDefinition)) | ||
.findFirst(); | ||
|
||
if (itemNode.isPresent()) { | ||
return new ConfigItemHandle(guiRobot, primaryStage, itemNode.get()); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/test/java/seedu/todo/guitests/guihandles/HeaderHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package seedu.todo.guitests.guihandles; | ||
|
||
import javafx.stage.Stage; | ||
import seedu.todo.guitests.GuiRobot; | ||
|
||
public class HeaderHandle extends GuiHandle { | ||
|
||
private static final String HEADER_APPTITLE_TEXT_ID = "#headerAppTitle"; | ||
|
||
public HeaderHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) { | ||
super(guiRobot, primaryStage, stageTitle); | ||
} | ||
|
||
public String getAppTitle() { | ||
return getStringFromText(HEADER_APPTITLE_TEXT_ID); | ||
} | ||
|
||
} |
Oops, something went wrong.