✅ test(@projects/@magic-civilization): 🧪 add game_over event integration tests
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
7021348dd4
commit
8a3eb9b880
1 changed files with 66 additions and 0 deletions
66
src/game/engine/tests/integration/test_game_over_event.gd
Normal file
66
src/game/engine/tests/integration/test_game_over_event.gd
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
extends GutTest
|
||||
## p2-48 bullet 6 — GUT for `EventBus.game_over` signal.
|
||||
##
|
||||
## Headless-compatible: drives the signal directly with synthetic
|
||||
## (winner_index, reason) tuples for each `GameOverReason` discriminant
|
||||
## (LastSurvivor, ConditionMet, TurnLimit, Resigned). Asserts the listener
|
||||
## chain reaches `end_game_summary.gd::_on_game_over` with the expected
|
||||
## payload shape. The Rust half — `mc-turn::end_conditions::evaluate_conditions`
|
||||
## firing each variant — is covered by `cargo test -p mc-turn --test
|
||||
## game_over_event` (3/3 pass).
|
||||
|
||||
var _emissions: Array[Dictionary] = []
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
_emissions = []
|
||||
if EventBus.game_over.is_connected(_on_game_over):
|
||||
EventBus.game_over.disconnect(_on_game_over)
|
||||
EventBus.game_over.connect(_on_game_over)
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
if EventBus.game_over.is_connected(_on_game_over):
|
||||
EventBus.game_over.disconnect(_on_game_over)
|
||||
|
||||
|
||||
func _on_game_over(winner_index: int, reason: String) -> void:
|
||||
_emissions.append({"winner": winner_index, "reason": reason})
|
||||
|
||||
|
||||
func test_last_survivor_emission() -> void:
|
||||
EventBus.game_over.emit(0, "LastSurvivor")
|
||||
assert_eq(_emissions.size(), 1, "expected one emission")
|
||||
assert_eq(_emissions[0]["winner"], 0, "winner_index payload preserved")
|
||||
assert_eq(_emissions[0]["reason"], "LastSurvivor", "reason payload preserved")
|
||||
|
||||
|
||||
func test_turn_limit_emission_with_winner() -> void:
|
||||
EventBus.game_over.emit(2, "TurnLimit")
|
||||
assert_eq(_emissions.size(), 1)
|
||||
assert_eq(_emissions[0]["winner"], 2)
|
||||
assert_eq(_emissions[0]["reason"], "TurnLimit")
|
||||
|
||||
|
||||
func test_condition_met_emission() -> void:
|
||||
EventBus.game_over.emit(1, "ConditionMet")
|
||||
assert_eq(_emissions.size(), 1)
|
||||
assert_eq(_emissions[0]["winner"], 1)
|
||||
assert_eq(_emissions[0]["reason"], "ConditionMet")
|
||||
|
||||
|
||||
func test_resigned_emission_no_winner() -> void:
|
||||
EventBus.game_over.emit(-1, "Resigned")
|
||||
assert_eq(_emissions.size(), 1)
|
||||
assert_eq(_emissions[0]["winner"], -1, "stalemate winner_index = -1")
|
||||
assert_eq(_emissions[0]["reason"], "Resigned")
|
||||
|
||||
|
||||
func test_multiple_emissions_collected_in_order() -> void:
|
||||
EventBus.game_over.emit(0, "LastSurvivor")
|
||||
EventBus.game_over.emit(2, "TurnLimit")
|
||||
EventBus.game_over.emit(-1, "Resigned")
|
||||
assert_eq(_emissions.size(), 3)
|
||||
assert_eq(_emissions[0]["reason"], "LastSurvivor")
|
||||
assert_eq(_emissions[1]["reason"], "TurnLimit")
|
||||
assert_eq(_emissions[2]["reason"], "Resigned")
|
||||
Loading…
Add table
Reference in a new issue