diff options
| author | Sophia Pearson <codergal89@gmail.com> | 2022-09-05 20:35:53 +0200 |
|---|---|---|
| committer | Sophia Pearson <codergal89@gmail.com> | 2022-09-05 20:35:53 +0200 |
| commit | f20bd89dc4a7bf14a88b1effcaa1887b29314525 (patch) | |
| tree | d114787f68efd2a7d61d95fa9c84e8e5d69a7c11 /Tests/Game/test_CommandInputArea.gd | |
| parent | 1b477b62f8be8c546a35dbd1d2688ebf623c496f (diff) | |
| download | texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.tar.xz texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.zip | |
gui: split GUI into Terminal components
Diffstat (limited to 'Tests/Game/test_CommandInputArea.gd')
| -rw-r--r-- | Tests/Game/test_CommandInputArea.gd | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Tests/Game/test_CommandInputArea.gd b/Tests/Game/test_CommandInputArea.gd new file mode 100644 index 0000000..c233ec4 --- /dev/null +++ b/Tests/Game/test_CommandInputArea.gd @@ -0,0 +1,89 @@ +extends GutTest + +const Scene = preload('res://Scenes/Game/CommandInputArea.tscn') +const GameInput = preload('res://Scripts/Game/CommandInputArea.cs') + +var _instance: GameInput = null +var _sender = InputSender.new(Input) + +const _invalid_input = 'ThisIsNotAValidCommand!' +const _valid_input = 'look at door' +const _command_submitted = 'CommandSubmitted' +const _unknown_input_submitted = 'UnknownInputSubmitted' + +func _get_input_node() -> LineEdit: + return _instance.get_node('%TextInput') as LineEdit + +func _set_input_text(text): + var textInputNode = _get_input_node() + textInputNode.text = text + textInputNode.emit_signal('text_changed', textInputNode.text) + +func before_each(): + _instance = add_child_autofree(Scene.instance()) + +func after_each(): + _sender.release_all() + _sender.clear() + +func before_all(): + _sender.set_auto_flush_input(true) + +func after_all(): + assert_no_new_orphans() + +func test_can_instantiate(): + assert_not_null(_instance) + +func test_has_CommandSubmitted_signal(): + assert_has_signal(_instance, _command_submitted) + +func test_has_UnknownInputSubmitted_signal(): + assert_has_signal(_instance, _unknown_input_submitted) + +func test_TextInput_has_focus_when_scene_is_instantiated(): + assert_true(_get_input_node().has_focus()) + +func test_CommandSubmitted_signal_is_not_emitted_when_enter_is_pressed_without_text_in_TextInput(): + watch_signals(_instance) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_signal_not_emitted(_instance, _command_submitted) + +func test_UknownInputSumbmitted_signal_is_not_emitted_when_enter_is_pressed_without_text_in_TextInput(): + watch_signals(_instance) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_signal_not_emitted(_instance, _unknown_input_submitted) + +func test_CommandSubmitted_signal_is_emitted_when_enter_is_pressed_with_a_valid_command_in_TextInput(): + watch_signals(_instance) + _set_input_text(_valid_input) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_signal_emitted(_instance, _command_submitted) + +func test_UnknownInputSubmitted_signal_is_not_emitted_when_enter_is_pressed_with_an_invalid_command_in_TextInput(): + watch_signals(_instance) + _set_input_text(_valid_input) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_signal_not_emitted(_instance, _unknown_input_submitted) + +func test_CommandSubmitted_signal_is_not_emitted_when_enter_is_pressed_with_an_invalid_command_in_TextInput(): + watch_signals(_instance) + _set_input_text(_invalid_input) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_signal_not_emitted(_instance, _command_submitted) + +func test_UnknownInputSubmitted_signal_is_emitted_when_enter_is_pressed_with_a_valid_command_in_TextInput(): + watch_signals(_instance) + _set_input_text(_invalid_input) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_signal_emitted(_instance, _unknown_input_submitted) + +func test_TextInput_is_empty_after_submitting_a_valid_command(): + _set_input_text(_valid_input) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_true(_get_input_node().text.empty()) + +func test_TextInput_is_empty_after_submitting_an_invalid_command(): + _set_input_text(_invalid_input) + UiHelpers.press_key(_sender, KEY_ENTER) + assert_true(_get_input_node().text.empty()) |
