## Sprint 21 — Save/load game flow (#257) ## Tests: LoadingScreen overlay, pending_load_path field, deferred dispatch guards. class_name TestSaveLoadFlowSprint21 extends GdUnitTestSuite const LOADING_SCREEN_SCENE_PATH: String = "res://ui/loading_screen.tscn" func _make_loading_screen() -> Control: if not ResourceLoader.exists(LOADING_SCREEN_SCENE_PATH): push_warning("TestSaveLoadFlowSprint21: loading_screen.tscn not found — skip") return null var node: Control = load(LOADING_SCREEN_SCENE_PATH).instantiate() add_child(node) return node func before_test() -> void: GameState.pending_load_path = "" func after_test() -> void: GameState.pending_load_path = "" # --------------------------------------------------------------------------- # LoadingScreen scene # --------------------------------------------------------------------------- func test_loading_screen_scene_exists() -> void: assert_bool(ResourceLoader.exists(LOADING_SCREEN_SCENE_PATH)).override_failure_message( "LoadingScreen scene must exist at res://ui/loading_screen.tscn (#257)" ).is_true() func test_loading_screen_hidden_on_ready() -> void: var ls := _make_loading_screen() if ls == null: return assert_bool(ls.visible).override_failure_message( "LoadingScreen must be hidden on _ready (#257)" ).is_false() ls.queue_free() func test_show_loading_makes_visible() -> void: var ls := _make_loading_screen() if ls == null: return ls.show_loading() assert_bool(ls.visible).override_failure_message( "show_loading() must make LoadingScreen visible" ).is_true() ls.queue_free() func test_hide_loading_makes_invisible() -> void: var ls := _make_loading_screen() if ls == null: return ls.show_loading() ls.hide_loading() assert_bool(ls.visible).override_failure_message( "hide_loading() must hide LoadingScreen" ).is_false() ls.queue_free() func test_hide_loading_accepts_success_param() -> void: var ls := _make_loading_screen() if ls == null: return ls.show_loading() ls.hide_loading(true) assert_bool(ls.visible).is_false() ls.show_loading() ls.hide_loading(false) assert_bool(ls.visible).is_false() ls.queue_free() func test_hide_loading_default_param_is_true() -> void: var ls := _make_loading_screen() if ls == null: return ls.show_loading() ls.hide_loading() # no argument — default success=true assert_bool(ls.visible).is_false() ls.queue_free() # --------------------------------------------------------------------------- # GameState.pending_load_path field # --------------------------------------------------------------------------- func test_pending_load_path_default_is_empty() -> void: GameState.pending_load_path = "" assert_str(GameState.pending_load_path).override_failure_message( "GameState.pending_load_path default must be empty string" ).is_empty() func test_pending_load_path_can_be_set_and_read() -> void: var path := "user://saves/20260225-143022-a7b3f1/quicksave.sav" GameState.pending_load_path = path assert_str(GameState.pending_load_path).override_failure_message( "GameState.pending_load_path must persist the value set" ).is_equal(path) func test_pending_load_path_can_be_cleared() -> void: GameState.pending_load_path = "user://saves/test/quicksave.sav" GameState.pending_load_path = "" assert_str(GameState.pending_load_path).is_empty()