Files
MusicPlayer/tests/unit/test_button_bounce.gd
T
Sansan 4a934840f6
Build / test (push) Successful in 1m11s
Build / build (push) Successful in 1m20s
Restyle the music player bar
The bar is rounded and a little taller, with a round orange play button
and a restart button that lights up orange under the mouse. The icons sit
inside their buttons with room around them, and are one colour, cropped to
their shape. Progress fills in orange, the volume slider gets a speaker
icon, and the buttons say their shortcut keys in their tooltips.

Buttons grow a little under the mouse and shrink while held down, and the
play button pops when it switches between play and pause. ButtonBounce
holds these animations so other buttons can use them too.
2026-10-09 17:38:38 +02:00

81 lines
2.2 KiB
GDScript

extends GdUnitTestSuite
## ButtonBounce: buttons grow under the mouse, shrink while held down, pop when asked to,
## and always around their middle.
var _button: Button
func before_test() -> void:
_button = auto_free(Button.new())
_button.size = Vector2(40, 40)
add_child(_button)
ButtonBounce.add_to(_button)
func _settle() -> void:
await await_millis(int(maxf(ButtonBounce.DURATION, ButtonBounce.POP_DURATION) * 1000) + 80)
func test_starts_at_its_normal_size_scaled_around_its_middle() -> void:
assert_vector(_button.scale).is_equal(Vector2.ONE)
assert_vector(_button.pivot_offset).is_equal(Vector2(20, 20))
func test_pivot_follows_the_size() -> void:
_button.size = Vector2(60, 30)
assert_vector(_button.pivot_offset).is_equal(Vector2(30, 15))
func test_grows_when_the_mouse_enters_and_shrinks_back_when_it_leaves() -> void:
_button.mouse_entered.emit()
await _settle()
assert_vector(_button.scale).is_equal_approx(ButtonBounce.HOVER_SCALE, Vector2(0.01, 0.01))
_button.mouse_exited.emit()
await _settle()
assert_vector(_button.scale).is_equal_approx(Vector2.ONE, Vector2(0.01, 0.01))
func test_shrinks_while_held_down() -> void:
_button.button_down.emit()
await _settle()
assert_vector(_button.scale).is_equal_approx(ButtonBounce.PRESSED_SCALE, Vector2(0.01, 0.01))
func test_goes_back_to_normal_when_let_go_away_from_the_mouse() -> void:
_button.button_down.emit()
await _settle()
_button.button_up.emit()
await _settle()
assert_vector(_button.scale).is_equal_approx(Vector2.ONE, Vector2(0.01, 0.01))
func test_disabled_button_does_not_grow() -> void:
_button.disabled = true
_button.mouse_entered.emit()
await _settle()
assert_vector(_button.scale).is_equal(Vector2.ONE)
func test_pop_starts_small_and_springs_back() -> void:
ButtonBounce.pop(_button)
assert_vector(_button.scale).is_equal(ButtonBounce.POP_SCALE)
await _settle()
assert_vector(_button.scale).is_equal_approx(Vector2.ONE, Vector2(0.01, 0.01))
func test_a_new_animation_stops_the_one_before() -> void:
_button.mouse_entered.emit()
_button.button_down.emit()
await _settle()
# Only the last one ran to the end
assert_vector(_button.scale).is_equal_approx(ButtonBounce.PRESSED_SCALE, Vector2(0.01, 0.01))