forked from AY2324S1-CS2103-T16-3/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into branch-Documentation/DGSkeleton
* master: Add Ui unit tests for CommandBox Fix magic values issue Update version number Fix style Add comment to ESCAPE key behaviour Update cursor behaviour for command history Improve code style and rename remaining addressbook references Add keypress commandhistory functionality
- Loading branch information
Showing
7 changed files
with
213 additions
and
20 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
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
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,88 @@ | ||
package unicash.ui; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.testfx.api.FxRobot; | ||
import org.testfx.framework.junit5.ApplicationExtension; | ||
import org.testfx.framework.junit5.Start; | ||
|
||
import javafx.scene.Scene; | ||
import javafx.scene.input.KeyCode; | ||
import javafx.stage.Stage; | ||
|
||
|
||
@ExtendWith(ApplicationExtension.class) | ||
public class CommandBoxUiTest { | ||
|
||
private CommandBox commandBox; | ||
|
||
@Start | ||
public void start(Stage stage) { | ||
CommandBox.CommandExecutor dummyExecutor = (commandText) -> { | ||
return null; // A dummy implementation | ||
}; | ||
commandBox = new CommandBox(dummyExecutor); | ||
stage.setScene(new Scene(commandBox.getRoot())); | ||
stage.show(); | ||
} | ||
|
||
@Test | ||
public void upArrowKey_showsPreviousUserInput(FxRobot robot) { | ||
robot.clickOn(commandBox.getCommandTextField()) | ||
.write("testCommand") | ||
.type(KeyCode.ENTER) | ||
.write("anotherTestCommand") | ||
.type(KeyCode.ENTER) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.UP); | ||
|
||
assertEquals("testCommand", commandBox.getCommandTextField().getText()); | ||
} | ||
|
||
@Test | ||
public void downArrowKey_showsNextUserInput(FxRobot robot) { | ||
robot.clickOn(commandBox.getCommandTextField()) | ||
.write("testCommand") | ||
.type(KeyCode.ENTER) | ||
.write("anotherTestCommand") | ||
.type(KeyCode.ENTER) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.DOWN); | ||
|
||
assertEquals("anotherTestCommand", commandBox.getCommandTextField().getText()); | ||
} | ||
|
||
@Test | ||
public void escapeKey_clearsUserInput(FxRobot robot) { | ||
robot.clickOn(commandBox.getCommandTextField()) | ||
.write("testCommand") | ||
.type(KeyCode.ESCAPE) | ||
.write("anotherTestCommand") | ||
.type(KeyCode.ESCAPE) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.ESCAPE); | ||
|
||
assertEquals("", commandBox.getCommandTextField().getText()); | ||
} | ||
|
||
@Test | ||
public void downKeyMultipleTimes_showsClearedUserInput(FxRobot robot) { | ||
robot.clickOn(commandBox.getCommandTextField()) | ||
.write("testCommand") | ||
.type(KeyCode.ENTER) | ||
.write("anotherTestCommand") | ||
.type(KeyCode.ENTER) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.UP) | ||
.type(KeyCode.DOWN) | ||
.type(KeyCode.DOWN) | ||
.type(KeyCode.DOWN); | ||
|
||
assertEquals("", commandBox.getCommandTextField().getText()); | ||
} | ||
|
||
} |