Files
step3/tests/simulation_history_test.gd
T
2026-07-16 22:42:03 -05:00

30 lines
2.1 KiB
GDScript

extends SceneTree
var failures := 0
func _initialize() -> void:
var history = load("res://scripts/ui/simulation_history.gd")
_assert(history._action_for_state("completed") == "results", "completed simulations should open results")
_assert(history._action_for_state("block_active") == "resume", "active blocks should resume")
_assert(history._action_for_state("between_blocks") == "resume", "between-block simulations should resume")
_assert(history._action_for_state("abandoned") == "none", "abandoned simulations should be read-only")
_assert(history.has_active_simulation({"hasActiveSimulation": true}, {}), "readiness should identify an active simulation")
_assert(history.has_active_simulation({}, {"state": "block_active"}), "a loaded active block should be resumable")
_assert(history.has_active_simulation({}, {"state": "between_blocks"}), "a loaded between-block simulation should be resumable")
_assert(not history.has_active_simulation({}, {"state": "completed"}), "completed simulations should not appear active")
_assert(history.completed_blocks({"state": "block_active", "currentBlock": 3, "totalBlocks": 12}) == 3, "active block progress should count only finished blocks")
_assert(history.completed_blocks({"state": "between_blocks", "currentBlock": 3, "totalBlocks": 12}) == 4, "between-block progress should include the submitted block")
_assert(history.completed_blocks({"state": "completed", "currentBlock": 11, "totalBlocks": 12}) == 12, "completed simulations should show every block")
_assert(history.progress_percent(3, 12) == 25, "progress percentage should use floating-point division")
_assert(history.remaining_time_text({"state": "between_blocks", "currentBlock": 2, "totalBlocks": 12}) == "~4h 30m remaining", "remaining time should reflect unstarted blocks")
_assert(history.format_datetime_parts({"year": 2026, "month": 7, "day": 16, "hour": 22, "minute": 4}) == "Jul 16, 2026\n10:04 PM", "history dates should use the compact mockup format")
quit(1 if failures > 0 else 0)
func _assert(condition: bool, message: String) -> void:
if condition:
return
failures += 1
push_error(message)