Files
aetherbound-guild/runtime/tests/foundation/m46_ui_foundation_test.gd
T

78 lines
3.6 KiB
GDScript

extends SceneTree
const Tokens = preload("res://foundation/ui_tokens.gd")
const UIFactory = preload("res://ui/shared/ui_factory.gd")
const UIIcon = preload("res://ui/shared/ui_icon.gd")
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
# Single target size (owner policy): every screen is authored at 1280x720.
root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_KEEP
root.content_scale_size = Vector2i(1280, 720)
root.size = Vector2i(1280, 720)
verify_tokens()
await verify_factory_controls()
if failures.is_empty():
print("ABG_M46_UI_FOUNDATION_OK tokens=true command_factory=true icons=true notices=true touch=true")
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func verify_tokens() -> void:
expect(Tokens.normalize_variant("company_primary") == "primary", "company primary normalizes to primary")
expect(Tokens.normalize_variant("content_utility") == "utility", "content utility normalizes to utility")
expect(Tokens.normalize_variant("danger") == "danger", "danger remains a supported semantic variant")
expect(Tokens.command_height("primary") == 52 and Tokens.command_height("secondary") == 48, "command heights remain readable")
expect(Tokens.command_size("secondary", Vector2(12, 12)).y >= 48.0, "command size enforces the minimum touch target")
expect(Tokens.icon_kind_supported("settings") and not Tokens.icon_kind_supported("unicode_gear"), "icon vocabulary is explicit")
expect(Tokens.notice_style("warning") is StyleBoxFlat, "notice style is a shared presentation primitive")
func verify_factory_controls() -> void:
var angular := UIFactory.command_button("M46Angular", "确认", "primary", "confirm", "angular", "company", Vector2(190, 52), false, "确认")
root.add_child(angular)
await process_frame
expect(angular.get_meta("ui_factory_control", false), "angular command is marked as a shared control")
expect(String(angular.get_meta("ui_semantic_variant", "")) == "primary", "angular command keeps its semantic variant")
expect(angular.find_child("Chrome", true, false) != null and angular.find_child("ButtonLabel", true, false) != null, "angular command has shared chrome and label")
expect(angular.custom_minimum_size.y >= 52.0, "primary command keeps its canonical height")
var flat := UIFactory.command_button("M46Flat", "返回", "utility", "back", "flat", "company", Vector2(120, 44), false, "返回")
root.add_child(flat)
await process_frame
var icon := flat.find_child("CommandIcon", true, false)
expect(icon is UIIcon, "flat command uses the owned vector icon")
expect(flat.find_child("ButtonLabel", true, false) != null, "flat command has a shared label")
expect(flat.custom_minimum_size.y >= 48.0, "flat command remains touchable")
UIFactory.refresh_command_button(flat, true, true)
expect(flat.disabled and bool(flat.get_meta("ui_selected", false)), "shared refresh applies disabled and selected state")
if icon is UIIcon:
expect((icon as UIIcon).disabled, "icon mirrors disabled state")
var notice := UIFactory.notice_surface("M46Notice", "success")
root.add_child(notice)
await process_frame
expect(notice.get_meta("ui_notice_severity", "") == "success", "notice surface keeps severity metadata")
expect(notice.get_theme_stylebox("panel") is StyleBoxFlat, "notice surface uses a shared style")
angular.queue_free()
flat.queue_free()
notice.queue_free()
await process_frame
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("M46 UI Foundation: %s" % message)