test(gift-box): add unit tests for CLOSED/OPENING/OPEN state machine
This commit is contained in:
63
test/unit/test_gift_box.gd
Normal file
63
test/unit/test_gift_box.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
## Tests for GiftBox — CLOSED/OPENING/OPEN 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_open() -> void:
|
||||
_box._start_opening()
|
||||
_box._on_lid_opened()
|
||||
assert_eq(_box._state, GiftBox.State.OPEN)
|
||||
|
||||
|
||||
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_open() -> void:
|
||||
_box._state = GiftBox.State.OPEN
|
||||
var event: InputEventScreenTouch = InputEventScreenTouch.new()
|
||||
event.pressed = true
|
||||
event.position = _box.global_position
|
||||
_box._input(event)
|
||||
assert_eq(_box._state, GiftBox.State.OPEN)
|
||||
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user