Files
gplan-2/game/tests/unit/presentation/confirm_dialog_test.gd
T

60 lines
3.1 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends SceneTree
# 确认弹窗按钮位次与语义同钉单元套——
# 守 ConfirmDialog 公开入口 open()/open_three()(四处消费方实际用的两个公开方法)的按钮行子节点序:
# 推进钮恒 child(0)、次推进 child(1)、维持 child(2)(HUD框架.md:90 三条纪律·其三——营地交互修复批 R3)。
# 判据面=树的公开子节点序+Button 公开 text,零私有成员直读;次钮在 open() 里只置 visible=false
# 不从子节点表移除——双钮形态下子节点仍为 3,按下标断必取 child(2)。
# 运行:godot --headless --path game --script res://tests/unit/presentation/confirm_dialog_test.gd(expect 0)
const Kit := preload("res://tests/unit/test_kit.gd")
const ConfirmDialogScript := preload("res://presentation/views/confirm_dialog.gd")
func _initialize() -> void:
# oracle: design/gdd/systems/表现与支撑/HUD框架.md:90 (确认弹窗按钮位次定值——位次与语义同钉组)
call_deferred("_run")
# 按类型向下定位第一个 HBoxContainer(该弹窗树内唯一横排——modal_shell 产 CenterContainer+
# PanelContainer+VBox 不产横排;HSeparator 与 UiKit.button 产件也不是 HBoxContainer)
func _find_btn_row(node: Node) -> HBoxContainer:
if node is HBoxContainer:
return node
for ch in node.get_children():
var found := _find_btn_row(ch)
if found != null:
return found
return null
func _test_two_button_row_order() -> void:
# oracle: design/gdd/systems/表现与支撑/HUD框架.md:90 双钮形态位次=推进在左、维持在右(两钮同钉组)
var ov: Control = ConfirmDialogScript.new()
root.add_child(ov)
ov.open("t", "推进", "维持")
var row := _find_btn_row(ov)
Kit.check("双钮形态按钮行子节点数=3(次钮只隐藏不移除——非空前置)", row != null and row.get_child_count() == 3)
if row != null and row.get_child_count() == 3:
Kit.check("双钮形态位次 child(0)=推进", String((row.get_child(0) as Button).text) == "推进")
Kit.check("双钮形态位次 child(2)=维持(次钮占 child(1) 位——按下标断必取 child(2))", String((row.get_child(2) as Button).text) == "维持")
ov.queue_free()
func _test_three_button_row_order() -> void:
# oracle: design/gdd/systems/表现与支撑/HUD框架.md:90 三钮形态位次=推进/次推/维持(三钮同钉组)
var ov: Control = ConfirmDialogScript.new()
root.add_child(ov)
ov.open_three("t", "推进", "次推", "维持")
var row := _find_btn_row(ov)
Kit.check("三钮形态按钮行子节点数=3(非空前置)", row != null and row.get_child_count() == 3)
if row != null and row.get_child_count() == 3:
Kit.check("三钮形态位次 child(0)=推进", String((row.get_child(0) as Button).text) == "推进")
Kit.check("三钮形态位次 child(1)=次推", String((row.get_child(1) as Button).text) == "次推")
Kit.check("三钮形态位次 child(2)=维持", String((row.get_child(2) as Button).text) == "维持")
ov.queue_free()
func _run() -> void:
_test_two_button_row_order()
_test_three_button_row_order()
quit(Kit.finish("confirm_dialog_test", "PASS — 双钮/三钮形态位次与语义同钉 全过"))