Files
aetherbound-guild/runtime/tests/dev2/initial_company_full_flow_touch_test.gd
T

108 lines
4.1 KiB
GDScript

extends SceneTree
const MainScene = preload("res://main.tscn")
const SETTINGS_PATH := "user://aetherbound_guild_settings.json"
const DRAFT_PATH := "user://aetherbound_initial_company_draft.json"
const COMPANY_PATH := "user://aetherbound_expedition_company.json"
const LEGACY_SAVE_PATH := "user://aetherbound_guild_p10_3.json"
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND
root.content_scale_size = Vector2i(844, 390)
root.size = Vector2i(844, 390)
_cleanup()
var game = MainScene.instantiate()
root.add_child(game)
await _frames(60)
var shell = game.entry_shell
expect(shell.find_child("SetupApply", true, false) != null, "fresh launch reaches first-launch setup after Boot")
await _touch(shell.find_child("SetupApply", true, false))
expect(shell.current_screen == "title", "first-launch setup reaches Title")
await _touch(shell.find_child("TitleNewGame", true, false))
var page = shell.initial_company_page
await _touch(page.find_child("CandidateSelect_0", true, false))
await _touch(page.find_child("CandidateSelect_2", true, false))
await _touch(page.find_child("ReviewCompany", true, false))
expect(page.mode == "review", "choose-two reaches Review through parsed touch")
await _touch(page.find_child("ReviewRevise", true, false))
expect(page.mode == "choice" and page.draft.selected_offer_ids.size() == 2, "Revise keeps the saved pair")
var selected_ids: Array = Array(page.draft.selected_offer_ids).duplicate()
game.queue_free()
await _frames(20)
var precommit_restart = MainScene.instantiate()
root.add_child(precommit_restart)
await _frames(60)
var restarted_shell = precommit_restart.entry_shell
expect(restarted_shell.current_screen == "title", "pre-commit restart skips completed setup and reaches Title")
await _touch(restarted_shell.find_child("TitleNewGame", true, false))
page = restarted_shell.initial_company_page
expect(page.draft.selected_offer_ids == selected_ids, "pre-commit restart restores the same selected IDs")
await _touch(page.find_child("ReviewCompany", true, false))
await _touch(page.find_child("CreateCompany", true, false))
expect(restarted_shell.current_screen == "guild_handoff", "Create Company reaches the bounded Guild handoff")
expect(restarted_shell.find_child("GuildRoster", true, false).get_child_count() == 2, "Guild handoff shows the persistent pair")
precommit_restart.queue_free()
await _frames(20)
var committed_restart = MainScene.instantiate()
root.add_child(committed_restart)
await _frames(60)
expect(committed_restart.entry_shell.current_screen == "guild_handoff", "post-commit restart resumes directly at Guild")
expect(committed_restart.entry_shell.find_child("GuildRoster", true, false).get_child_count() == 2, "post-commit Guild retains exactly two members")
committed_restart.queue_free()
await _frames(20)
_cleanup()
if failures.is_empty():
print("ABG_DEV2_FULL_FLOW_TOUCH_OK boot_setup_title_choose_review_revise_precommit_restart_create_guild_postcommit_restart=true parsed_screen_touch=true")
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func _touch(control: Control) -> void:
var center := root.get_final_transform() * control.get_global_rect().get_center()
var press := InputEventScreenTouch.new()
press.position = center
press.pressed = true
press.index = 0
Input.parse_input_event(press)
await _frames(2)
var release := InputEventScreenTouch.new()
release.position = center
release.pressed = false
release.index = 0
Input.parse_input_event(release)
await _frames(5)
func _cleanup() -> void:
for base in [SETTINGS_PATH, DRAFT_PATH, COMPANY_PATH, LEGACY_SAVE_PATH]:
for suffix in ["", ".bak", ".candidate", ".bak.candidate", ".corrupt"]:
var path := "%s%s" % [base, suffix]
if FileAccess.file_exists(path):
DirAccess.remove_absolute(path)
func _frames(count: int) -> void:
for frame in range(count):
await process_frame
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("DEV-2 full entry flow: %s" % message)