105 lines
3.2 KiB
GDScript
105 lines
3.2 KiB
GDScript
extends GdUnitTestSuite
|
|
|
|
## NEO-122 follow-up: craft recipe panel rows + economy body scroll reset.
|
|
|
|
const CraftRecipePanel := preload("res://scripts/craft_recipe_panel.gd")
|
|
const EconomyHudSection := preload("res://scripts/prototype_economy_hud_section.gd")
|
|
|
|
|
|
static func _sample_recipes() -> Array:
|
|
return [
|
|
{
|
|
"id": "refine_scrap_standard",
|
|
"displayName": "Refine Scrap (Standard)",
|
|
"inputs": [{"itemId": "scrap_metal_bulk", "quantity": 5}],
|
|
},
|
|
{
|
|
"id": "refine_scrap_efficient",
|
|
"displayName": "Refine Scrap (Efficient)",
|
|
"inputs": [{"itemId": "scrap_metal_bulk", "quantity": 10}],
|
|
},
|
|
]
|
|
|
|
|
|
func _build_panel() -> Control:
|
|
var panel: Control = CraftRecipePanel.new()
|
|
var rows := VBoxContainer.new()
|
|
rows.name = "RecipeRows"
|
|
panel.add_child(rows)
|
|
auto_free(panel)
|
|
add_child(panel)
|
|
await get_tree().process_frame
|
|
return panel
|
|
|
|
|
|
func _build_panel_in_economy_section() -> Dictionary:
|
|
var section: VBoxContainer = EconomyHudSection.new()
|
|
var header := HBoxContainer.new()
|
|
header.name = "HeaderRow"
|
|
var toggle := CheckButton.new()
|
|
toggle.name = "ToggleButton"
|
|
header.add_child(toggle)
|
|
var body_scroll := ScrollContainer.new()
|
|
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 panel: Control = CraftRecipePanel.new()
|
|
panel.name = "CraftRecipePanel"
|
|
var rows := VBoxContainer.new()
|
|
rows.name = "RecipeRows"
|
|
panel.add_child(rows)
|
|
body.add_child(panel)
|
|
body_scroll.add_child(body)
|
|
section.add_child(header)
|
|
section.add_child(body_scroll)
|
|
auto_free(section)
|
|
add_child(section)
|
|
await get_tree().process_frame
|
|
return {"section": section, "panel": panel, "body_scroll": body_scroll}
|
|
|
|
|
|
func test_populate_builds_one_row_per_recipe() -> void:
|
|
# Arrange
|
|
var panel := await _build_panel()
|
|
# Act
|
|
panel.call("populate", _sample_recipes())
|
|
await get_tree().process_frame
|
|
# Assert
|
|
var rows: VBoxContainer = panel.get_node("RecipeRows")
|
|
assert_that(rows.get_child_count()).is_equal(2)
|
|
|
|
|
|
func test_populate_scrolls_economy_body_to_recipes() -> void:
|
|
# Arrange
|
|
var built: Dictionary = await _build_panel_in_economy_section()
|
|
var panel: Control = built["panel"]
|
|
var body_scroll: ScrollContainer = built["body_scroll"]
|
|
body_scroll.scroll_vertical = 999
|
|
# Act
|
|
panel.call("populate", _sample_recipes())
|
|
await get_tree().process_frame
|
|
await get_tree().process_frame
|
|
# Assert
|
|
assert_that(body_scroll.scroll_vertical).is_equal(0)
|
|
|
|
|
|
func test_populate_emits_craft_requested_for_row() -> void:
|
|
# Arrange
|
|
var panel := await _build_panel()
|
|
var captured: Array = []
|
|
panel.connect("craft_requested", func(recipe_id: String) -> void: captured.append(recipe_id))
|
|
panel.call("populate", _sample_recipes())
|
|
await get_tree().process_frame
|
|
var rows: VBoxContainer = panel.get_node("RecipeRows")
|
|
var first_row: VBoxContainer = rows.get_child(0) as VBoxContainer
|
|
var btn_row: HBoxContainer = first_row.get_child(1) as HBoxContainer
|
|
var craft_btn: Button = btn_row.get_child(0) as Button
|
|
# Act
|
|
craft_btn.pressed.emit()
|
|
# Assert
|
|
assert_that(captured.size()).is_equal(1)
|
|
assert_that(str(captured[0])).is_equal("refine_scrap_standard")
|