diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index ac165736001d..74864bce2346 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -181,7 +181,7 @@ private CommandResult executeCommand(String commandText) throws CommandException try { CommandResult commandResult = logic.execute(commandText); logger.info("Result: " + commandResult.getFeedbackToUser()); - resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser()); + resultDisplay.setFeedbackSuccessToUser(commandResult.getFeedbackToUser()); if (commandResult.isShowHelp()) { handleHelp(); @@ -194,7 +194,7 @@ private CommandResult executeCommand(String commandText) throws CommandException return commandResult; } catch (CommandException | ParseException e) { logger.info("Invalid command: " + commandText); - resultDisplay.setFeedbackToUser(e.getMessage()); + resultDisplay.setFeedbackErrorToUser(e.getMessage()); throw e; } } diff --git a/src/main/java/seedu/address/ui/ResultDisplay.java b/src/main/java/seedu/address/ui/ResultDisplay.java index 7d98e84eedf0..b3225fb05858 100644 --- a/src/main/java/seedu/address/ui/ResultDisplay.java +++ b/src/main/java/seedu/address/ui/ResultDisplay.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.TextArea; import javafx.scene.layout.Region; @@ -11,6 +12,8 @@ */ public class ResultDisplay extends UiPart { + public static final String ERROR_STYLE_CLASS = "error"; + private static final String FXML = "ResultDisplay.fxml"; @FXML @@ -20,7 +23,34 @@ public ResultDisplay() { super(FXML); } - public void setFeedbackToUser(String feedbackToUser) { + /** + * Sets the command box style to use the default style. + */ + private void setStyleToDefault() { + resultDisplay.getStyleClass().remove(ERROR_STYLE_CLASS); + } + + /** + * Sets the command box style to indicate a failed command. + */ + private void setStyleToIndicateCommandFailure() { + ObservableList styleClass = resultDisplay.getStyleClass(); + + if (styleClass.contains(ERROR_STYLE_CLASS)) { + return; + } + + styleClass.add(ERROR_STYLE_CLASS); + } + + public void setFeedbackErrorToUser(String feedbackToUser) { + setStyleToIndicateCommandFailure(); + requireNonNull(feedbackToUser); + resultDisplay.setText(feedbackToUser); + } + + public void setFeedbackSuccessToUser(String feedbackToUser) { + setStyleToDefault(); requireNonNull(feedbackToUser); resultDisplay.setText(feedbackToUser); } diff --git a/src/test/java/guitests/guihandles/ResultDisplayHandle.java b/src/test/java/guitests/guihandles/ResultDisplayHandle.java index ec445e4154ff..f5a4f9e720d8 100644 --- a/src/test/java/guitests/guihandles/ResultDisplayHandle.java +++ b/src/test/java/guitests/guihandles/ResultDisplayHandle.java @@ -1,5 +1,6 @@ package guitests.guihandles; +import javafx.collections.ObservableList; import javafx.scene.control.TextArea; /** @@ -19,4 +20,11 @@ public ResultDisplayHandle(TextArea resultDisplayNode) { public String getText() { return getRootNode().getText(); } + + /** + * Returns the list of style classes present in the command box. + */ + public ObservableList getStyleClass() { + return getRootNode().getStyleClass(); + } } diff --git a/src/test/java/seedu/address/ui/ResultDisplayTest.java b/src/test/java/seedu/address/ui/ResultDisplayTest.java index 23a47b651881..fb8b5f5c0bb5 100644 --- a/src/test/java/seedu/address/ui/ResultDisplayTest.java +++ b/src/test/java/seedu/address/ui/ResultDisplayTest.java @@ -2,6 +2,8 @@ import static org.junit.Assert.assertEquals; +import java.util.ArrayList; + import org.junit.Before; import org.junit.Test; @@ -12,6 +14,9 @@ public class ResultDisplayTest extends GuiUnitTest { private ResultDisplay resultDisplay; private ResultDisplayHandle resultDisplayHandle; + private ArrayList defaultStyleOfResultDisplay; + private ArrayList errorStyleOfResultDisplay; + @Before public void setUp() { resultDisplay = new ResultDisplay(); @@ -19,17 +24,82 @@ public void setUp() { resultDisplayHandle = new ResultDisplayHandle(getChildNode(resultDisplay.getRoot(), ResultDisplayHandle.RESULT_DISPLAY_ID)); + + defaultStyleOfResultDisplay = new ArrayList<>(resultDisplayHandle.getStyleClass()); + + errorStyleOfResultDisplay = new ArrayList<>(defaultStyleOfResultDisplay); + errorStyleOfResultDisplay.add(CommandBox.ERROR_STYLE_CLASS); } @Test - public void display() { + public void defaultDisplay_emptyDisplay() { // default result text guiRobot.pauseForHuman(); assertEquals("", resultDisplayHandle.getText()); + } - // new result received - guiRobot.interact(() -> resultDisplay.setFeedbackToUser("Dummy feedback to user")); + @Test + public void emptyFeedback_emptyDisplay() { + guiRobot.interact(() -> resultDisplay.setFeedbackSuccessToUser("")); + guiRobot.pauseForHuman(); + assertEquals("", resultDisplayHandle.getText()); + assertEquals(defaultStyleOfResultDisplay, resultDisplayHandle.getStyleClass()); + } + + @Test + public void successfulFeedback() { + guiRobot.interact(() -> resultDisplay.setFeedbackSuccessToUser("Dummy feedback to user")); guiRobot.pauseForHuman(); assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForSuccessfulFeedback(resultDisplayHandle); + } + + @Test + public void errorFeedback() { + guiRobot.interact(() -> resultDisplay.setFeedbackErrorToUser("Dummy feedback to user")); + guiRobot.pauseForHuman(); + assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForErrorFeedback(resultDisplayHandle); + } + + @Test + public void consecutiveFeedBack() { + // new error result received + guiRobot.interact(() -> resultDisplay.setFeedbackErrorToUser("Dummy feedback to user")); + guiRobot.pauseForHuman(); + assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForErrorFeedback(resultDisplayHandle); + + // new error result received + guiRobot.interact(() -> resultDisplay.setFeedbackErrorToUser("Dummy feedback to user")); + guiRobot.pauseForHuman(); + assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForErrorFeedback(resultDisplayHandle); + + // new success result received + guiRobot.interact(() -> resultDisplay.setFeedbackSuccessToUser("Dummy feedback to user")); + guiRobot.pauseForHuman(); + assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForSuccessfulFeedback(resultDisplayHandle); + + // new success result received + guiRobot.interact(() -> resultDisplay.setFeedbackSuccessToUser("Dummy feedback to user")); + guiRobot.pauseForHuman(); + assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForSuccessfulFeedback(resultDisplayHandle); + + // new error result received + guiRobot.interact(() -> resultDisplay.setFeedbackErrorToUser("Dummy feedback to user")); + guiRobot.pauseForHuman(); + assertEquals("Dummy feedback to user", resultDisplayHandle.getText()); + assertStyleForErrorFeedback(resultDisplayHandle); + } + + private void assertStyleForSuccessfulFeedback(ResultDisplayHandle resultDisplayHandle) { + assertEquals(defaultStyleOfResultDisplay, resultDisplayHandle.getStyleClass()); + } + + private void assertStyleForErrorFeedback(ResultDisplayHandle resultDisplayHandle) { + assertEquals(errorStyleOfResultDisplay, resultDisplayHandle.getStyleClass()); } } diff --git a/src/test/java/systemtests/AddCommandSystemTest.java b/src/test/java/systemtests/AddCommandSystemTest.java index b7e5e2d23a4e..c835684afe47 100644 --- a/src/test/java/systemtests/AddCommandSystemTest.java +++ b/src/test/java/systemtests/AddCommandSystemTest.java @@ -229,6 +229,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); assertStatusBarUnchangedExceptSyncStatus(); } @@ -250,6 +251,7 @@ private void assertCommandFailure(String command, String expectedResultMessage) assertApplicationDisplaysExpected(command, expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsErrorStyle(); + assertResultDisplayShowsErrorStyle(); assertStatusBarUnchanged(); } } diff --git a/src/test/java/systemtests/AddressBookSystemTest.java b/src/test/java/systemtests/AddressBookSystemTest.java index 0baeaf860e6e..3bc9c5d09157 100644 --- a/src/test/java/systemtests/AddressBookSystemTest.java +++ b/src/test/java/systemtests/AddressBookSystemTest.java @@ -39,6 +39,7 @@ import seedu.address.testutil.TypicalPersons; import seedu.address.ui.BrowserPanel; import seedu.address.ui.CommandBox; +import seedu.address.ui.ResultDisplay; /** * A system test class for AddressBook, which provides access to handles of GUI components and helper methods @@ -52,6 +53,12 @@ public abstract class AddressBookSystemTest { private static final List COMMAND_BOX_ERROR_STYLE = Arrays.asList("text-input", "text-field", CommandBox.ERROR_STYLE_CLASS); + private static final List RESULT_DISPLAY_DEFAULT_STYLE = Arrays.asList("text-input", + "text-area", + "result-display"); + private static final List RESULT_DISPLAY_ERROR_STYLE = + Arrays.asList("text-input", "text-area", "result-display", ResultDisplay.ERROR_STYLE_CLASS); + private MainWindowHandle mainWindowHandle; private TestApp testApp; private SystemTestSetupHelper setupHelper; @@ -231,19 +238,33 @@ protected void assertSelectedCardUnchanged() { } /** - * Asserts that the command box's shows the default style. + * Asserts that the command box shows the default style. */ protected void assertCommandBoxShowsDefaultStyle() { assertEquals(COMMAND_BOX_DEFAULT_STYLE, getCommandBox().getStyleClass()); } /** - * Asserts that the command box's shows the error style. + * Asserts that the command box shows the error style. */ protected void assertCommandBoxShowsErrorStyle() { assertEquals(COMMAND_BOX_ERROR_STYLE, getCommandBox().getStyleClass()); } + /** + * Asserts that the result display shows the default style. + */ + protected void assertResultDisplayShowsDefaultStyle() { + assertEquals(RESULT_DISPLAY_DEFAULT_STYLE, getResultDisplay().getStyleClass()); + } + + /** + * Asserts that the result display shows the error style. + */ + protected void assertResultDisplayShowsErrorStyle() { + assertEquals(RESULT_DISPLAY_ERROR_STYLE, getResultDisplay().getStyleClass()); + } + /** * Asserts that the entire status bar remains the same. */ diff --git a/src/test/java/systemtests/ClearCommandSystemTest.java b/src/test/java/systemtests/ClearCommandSystemTest.java index fb01059d9fe4..d439d6ab2d34 100644 --- a/src/test/java/systemtests/ClearCommandSystemTest.java +++ b/src/test/java/systemtests/ClearCommandSystemTest.java @@ -77,6 +77,7 @@ private void assertCommandSuccess(String command, String expectedResultMessage, executeCommand(command); assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel); assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); assertStatusBarUnchangedExceptSyncStatus(); } @@ -96,6 +97,7 @@ private void assertCommandFailure(String command, String expectedResultMessage) assertApplicationDisplaysExpected(command, expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsErrorStyle(); + assertResultDisplayShowsErrorStyle(); assertStatusBarUnchanged(); } } diff --git a/src/test/java/systemtests/DeleteCommandSystemTest.java b/src/test/java/systemtests/DeleteCommandSystemTest.java index 29fbb5fc3930..9b5f6d477fd8 100644 --- a/src/test/java/systemtests/DeleteCommandSystemTest.java +++ b/src/test/java/systemtests/DeleteCommandSystemTest.java @@ -168,6 +168,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex } assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); assertStatusBarUnchangedExceptSyncStatus(); } @@ -188,6 +189,7 @@ private void assertCommandFailure(String command, String expectedResultMessage) assertApplicationDisplaysExpected(command, expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsErrorStyle(); + assertResultDisplayShowsErrorStyle(); assertStatusBarUnchanged(); } } diff --git a/src/test/java/systemtests/EditCommandSystemTest.java b/src/test/java/systemtests/EditCommandSystemTest.java index 5046250c0016..65c683f62557 100644 --- a/src/test/java/systemtests/EditCommandSystemTest.java +++ b/src/test/java/systemtests/EditCommandSystemTest.java @@ -268,6 +268,7 @@ private void assertCommandSuccess(String command, Model expectedModel, String ex expectedModel.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel); assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); if (expectedSelectedCardIndex != null) { assertSelectedCardChanged(expectedSelectedCardIndex); } else { @@ -293,6 +294,7 @@ private void assertCommandFailure(String command, String expectedResultMessage) assertApplicationDisplaysExpected(command, expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsErrorStyle(); + assertResultDisplayShowsErrorStyle(); assertStatusBarUnchanged(); } } diff --git a/src/test/java/systemtests/FindCommandSystemTest.java b/src/test/java/systemtests/FindCommandSystemTest.java index 0bde83c0444b..6ab8c9bee035 100644 --- a/src/test/java/systemtests/FindCommandSystemTest.java +++ b/src/test/java/systemtests/FindCommandSystemTest.java @@ -171,6 +171,7 @@ private void assertCommandSuccess(String command, Model expectedModel) { executeCommand(command); assertApplicationDisplaysExpected("", expectedResultMessage, expectedModel); assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); assertStatusBarUnchanged(); } @@ -190,6 +191,7 @@ private void assertCommandFailure(String command, String expectedResultMessage) assertApplicationDisplaysExpected(command, expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsErrorStyle(); + assertResultDisplayShowsErrorStyle(); assertStatusBarUnchanged(); } } diff --git a/src/test/java/systemtests/HelpCommandSystemTest.java b/src/test/java/systemtests/HelpCommandSystemTest.java index 3fa0cc98236e..73e8b603f434 100644 --- a/src/test/java/systemtests/HelpCommandSystemTest.java +++ b/src/test/java/systemtests/HelpCommandSystemTest.java @@ -63,6 +63,7 @@ public void openHelpWindow() { executeCommand(SelectCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); assertEquals("", getCommandBox().getInput()); assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); assertNotEquals(HelpCommand.SHOWING_HELP_MESSAGE, getResultDisplay().getText()); assertNotEquals(BrowserPanel.DEFAULT_PAGE, getBrowserPanel().getLoadedUrl()); assertListMatching(getPersonListPanel(), getModel().getFilteredPersonList()); diff --git a/src/test/java/systemtests/SelectCommandSystemTest.java b/src/test/java/systemtests/SelectCommandSystemTest.java index 68d024c22e64..35349fd10cb1 100644 --- a/src/test/java/systemtests/SelectCommandSystemTest.java +++ b/src/test/java/systemtests/SelectCommandSystemTest.java @@ -128,6 +128,7 @@ private void assertCommandSuccess(String command, Index expectedSelectedCardInde } assertCommandBoxShowsDefaultStyle(); + assertResultDisplayShowsDefaultStyle(); assertStatusBarUnchanged(); } @@ -149,6 +150,7 @@ private void assertCommandFailure(String command, String expectedResultMessage) assertApplicationDisplaysExpected(command, expectedResultMessage, expectedModel); assertSelectedCardUnchanged(); assertCommandBoxShowsErrorStyle(); + assertResultDisplayShowsErrorStyle(); assertStatusBarUnchanged(); } }