spaceship/tests/test_icon_button.gd
Loïc Wisniewski 85814ce88c Initial commit: SpaceshipTest, a top-down space RTS in Godot 4.7.1
A fleet of neon-outlined ships explores a procedurally generated, seeded
infinite world: tap/joystick steering, pinch zoom, formation pivoting,
planet landings, an ore economy with extractors and haulers, and player
built structures (mothership, ship crafter, command centre).

All art is hand-drawn with draw_* calls rather than textures, and the
backgrounds are camera-relative shaders so they stay precise at large
world coordinates.

Includes a 35-test headless suite (tests/run_tests.sh) plus screenshot
tooling that renders real frames through Xvfb and Mesa softpipe, since
--headless has no GPU.

Excluded from version control: .godot/ (import cache, and it holds
export credentials), builds/, android/build/ and packaged APKs - all
regenerable, and ~325 MB combined.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 18:41:58 +02:00

56 lines
1.8 KiB
GDScript

extends SceneTree
# Headless gameplay test: run with
# godot --headless -s res://tests/test_icon_button.gd
# Verifies IconButton correctly turns a touch-down + touch-up into its
# `pressed` signal, which the Map button is wired to open the world map -
# and that opening the map hides the Map button itself (avoiding it
# overlapping the Close button, which occupies the same corner).
#
# Calls _gui_input directly rather than routing a synthetic touch through
# the viewport's screen-position hit-testing, since headless mode's
# placeholder window makes exact on-screen coordinates unreliable to
# target (see test_world_map_ui.gd's pan test for the same issue) - this
# is a more targeted unit test of the button's own press logic anyway.
var main_scene: Node
var world_map: Control
var map_button: IconButton
var press_count: int = 0
func _initialize() -> void:
var packed: PackedScene = load("res://Main.tscn")
main_scene = packed.instantiate()
root.add_child(main_scene)
world_map = main_scene.get_node("UI/WorldMap")
map_button = main_scene.get_node("UI/MapButton")
map_button.pressed.connect(_on_pressed)
func _on_pressed() -> void:
press_count += 1
func _process(_delta: float) -> bool:
var down: InputEventScreenTouch = InputEventScreenTouch.new()
down.pressed = true
map_button._gui_input(down)
var up: InputEventScreenTouch = InputEventScreenTouch.new()
up.pressed = false
map_button._gui_input(up)
var press_fired: bool = press_count == 1
var map_opened: bool = world_map.visible
var map_button_hidden: bool = not map_button.visible
print("press_fired=%s map_opened=%s map_button_hidden=%s" % [press_fired, map_opened, map_button_hidden])
if press_fired and map_opened and map_button_hidden:
print("TEST_ICON_BUTTON: PASS")
quit(0)
else:
print("TEST_ICON_BUTTON: FAIL")
quit(1)
return true