diff options
| author | Sophia Pearson <codergal89@gmail.com> | 2022-05-20 00:45:25 +0200 |
|---|---|---|
| committer | Sophia Pearson <codergal89@gmail.com> | 2022-05-20 18:56:04 +0200 |
| commit | 05d29ccce1898ed89c0b650c77242c2fa2805128 (patch) | |
| tree | e8ee3bcb570fa6f3d9d96273c2bf4d4c8618d08b /Tests | |
| download | texty-05d29ccce1898ed89c0b650c77242c2fa2805128.tar.xz texty-05d29ccce1898ed89c0b650c77242c2fa2805128.zip | |
texty: initial commit
Diffstat (limited to 'Tests')
| -rw-r--r-- | Tests/ComponentTests/test_InputContainer.gd | 94 | ||||
| -rw-r--r-- | Tests/ComponentTests/test_OutputRow.gd | 46 |
2 files changed, 140 insertions, 0 deletions
diff --git a/Tests/ComponentTests/test_InputContainer.gd b/Tests/ComponentTests/test_InputContainer.gd new file mode 100644 index 0000000..3fdaa7b --- /dev/null +++ b/Tests/ComponentTests/test_InputContainer.gd @@ -0,0 +1,94 @@ +extends GutTest + +const Scene = preload('res://Scenes/InputContainer.tscn') +const InputContainer = preload('res://Scripts/InputContainer.cs') + +var _instance: InputContainer = null +var _sender = InputSender.new(Input) +const _test_data = 'This is some test data' +const _input_submitted = 'InputSubmitted' + +func _click_submit_button(): + var button: Button = _instance.SubmitButton + var rect = button.get_global_rect() + var center = (rect.end - rect.size / 2) + _sender.mouse_left_button_down(center, center) \ + .hold_for('1f') \ + .wait('1f') + return _sender + +func _press_enter_key(): + _sender.key_down(KEY_ENTER) \ + .hold_for('1f') \ + .wait('1f') + return _sender + +func _set_input_text(text): + _instance.InputField.text = text + _instance.InputField.emit_signal('text_changed', _instance.InputField.text) + +func before_each(): + _instance = add_child_autofree(Scene.instance()) + +func after_each(): + _sender.release_all() + _sender.clear() + +func test_can_instantiate(): + assert_not_null(_instance) + +func test_has_InputSubmitted_signal(): + assert_has_signal(_instance, _input_submitted) + +func test_has_InputField(): + assert_not_null(_instance.InputField) + +func test_InputField_has_focus_when_scene_is_instantiated(): + assert_true(_instance.InputField.has_focus()) + +func test_InputSubmitted_signal_is_not_emitted_when_enter_is_pressed_without_text_in_InputField(): + watch_signals(_instance) + yield(_press_enter_key(), 'idle') + assert_signal_not_emitted(_instance, _input_submitted) + +func test_InputSubmitted_signal_is_emitted_when_enter_is_pressed_with_text_in_InputField(): + watch_signals(_instance) + _set_input_text(_test_data) + yield(_press_enter_key(), 'idle') + assert_signal_emitted(_instance, _input_submitted) + +func test_InputField_is_empty_after_text_is_submitted(): + _set_input_text(_test_data) + yield(_press_enter_key(), 'idle') + assert_eq(_instance.InputField.text, '') + +func test_has_SubmitButton(): + assert_not_null(_instance.SubmitButton) + +func test_SubmitButton_is_disable_after_scene_was_instantiated(): + assert_true(_instance.SubmitButton.disabled) + +func test_SubmitButton_is_disabled_when_InputField_is_set_to_empty(): + _set_input_text('') + assert_true(_instance.SubmitButton.disabled) + +func test_SubmitButton_is_enabled_when_InputField_is_set_to_some_text(): + _set_input_text(_test_data) + assert_false(_instance.SubmitButton.disabled) + +func test_InputSubmitted_signal_is_not_emitted_when_SubmitButton_is_clicked_without_text_in_InputField(): + watch_signals(_instance) + _set_input_text('') + yield(_click_submit_button(), 'idle') + assert_signal_not_emitted(_instance, _input_submitted) + +func test_InputSubmitted_signal_is_emitted_when_SubmitButton_is_clicked_with_text_in_InputField(): + watch_signals(_instance) + _set_input_text(_test_data) + yield(_click_submit_button(), 'idle') + assert_signal_emitted(_instance, _input_submitted) + +func test_InputField_is_empty_after_text_is_submitted_via_SubmitButton(): + _set_input_text(_test_data) + yield(_click_submit_button(), 'idle') + assert_eq(_instance.InputField.text, '') diff --git a/Tests/ComponentTests/test_OutputRow.gd b/Tests/ComponentTests/test_OutputRow.gd new file mode 100644 index 0000000..6e782de --- /dev/null +++ b/Tests/ComponentTests/test_OutputRow.gd @@ -0,0 +1,46 @@ +extends GutTest + +const Scene = preload("res://Scenes/OutputRow.tscn") +const OutputRow = preload("res://Scripts/OutputRow.cs") + +const _input_text_changed = 'InputTextChanged' +const _output_text_changed = 'OutputTextChanged' +const _test_data = 'This is some test data' +var _instance: OutputRow = null + + +func before_each(): + _instance = add_child_autofree(Scene.instance()) + +func test_can_instantiate(): + assert_not_null(_instance) + +func test_InputText_is_empty_after_instantiation(): + assert_eq(_instance.InputText, '') + +func test_OutputText_is_empty_after_instantiation(): + assert_eq(_instance.OutputText, '') + +func test_Input_contains_text_assigned_to_InputText(): + _instance.InputText = _test_data + assert_eq(_instance.Input.text, _test_data) + +func test_Output_contains_text_assigned_to_OutputText(): + _instance.OutputText = _test_data + assert_eq(_instance.Output.text, _test_data) + +func test_has_InputTextChanged_signal(): + assert_has_signal(_instance, _input_text_changed) + +func test_has_OutputTextChanged_signal(): + assert_has_signal(_instance, _output_text_changed) + +func test_InputTextChanged_signal_is_emitted_when_setting_InputText(): + watch_signals(_instance) + _instance.InputText = _test_data + assert_signal_emitted(_instance, _input_text_changed) + +func test_OutputTextChanged_signal_is_emitted_when_setting_OutputText(): + watch_signals(_instance) + _instance.OutputText = _test_data + assert_signal_emitted(_instance, _output_text_changed) |
