Files
Cozypaw-Hospital/test/unit/test_gift_box.gd
T
2026-05-11 20:05:21 +02:00

70 lines
2.0 KiB
GDScript

## Tests for GiftBox — CLOSED/OPENING/RESETTING state machine transitions.
extends GutTest
var _box: GiftBox
func before_each() -> void:
_box = preload("res://scenes/objects/GiftBox.tscn").instantiate() as GiftBox
add_child_autofree(_box)
func test_initial_state_is_closed() -> void:
assert_eq(_box._state, GiftBox.State.CLOSED)
func test_ready_hides_gift_node() -> void:
var gift: Node2D = _box.get_node("Gift") as Node2D
assert_eq(gift.modulate.a, 0.0)
func test_start_opening_transitions_to_opening() -> void:
_box._start_opening()
assert_eq(_box._state, GiftBox.State.OPENING)
func test_on_lid_opened_transitions_to_resetting() -> void:
_box._start_opening()
_box._on_lid_opened()
assert_eq(_box._state, GiftBox.State.RESETTING)
func test_input_ignored_when_state_is_opening() -> void:
_box._state = GiftBox.State.OPENING
var event: InputEventScreenTouch = InputEventScreenTouch.new()
event.pressed = true
event.position = _box.global_position
_box._input(event)
assert_eq(_box._state, GiftBox.State.OPENING)
func test_input_ignored_when_state_is_resetting() -> void:
_box._state = GiftBox.State.RESETTING
var event: InputEventScreenTouch = InputEventScreenTouch.new()
event.pressed = true
event.position = _box.global_position
_box._input(event)
assert_eq(_box._state, GiftBox.State.RESETTING)
func test_tap_outside_hitbox_does_not_open() -> void:
var event: InputEventScreenTouch = InputEventScreenTouch.new()
event.pressed = true
event.position = _box.global_position + Vector2(200.0, 200.0)
_box._input(event)
assert_eq(_box._state, GiftBox.State.CLOSED)
func test_release_event_does_not_open() -> void:
var event: InputEventScreenTouch = InputEventScreenTouch.new()
event.pressed = false
event.position = _box.global_position
_box._input(event)
assert_eq(_box._state, GiftBox.State.CLOSED)
func test_on_reset_complete_transitions_to_closed() -> void:
_box._state = GiftBox.State.RESETTING
_box._on_reset_complete()
assert_eq(_box._state, GiftBox.State.CLOSED)