extends GdUnitTestSuite

## NEO-75: economy HUD collapse toggle shows/hides body container.
## Covers economy HUD node paths via EconomyHudSection.get_node in main.gd.

const EconomyHudSection := preload("res://scripts/prototype_economy_hud_section.gd")


func _build_section() -> Node:
	var section: VBoxContainer = EconomyHudSection.new()
	var header := HBoxContainer.new()
	header.name = "HeaderRow"
	var toggle := CheckButton.new()
	toggle.name = "ToggleButton"
	toggle.text = "Economy HUD"
	header.add_child(toggle)
	var body := VBoxContainer.new()
	body.name = "Body"
	var inventory := Label.new()
	inventory.name = "InventoryLabel"
	body.add_child(inventory)
	section.add_child(header)
	section.add_child(body)
	return section


func test_body_visible_when_expanded_by_default() -> void:
	# Arrange
	var section := _build_section()
	add_child(section)
	await await_idle_frame()
	# Act
	var visible: bool = section.call("is_body_visible")
	# Assert
	assert_bool(visible).is_true()


func test_toggle_collapses_body() -> void:
	# Arrange
	var section := _build_section()
	add_child(section)
	await await_idle_frame()
	# Act
	section.get_node("HeaderRow/ToggleButton").button_pressed = false
	await await_idle_frame()
	# Assert
	assert_bool(section.call("is_body_visible")).is_false()


func test_toggle_expands_body_again() -> void:
	# Arrange
	var section := _build_section()
	add_child(section)
	await await_idle_frame()
	section.call("set_expanded", false)
	await await_idle_frame()
	# Act
	section.call("set_expanded", true)
	await await_idle_frame()
	# Assert
	assert_bool(section.call("is_body_visible")).is_true()
