From f20bd89dc4a7bf14a88b1effcaa1887b29314525 Mon Sep 17 00:00:00 2001 From: Sophia Pearson Date: Mon, 5 Sep 2022 20:35:53 +0200 Subject: gui: split GUI into Terminal components --- Tests/Game/test_CommandInputArea.gd | 89 +++++++++++++++++++++++++++++++++++++ Tests/Game/test_Game.gd | 50 +++++++++++++++++++++ Tests/Game/test_Input.gd | 86 ----------------------------------- Tests/Game/test_Output.gd | 51 --------------------- Tests/Game/test_OutputBlock.gd | 32 ------------- Tests/Game/test_StatusLine.gd | 32 ------------- 6 files changed, 139 insertions(+), 201 deletions(-) create mode 100644 Tests/Game/test_CommandInputArea.gd create mode 100644 Tests/Game/test_Game.gd delete mode 100644 Tests/Game/test_Input.gd delete mode 100644 Tests/Game/test_Output.gd delete mode 100644 Tests/Game/test_OutputBlock.gd delete mode 100644 Tests/Game/test_StatusLine.gd (limited to 'Tests/Game') 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()) diff --git a/Tests/Game/test_Game.gd b/Tests/Game/test_Game.gd new file mode 100644 index 0000000..427d28c --- /dev/null +++ b/Tests/Game/test_Game.gd @@ -0,0 +1,50 @@ +extends GutTest + +const Scene = preload('res://Scenes/Game/Game.tscn') +const Game = preload('res://Scripts/Game/Game.cs') + +const InputArea = preload('res://Scripts/Game/CommandInputArea.cs') +const OutputArea = preload('res://Scripts/Terminal/OutputArea.cs') + +var _instance: Game = null +var _sender = InputSender.new(Input) + +func _get_output_area() -> OutputArea: + return _instance.get_node('%OutputArea') as OutputArea + +func _get_input_area() -> InputArea: + return _instance.get_node('%InputArea') as InputArea + +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_OutputArea(): + assert_not_null(_get_output_area()) + +func test_OutputArea_is_empty_after_instantiation(): + assert_true(_get_output_area().TextBlocks.empty()) + +func test_has_InputArea(): + assert_not_null(_get_input_area()) + +func test_InputArea_has_focus_after_instantiation(): + assert_true(_get_input_area().HasFocus) + +func test_after_submitting_some_text_via_InputArea_OutputArea_is_not_empty(): + var textInput = _get_input_area().get_node('%TextInput') + textInput.text = 'this is a test' + UiHelpers.press_key(_sender, KEY_ENTER) + assert_false(_get_output_area().TextBlocks.empty()) diff --git a/Tests/Game/test_Input.gd b/Tests/Game/test_Input.gd deleted file mode 100644 index fca14e5..0000000 --- a/Tests/Game/test_Input.gd +++ /dev/null @@ -1,86 +0,0 @@ -extends GutTest - -const Scene = preload('res://Scenes/Game/Input.tscn') -const GameInput = preload('res://Scripts/Game/Input.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 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) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - 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) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - 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) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - 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) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - 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) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - 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) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - assert_signal_emitted(_instance, _unknown_input_submitted) - -func test_TextInput_is_empty_after_submitting_a_valid_command(): - _set_input_text(_valid_input) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - assert_true(_get_input_node().text.empty()) - -func test_TextInput_is_empty_after_submitting_an_invalid_command(): - _set_input_text(_invalid_input) - yield(UiHelpers.press_key(_sender, KEY_ENTER), 'idle') - assert_true(_get_input_node().text.empty()) diff --git a/Tests/Game/test_Output.gd b/Tests/Game/test_Output.gd deleted file mode 100644 index f3793de..0000000 --- a/Tests/Game/test_Output.gd +++ /dev/null @@ -1,51 +0,0 @@ -extends GutTest - -const Scene = preload('res://Scenes/Game/Output.tscn') -const GameOutput = preload('res://Scripts/Game/Output.cs') - -var _instance: GameOutput = null - -func _get_line_container() -> VBoxContainer: - return _instance.get_node('%LineContainer') as VBoxContainer - -func after_each(): - yield(yield_frames(1), YIELD) - -func before_each(): - var scene = Scene.instance() - scene.OutputBlockScene = load('res://Scenes/Game/OutputBlock.tscn') - _instance = add_child_autofree(scene) - -func after_all(): - assert_no_new_orphans() - -func test_can_be_instantiated(): - assert_not_null(_instance) - -func test_LineContainer_is_empty_after_instantiation(): - assert_true(_get_line_container().get_children().empty()) - -func test_TextBlocks_is_empty_after_instantiation(): - assert_true(_instance.TextBlocks.empty()) - -func test_LineContainer_is_not_empty_after_calling_Push_with_a_non_empty_string_as_text(): - _instance.Push('this is some test data') - assert_false(_get_line_container().get_children().empty()) - -func test_LineContainer_is_empty_after_calling_Push_with_an_empty_string_as_text(): - _instance.Push('') - assert_true(_get_line_container().get_children().empty()) - -func test_TextBlocks_is_not_empty_after_calling_Push_with_a_non_empty_string_as_text(): - _instance.Push('this is some test data') - assert_false(_instance.TextBlocks.empty()) - -func test_TextBlocks_is_empty_after_calling_Push_with_an_empty_string_as_text(): - _instance.Push('') - assert_true(_instance.TextBlocks.empty()) - -func test_TextBlocks_contains_all_pushed_texts_in_the_push_order(): - var texts = ['text block a', 'text block b'] - for text in texts: - _instance.Push(text) - assert_eq(_instance.TextBlocks, texts) diff --git a/Tests/Game/test_OutputBlock.gd b/Tests/Game/test_OutputBlock.gd deleted file mode 100644 index c7addfe..0000000 --- a/Tests/Game/test_OutputBlock.gd +++ /dev/null @@ -1,32 +0,0 @@ -extends GutTest - -const Scene = preload("res://Scenes/Game/OutputBlock.tscn") -const OutputBlock = preload("res://Scripts/Game/OutputBlock.cs") - -const _input_text_changed = 'InputTextChanged' -const _output_text_changed = 'OutputTextChanged' -const _test_data = 'This is some test data' -var _instance: OutputBlock = null - - -func before_each(): - _instance = add_child_autofree(Scene.instance()) - -func after_all(): - assert_no_new_orphans() - -func test_can_instantiate(): - assert_not_null(_instance) - -func test_Content_is_empty_after_instantiation(): - assert_eq(_instance.Content, '') - -func test_ContentLabel_bbcode_enabled_is_enabled_after_instantiation(): - assert_true(_instance.get_node('ContentLabel').bbcode_enabled) - -func test_ContentLabel_is_empty_after_instantiation(): - assert_eq(_instance.get_node('ContentLabel').bbcode_text, '') - -func test_setting_Content_sets_ContentLabel_bbcode_text(): - _instance.Content = 'test' - assert_eq(_instance.get_node('ContentLabel').bbcode_text, 'test') diff --git a/Tests/Game/test_StatusLine.gd b/Tests/Game/test_StatusLine.gd deleted file mode 100644 index b22f624..0000000 --- a/Tests/Game/test_StatusLine.gd +++ /dev/null @@ -1,32 +0,0 @@ -extends GutTest - -const Scene = preload("res://Scenes/Game/StatusLine.tscn") -const StatusLine = preload("res://Scripts/Game/StatusLine.cs") - -var _instance: StatusLine = null - -func _get_title_label() -> RichTextLabel: - return _instance.get_node('%TitleLabel') as RichTextLabel - -func before_each(): - _instance = add_child_autofree(Scene.instance()) - -func after_all(): - assert_no_new_orphans() - -func test_can_be_instantiated(): - assert_not_null(_instance) - -func test_Title_is_empty_after_instantiation(): - assert_true(_instance.Title.empty()) - -func test_TitleLabel_is_empty_after_instantiation(): - assert_true(_get_title_label().text.empty()) - -func test_setting_Title_to_a_non_empty_string_makes_TitleLable_non_empty(): - _instance.Title = 'this is a test title' - assert_false(_get_title_label().text.empty()) - -func test_setting_Title_sets_the_bbcode_text_property_on_TitleLabel(): - _instance.Title = '[wave]this is a test title[/wave]' - assert_false(_get_title_label().bbcode_text.empty()) -- cgit v1.2.3