2021-07-18 14:15:08 +02:00
|
|
|
extends "res://addons/gut/test.gd"
|
2021-07-03 16:57:19 +02:00
|
|
|
|
2022-08-03 12:07:21 +02:00
|
|
|
|
|
|
|
class TestMultipleInputs:
|
|
|
|
# Tests for when Terminal is around other input nodes and arrow keys or TAB
|
|
|
|
# key is pressed. Focus should not change to other inputs when pressing these
|
|
|
|
# keys (same behaviour as TextEdit node).
|
|
|
|
# See: https://github.com/lihop/godot-xterm/issues/51
|
|
|
|
extends "res://addons/gut/test.gd"
|
|
|
|
|
|
|
|
const KEYS := {
|
|
|
|
KEY_LEFT = KEY_LEFT,
|
|
|
|
KEY_UP = KEY_UP,
|
|
|
|
KEY_RIGHT = KEY_RIGHT,
|
|
|
|
KEY_DOWN = KEY_DOWN,
|
|
|
|
KEY_TAB = KEY_TAB,
|
|
|
|
}
|
|
|
|
|
|
|
|
var terminal: Control
|
|
|
|
|
2023-01-20 23:45:28 +01:00
|
|
|
func press_key(keycode: int, unicode := 0) -> void:
|
2022-08-03 12:07:21 +02:00
|
|
|
var key_down = InputEventKey.new()
|
2023-01-20 23:45:28 +01:00
|
|
|
key_down.keycode = keycode
|
|
|
|
key_down.pressed = true
|
2022-08-03 12:07:21 +02:00
|
|
|
Input.parse_input_event(key_down)
|
2022-11-09 21:57:46 +01:00
|
|
|
await get_tree().create_timer(0.1).timeout
|
2022-08-03 12:07:21 +02:00
|
|
|
var key_up = InputEventKey.new()
|
2023-01-20 23:45:28 +01:00
|
|
|
key_up.keycode = keycode
|
|
|
|
key_up.pressed = false
|
2022-08-03 12:07:21 +02:00
|
|
|
Input.parse_input_event(key_up)
|
|
|
|
|
|
|
|
func before_each():
|
2022-11-09 21:57:46 +01:00
|
|
|
var scene := preload("../scenes/multiple_inputs.tscn").instantiate()
|
2022-08-03 12:07:21 +02:00
|
|
|
add_child_autofree(scene)
|
2022-11-09 21:57:46 +01:00
|
|
|
terminal = scene.find_child("Terminal")
|
2022-08-03 12:07:21 +02:00
|
|
|
terminal.grab_focus()
|
|
|
|
|
|
|
|
func test_terminal_keeps_focus_when_certain_keys_pressed():
|
|
|
|
for key in KEYS.keys():
|
|
|
|
press_key(KEYS[key])
|
|
|
|
assert_true(
|
|
|
|
terminal.has_focus(), "Terminal should still have focus after %s is pressed." % key
|
|
|
|
)
|