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
parent
6397d81ca3
commit
2514772b43
|
|
@ -5,6 +5,8 @@ extends GdUnitTestSuite
|
|||
|
||||
const EconomyHudSection := preload("res://scripts/prototype_economy_hud_section.gd")
|
||||
|
||||
const TEST_VIEWPORT_SIZE := Vector2i(1280, 720)
|
||||
|
||||
|
||||
func _build_section() -> Node:
|
||||
var section: VBoxContainer = EconomyHudSection.new()
|
||||
|
|
@ -18,6 +20,9 @@ func _build_section() -> Node:
|
|||
body_scroll.name = "BodyScroll"
|
||||
var body := VBoxContainer.new()
|
||||
body.name = "Body"
|
||||
var recipes_header := Label.new()
|
||||
recipes_header.name = "RecipesHeaderLabel"
|
||||
body.add_child(recipes_header)
|
||||
var inventory := Label.new()
|
||||
inventory.name = "InventoryLabel"
|
||||
body.add_child(inventory)
|
||||
|
|
@ -27,6 +32,11 @@ func _build_section() -> Node:
|
|||
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:
|
||||
# Arrange
|
||||
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:
|
||||
# Arrange
|
||||
await _set_test_viewport_size()
|
||||
var section: Control = _build_section() as Control
|
||||
add_child(section)
|
||||
await await_idle_frame()
|
||||
|
|
@ -75,12 +86,14 @@ func test_viewport_layout_pins_section_above_bottom_margin() -> void:
|
|||
await get_tree().process_frame
|
||||
# Assert
|
||||
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 + section.size.y).is_less_equal(vp_height)
|
||||
|
||||
|
||||
func test_viewport_layout_clamps_hud_root_scroll() -> void:
|
||||
# Arrange
|
||||
await _set_test_viewport_size()
|
||||
var canvas := Control.new()
|
||||
canvas.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
var hud_scroll := ScrollContainer.new()
|
||||
|
|
@ -95,4 +108,6 @@ func test_viewport_layout_clamps_hud_root_scroll() -> void:
|
|||
section.call("_apply_viewport_layout")
|
||||
await get_tree().process_frame
|
||||
# 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)
|
||||
|
|
|
|||
|
|
@ -42,11 +42,16 @@ func test_try_accept_key_input_handles_q_key() -> void:
|
|||
func test_progress_label_shows_loading_before_snapshot() -> void:
|
||||
# Arrange
|
||||
var controller: Node = QuestHudController.new()
|
||||
var progress: Node = QuestProgressClient.new()
|
||||
var defs: Node = QuestDefinitionsClient.new()
|
||||
var progress_label := Label.new()
|
||||
add_child(controller)
|
||||
var progress := QuestProgressClient.new()
|
||||
var defs := QuestDefinitionsClient.new()
|
||||
controller.call("setup", progress, defs, progress_label, Label.new(), Callable())
|
||||
add_child(progress)
|
||||
add_child(defs)
|
||||
await get_tree().process_frame
|
||||
controller.call(
|
||||
"setup", progress, defs, progress_label, Label.new(), Callable(self, "_noop_http_config")
|
||||
)
|
||||
await get_tree().process_frame
|
||||
# Act
|
||||
var text: String = progress_label.text
|
||||
|
|
|
|||
Loading…
Reference in New Issue