Files
security-game/src/test/tests/test_ui_buttons.gd
T
zwitschi c1cd4898e8
Full build / Import + headless tests (push) Successful in 36s
Full build / Full desktop build + optional release (push) Skipped
Close the 0.9.3 UI polish milestone
Add deterministic captures 14-21 for the remaining screen-design states, fix the panel/button layout issues they exposed, and record 21/21 compare and judge results. Bump the source to 0.9.3 and move the completed milestone to DONE.md.
2026-11-02 17:57:40 +01:00

45 lines
1.9 KiB
GDScript

extends RefCounted
## Shared UI button states: every normal/hover/pressed/focus/disabled state is
## explicitly styled so the custom dark panels do not fall back to the engine
## theme when a control is focused or disabled.
const UiStyles := preload("res://src/game/ui/ui_styles.gd")
const UiFocus := preload("res://src/game/ui/ui_focus.gd")
func test_shared_button_states_are_complete() -> bool:
var button := Button.new()
UiStyles.apply_button(button, 16)
var states := ["normal", "hover", "pressed", "focus", "disabled"]
var missing: Array[String] = []
for state in states:
if not button.has_theme_stylebox_override(state):
missing.append(state)
var a := TestUtils.check(missing.is_empty(),
"all five button states have explicit styles (missing: %s)" % str(missing))
var b := TestUtils.check_eq(button.get_theme_font_size("font_size"), 16,
"the shared style applies the requested font size")
var disabled := button.get_theme_stylebox("disabled")
var normal := button.get_theme_stylebox("normal")
var c := TestUtils.check(disabled != null and normal != null
and disabled.bg_color != normal.bg_color,
"the disabled state is visually distinct from normal")
button.text = "A very long localized action label that must not push the panel beyond the viewport"
var d := TestUtils.check(button.clip_text
and button.get_combined_minimum_size().x < 500.0,
"long action labels ellipsize instead of forcing a wide panel")
button.free()
return a and b and c and d
func test_focus_helper_skips_hidden_and_disabled_controls() -> bool:
var hidden := Button.new()
hidden.visible = false
var disabled := Button.new()
disabled.disabled = true
var normal := Button.new()
var first := UiFocus.first_enabled([hidden, disabled, normal])
var a := TestUtils.check_eq(first, normal, "focus skips hidden and disabled controls")
hidden.free()
disabled.free()
normal.free()
return a