73 lines
2 KiB
GDScript
73 lines
2 KiB
GDScript
extends "res://test_base.gd"
|
|
## Tests for button/ components: action_button, play_button
|
|
|
|
const ActionButtonScript = preload("res://addons/godot-ui/button/action_button.gd")
|
|
const PlayButtonScript = preload("res://addons/godot-ui/button/play_button.gd")
|
|
|
|
|
|
func run_all() -> void:
|
|
_begin_suite("ButtonComponents")
|
|
|
|
_test_action_button_setup()
|
|
_test_play_button_setup()
|
|
_test_action_button_styling()
|
|
_test_play_button_styling()
|
|
|
|
_end_suite()
|
|
|
|
|
|
func _test_action_button_setup() -> void:
|
|
_test("ActionButton setup sets label text")
|
|
var btn: Button = ActionButtonScript.new()
|
|
btn.setup("Reset Position")
|
|
add_child(btn)
|
|
|
|
_assert_eq(btn.text, "Reset Position", "button text")
|
|
_assert_is(btn, Button, "is a Button")
|
|
|
|
btn.queue_free()
|
|
|
|
|
|
func _test_play_button_setup() -> void:
|
|
_test("PlayButton setup sets label text")
|
|
var btn: Button = PlayButtonScript.new()
|
|
btn.setup("Play Sound")
|
|
add_child(btn)
|
|
|
|
_assert_eq(btn.text, "Play Sound", "button text")
|
|
_assert_is(btn, Button, "is a Button")
|
|
|
|
btn.queue_free()
|
|
|
|
|
|
func _test_action_button_styling() -> void:
|
|
_test("ActionButton _ready applies bordered style")
|
|
var btn: Button = ActionButtonScript.new()
|
|
btn.setup("Test")
|
|
add_child(btn)
|
|
|
|
# After add_child, _ready() fires and applies styles
|
|
var style: StyleBox = btn.get_theme_stylebox("normal")
|
|
_assert_not_null(style, "normal stylebox should exist")
|
|
_assert_is(style, StyleBoxFlat, "normal should be StyleBoxFlat")
|
|
|
|
var flat_style: StyleBoxFlat = style as StyleBoxFlat
|
|
_assert_eq(flat_style.bg_color, UiTheme.bg_panel, "bg matches theme")
|
|
|
|
btn.queue_free()
|
|
|
|
|
|
func _test_play_button_styling() -> void:
|
|
_test("PlayButton _ready applies accent filled style")
|
|
var btn: Button = PlayButtonScript.new()
|
|
btn.setup("Test")
|
|
add_child(btn)
|
|
|
|
var style: StyleBox = btn.get_theme_stylebox("normal")
|
|
_assert_not_null(style, "normal stylebox should exist")
|
|
_assert_is(style, StyleBoxFlat, "normal should be StyleBoxFlat")
|
|
|
|
var flat_style: StyleBoxFlat = style as StyleBoxFlat
|
|
_assert_eq(flat_style.bg_color, UiTheme.accent, "bg matches accent")
|
|
|
|
btn.queue_free()
|