99 lines
3.0 KiB
GDScript
99 lines
3.0 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
const RunState = preload("res://domain/run_state.gd")
|
|
|
|
var game: Control
|
|
var touch_count := 0
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
game = MainScene.instantiate()
|
|
root.add_child(game)
|
|
await wait_for_title()
|
|
expect(game.page == game.AppPage.TITLE and game.boot_verified, "cold start reaches verified Title")
|
|
var before: Dictionary = game.run.snapshot()
|
|
await tap("TitleLocaleButton")
|
|
await tap("TitleTextScaleButton")
|
|
await tap("TitleMotionButton")
|
|
await tap("TitleMuteButton")
|
|
expect(game.locale == "en", "Title language touch")
|
|
expect(is_equal_approx(game.text_scale, 1.3), "Title 130 percent text touch")
|
|
expect(game.reduced_motion and game.muted, "Title motion and mute touches")
|
|
expect(game.run.snapshot() == before, "Title settings do not mutate run")
|
|
await tap("StartNewGame")
|
|
var snapshot: Dictionary = game.run.snapshot()
|
|
expect(game.page == game.AppPage.RUN and snapshot.step == RunState.Step.CONTRACT, "Start touch reaches Contract")
|
|
expect(snapshot.coin == 52 and snapshot.company.is_empty(), "Start touch preserves fresh resources")
|
|
expect(snapshot.contract.is_empty() and snapshot.difficulty.is_empty(), "Start touch makes no choice")
|
|
|
|
game.queue_free()
|
|
game = null
|
|
await drain_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_P9_0_TOUCH_OK touch=%d fallback=0 direct=0 locale=en text_130=true reduced_motion=true mute=true handoff=contract mutation=0" % touch_count)
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func wait_for_title() -> void:
|
|
for frame in range(90):
|
|
if game.page == game.AppPage.TITLE:
|
|
return
|
|
await process_frame
|
|
failures.append("cold start did not reach Title")
|
|
|
|
|
|
func tap(node_name: String) -> void:
|
|
var control := find_control(game, node_name)
|
|
if control == null or not control.is_visible_in_tree() or (control is BaseButton and control.disabled):
|
|
failures.append("unavailable touch target %s" % node_name)
|
|
return
|
|
var position := root.get_final_transform() * control.get_global_rect().get_center()
|
|
var down := InputEventScreenTouch.new()
|
|
down.index = 0
|
|
down.position = position
|
|
down.pressed = true
|
|
Input.parse_input_event(down)
|
|
await process_frame
|
|
var up := InputEventScreenTouch.new()
|
|
up.index = 0
|
|
up.position = position
|
|
up.pressed = false
|
|
Input.parse_input_event(up)
|
|
touch_count += 1
|
|
await settle()
|
|
|
|
|
|
func find_control(node: Node, node_name: String) -> Control:
|
|
if node.name == node_name and node is Control and not node.is_queued_for_deletion():
|
|
return node
|
|
for child in node.get_children():
|
|
var found := find_control(child, node_name)
|
|
if found != null:
|
|
return found
|
|
return null
|
|
|
|
|
|
func settle() -> void:
|
|
for frame in range(8):
|
|
await process_frame
|
|
|
|
|
|
func drain_cleanup() -> void:
|
|
for frame in range(50):
|
|
await process_frame
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("P9.0 touch: %s" % message)
|