NEO-122: Fix headless GdUnit failures in quest and economy tests.

Add HTTP clients to the scene tree before quest HUD setup, set a stable
1280x720 viewport for economy layout tests, and include RecipesHeaderLabel
in the test section scaffold.
pull/161/head
VinPropane 2026-06-07 13:45:10 -04:00
parent 6397d81ca3
commit 2514772b43
2 changed files with 24 additions and 4 deletions

View File

@ -5,6 +5,8 @@ extends GdUnitTestSuite
const EconomyHudSection := preload("res://scripts/prototype_economy_hud_section.gd") const EconomyHudSection := preload("res://scripts/prototype_economy_hud_section.gd")
const TEST_VIEWPORT_SIZE := Vector2i(1280, 720)
func _build_section() -> Node: func _build_section() -> Node:
var section: VBoxContainer = EconomyHudSection.new() var section: VBoxContainer = EconomyHudSection.new()
@ -18,6 +20,9 @@ func _build_section() -> Node:
body_scroll.name = "BodyScroll" body_scroll.name = "BodyScroll"
var body := VBoxContainer.new() var body := VBoxContainer.new()
body.name = "Body" body.name = "Body"
var recipes_header := Label.new()
recipes_header.name = "RecipesHeaderLabel"
body.add_child(recipes_header)
var inventory := Label.new() var inventory := Label.new()
inventory.name = "InventoryLabel" inventory.name = "InventoryLabel"
body.add_child(inventory) body.add_child(inventory)
@ -27,6 +32,11 @@ func _build_section() -> Node:
return section return section
func _set_test_viewport_size(size: Vector2i = TEST_VIEWPORT_SIZE) -> void:
get_tree().root.size = size
await get_tree().process_frame
func test_body_visible_when_expanded_by_default() -> void: func test_body_visible_when_expanded_by_default() -> void:
# Arrange # Arrange
var section := _build_section() var section := _build_section()
@ -66,6 +76,7 @@ func test_toggle_expands_body_again() -> void:
func test_viewport_layout_pins_section_above_bottom_margin() -> void: func test_viewport_layout_pins_section_above_bottom_margin() -> void:
# Arrange # Arrange
await _set_test_viewport_size()
var section: Control = _build_section() as Control var section: Control = _build_section() as Control
add_child(section) add_child(section)
await await_idle_frame() await await_idle_frame()
@ -75,12 +86,14 @@ func test_viewport_layout_pins_section_above_bottom_margin() -> void:
await get_tree().process_frame await get_tree().process_frame
# Assert # Assert
var vp_height: float = get_viewport().get_visible_rect().size.y var vp_height: float = get_viewport().get_visible_rect().size.y
assert_that(section.position.y).is_greater_equal(0.0)
assert_that(section.position.y).is_greater(vp_height * 0.2) assert_that(section.position.y).is_greater(vp_height * 0.2)
assert_that(section.position.y + section.size.y).is_less_equal(vp_height) assert_that(section.position.y + section.size.y).is_less_equal(vp_height)
func test_viewport_layout_clamps_hud_root_scroll() -> void: func test_viewport_layout_clamps_hud_root_scroll() -> void:
# Arrange # Arrange
await _set_test_viewport_size()
var canvas := Control.new() var canvas := Control.new()
canvas.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) canvas.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var hud_scroll := ScrollContainer.new() var hud_scroll := ScrollContainer.new()
@ -95,4 +108,6 @@ func test_viewport_layout_clamps_hud_root_scroll() -> void:
section.call("_apply_viewport_layout") section.call("_apply_viewport_layout")
await get_tree().process_frame await get_tree().process_frame
# Assert # Assert
assert_that(hud_scroll.size.y).is_less(section.call("panel_top_y")) var panel_top: float = section.call("panel_top_y")
assert_that(panel_top).is_greater(0.0)
assert_that(hud_scroll.size.y).is_less(panel_top)

View File

@ -42,11 +42,16 @@ func test_try_accept_key_input_handles_q_key() -> void:
func test_progress_label_shows_loading_before_snapshot() -> void: func test_progress_label_shows_loading_before_snapshot() -> void:
# Arrange # Arrange
var controller: Node = QuestHudController.new() var controller: Node = QuestHudController.new()
var progress: Node = QuestProgressClient.new()
var defs: Node = QuestDefinitionsClient.new()
var progress_label := Label.new() var progress_label := Label.new()
add_child(controller) add_child(controller)
var progress := QuestProgressClient.new() add_child(progress)
var defs := QuestDefinitionsClient.new() add_child(defs)
controller.call("setup", progress, defs, progress_label, Label.new(), Callable()) await get_tree().process_frame
controller.call(
"setup", progress, defs, progress_label, Label.new(), Callable(self, "_noop_http_config")
)
await get_tree().process_frame await get_tree().process_frame
# Act # Act
var text: String = progress_label.text var text: String = progress_label.text