Handle ui_cancel and the Android back-request notification. Back now dismisses overlays in priority order, closes the win overlay, navigates back, and asks for confirmation before quitting on Home.
416 lines
16 KiB
GDScript
416 lines
16 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless UI QA sweep: screens, settings, profile frames, daily/campaign
|
|
## win flows and the Guest Book detail guard.
|
|
## <godot> --headless --path . --script res://tools/qa_ui.gd --quit-after 1800
|
|
|
|
var failures := 0
|
|
var frames
|
|
|
|
|
|
func _init() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures += 1
|
|
print("FAIL: ", message)
|
|
|
|
|
|
func _run() -> void:
|
|
var err := change_scene_to_file("res://scenes/Main.tscn")
|
|
if err != OK:
|
|
print("FAIL: could not load Main")
|
|
quit(1)
|
|
return
|
|
|
|
await process_frame
|
|
await process_frame
|
|
|
|
var main = current_scene
|
|
var save = root.get_node_or_null("SaveGame")
|
|
_check(save != null, "SaveGame autoload missing")
|
|
if save == null:
|
|
quit(1)
|
|
return
|
|
|
|
# Resolve Frames at runtime: a static reference would compile it before
|
|
# autoloads are registered when this script is launched with --script.
|
|
frames = load("res://scripts/Frames.gd")
|
|
_check(frames != null, "Frames script missing")
|
|
|
|
_test_screen_cycle(main)
|
|
await _test_settings(main, save)
|
|
await _test_profile(main, save)
|
|
await _test_daily(main, save)
|
|
await _test_campaign(main, save)
|
|
await _test_guest_book(main)
|
|
await _test_back(main)
|
|
_restore_defaults(save)
|
|
|
|
print("QA UI: ", "PASS" if failures == 0 else "FAIL (%d)" % failures)
|
|
quit(0 if failures == 0 else 1)
|
|
|
|
|
|
func _test_screen_cycle(main) -> void:
|
|
var expected: Array[String] = ["home", "game", "guest_book", "rules", "profile", "streak"]
|
|
_check(main.screens.size() == expected.size(), "Main should expose all six screens")
|
|
for name in expected:
|
|
_check(main.screens.has(name) and main.screens[name] != null, "screen missing: %s" % name)
|
|
_check(
|
|
main.home != null and main.game != null and main.guest_book != null
|
|
and main.rulebook != null and main.profile != null and main.streak != null,
|
|
"named screen references should all exist"
|
|
)
|
|
_check(main.settings_sheet != null, "settings sheet missing")
|
|
|
|
var keys: Array = main.screens.keys()
|
|
for name in expected:
|
|
main.show_screen(name, false)
|
|
for key in keys:
|
|
_check(
|
|
bool(main.screens[key].visible) == (key == name),
|
|
"only %s should be visible after show_screen(%s)" % [key, name]
|
|
)
|
|
main.show_screen("home", false)
|
|
|
|
|
|
func _test_settings(main, save) -> void:
|
|
main.show_screen("home", false)
|
|
main.open_settings("home")
|
|
await process_frame
|
|
_check(main.settings_sheet.visible, "settings sheet should open from home")
|
|
_check(main.settings_sheet.resume_button.text == "Close", "home settings should use Close")
|
|
_check(not main.settings_sheet.game_actions.visible, "home settings should hide game actions")
|
|
|
|
var toggles: Dictionary = main.settings_sheet.toggles
|
|
_check(toggles.has("patterns") and toggles.has("double_tap_place"), "settings toggles missing")
|
|
_check(toggles["patterns"].mouse_filter == Control.MOUSE_FILTER_PASS, "settings rows should pass swipes")
|
|
|
|
# Changes made through SaveGame must be reflected after an explicit refresh.
|
|
save.set_setting("patterns", false)
|
|
save.set_setting("double_tap_place", false)
|
|
main.settings_sheet.refresh()
|
|
_check(not toggles["patterns"].button_pressed, "sheet should refresh patterns from SaveGame")
|
|
_check(not toggles["double_tap_place"].button_pressed, "sheet should refresh double-tap from SaveGame")
|
|
_check(main.settings_sheet.hold_slider.editable, "hold slider should be editable with double-tap off")
|
|
|
|
# The sheet's own toggles must write back to SaveGame.
|
|
toggles["patterns"].button_pressed = true
|
|
_check(bool(save.get_setting("patterns")), "patterns toggle should update SaveGame")
|
|
toggles["double_tap_place"].button_pressed = true
|
|
_check(bool(save.get_setting("double_tap_place")), "double-tap toggle should update SaveGame")
|
|
_check(not main.settings_sheet.hold_slider.editable, "hold slider should be disabled with double-tap on")
|
|
|
|
# Themed confirmation replaces the native popup on reset.
|
|
var sheet = main.settings_sheet
|
|
sheet._on_reset()
|
|
await process_frame
|
|
_check(sheet.confirm_layer.visible, "reset confirmation should be visible")
|
|
_check(sheet.confirm_title.text == "Reset progress?", "reset confirmation title")
|
|
_check(sheet.confirm_button.text == "Reset", "reset confirmation action text")
|
|
var panel: Control = sheet.confirm_layer.get_child(0).get_child(0)
|
|
var viewport_width: int = int(ProjectSettings.get_setting("display/window/size/viewport_width"))
|
|
_check(panel.custom_minimum_size.x <= viewport_width - 16, "confirmation panel should fit the screen")
|
|
var outside := InputEventMouseButton.new()
|
|
outside.button_index = MOUSE_BUTTON_LEFT
|
|
outside.pressed = true
|
|
sheet._on_confirm_scrim_input(outside)
|
|
_check(not sheet.confirm_layer.visible, "tapping outside should dismiss confirmation")
|
|
|
|
save.data["completed_rooms"].append("room-confirm")
|
|
sheet._on_reset()
|
|
await process_frame
|
|
sheet.confirm_button.pressed.emit()
|
|
await process_frame
|
|
_check((save.data.get("completed_rooms") as Array).is_empty(), "confirming reset should clear progress")
|
|
main.close_settings()
|
|
await process_frame
|
|
_check(not main.settings_sheet.visible, "settings sheet should close from home")
|
|
|
|
main.show_screen("game", false)
|
|
main.open_settings("game")
|
|
await process_frame
|
|
_check(main.settings_sheet.visible, "settings sheet should open from game")
|
|
_check(main.settings_sheet.resume_button.text == "Resume", "game settings should use Resume")
|
|
_check(main.settings_sheet.game_actions.visible, "game settings should show Restart/Lobby")
|
|
_check(main.game.ui_paused, "game should pause while settings are open")
|
|
main.settings_sheet._on_restart()
|
|
await process_frame
|
|
_check(main.settings_sheet.confirm_layer.visible, "restart confirmation should be visible")
|
|
_check(main.settings_sheet.confirm_title.text == "Restart room?", "restart confirmation title")
|
|
_check(main.settings_sheet.confirm_button.text == "Restart", "restart confirmation action text")
|
|
main.settings_sheet._hide_confirm()
|
|
main.close_settings()
|
|
await process_frame
|
|
_check(not main.settings_sheet.visible, "settings sheet should close from game")
|
|
_check(not main.game.ui_paused, "game should resume after closing settings")
|
|
main.show_screen("home", false)
|
|
|
|
|
|
func _test_back(main) -> void:
|
|
var back_event := InputEventAction.new()
|
|
back_event.action = "ui_cancel"
|
|
back_event.pressed = true
|
|
|
|
main.show_screen("home", false)
|
|
await process_frame
|
|
main._input(back_event)
|
|
await process_frame
|
|
_check(main.quit_layer.visible, "Android back on Home should open quit confirmation")
|
|
main._input(back_event)
|
|
await process_frame
|
|
_check(not main.quit_layer.visible, "second back should dismiss quit confirmation")
|
|
|
|
main.open_settings("home")
|
|
await process_frame
|
|
main._input(back_event)
|
|
await process_frame
|
|
_check(not main.settings_sheet.visible, "back should close the settings sheet")
|
|
|
|
main.open_settings("home")
|
|
await process_frame
|
|
main.settings_sheet._on_reset()
|
|
await process_frame
|
|
main._input(back_event)
|
|
await process_frame
|
|
_check(
|
|
not main.settings_sheet.confirm_layer.visible and main.settings_sheet.visible,
|
|
"back should dismiss a confirmation before closing settings"
|
|
)
|
|
main.close_settings()
|
|
|
|
main.show_screen("guest_book", false)
|
|
await process_frame
|
|
main.guest_book._show_detail(Guests.by_id("miso"))
|
|
await process_frame
|
|
main._input(back_event)
|
|
await process_frame
|
|
_check(not main.guest_book.detail_layer.visible, "back should close the guest detail")
|
|
|
|
main.show_screen("game", false)
|
|
main.game.start_level(0)
|
|
await process_frame
|
|
main.game.overlay.visible = true
|
|
main.game.win_shown = true
|
|
main._input(back_event)
|
|
await process_frame
|
|
_check(not main.game.overlay.visible, "back should close the win overlay first")
|
|
_check(not main.game.win_shown, "win state should clear when the overlay closes")
|
|
main.show_screen("home", false)
|
|
|
|
|
|
func _test_profile(main, save) -> void:
|
|
# Five campaign rooms and a three-day streak unlock Paper and Regular.
|
|
save.reset_progress()
|
|
var stats: Dictionary = save.daily_data().duplicate(true)
|
|
stats["best_streak"] = 3
|
|
save.data["daily"] = stats
|
|
save.select_frame("plain")
|
|
for i in range(5):
|
|
save.data["completed_rooms"].append("qa-frame-%02d" % i)
|
|
save.save_game()
|
|
save.progress_changed.emit()
|
|
|
|
main.show_screen("profile", false)
|
|
await process_frame
|
|
await process_frame
|
|
|
|
var profile = main.profile
|
|
_check(profile != null, "Profile screen missing")
|
|
if profile == null:
|
|
return
|
|
|
|
profile._set_tab("frame")
|
|
await process_frame
|
|
var expected: int = frames.all().size()
|
|
_check(profile.frame_grid.get_child_count() == expected, "Profile should show every frame")
|
|
for i in range(profile.frame_grid.get_child_count()):
|
|
_check(
|
|
profile.frame_grid.get_child(i).mouse_filter == Control.MOUSE_FILTER_PASS,
|
|
"frame card %d should pass swipes" % i
|
|
)
|
|
_check(profile.rooms_label.text == "5 / 30", "profile room count should reflect save data")
|
|
_check(profile.best_label.text == "3", "profile best streak should reflect save data")
|
|
|
|
var regular_index := -1
|
|
var night_index := -1
|
|
for i in range(frames.all().size()):
|
|
var id := str(frames.all()[i].get("id", ""))
|
|
if id == "regular":
|
|
regular_index = i
|
|
if id == "night":
|
|
night_index = i
|
|
_check(regular_index >= 0 and night_index >= 0, "Regular and Night owl frames should exist")
|
|
_check(frames.is_unlocked("regular"), "a three-day best streak should unlock Regular")
|
|
_check(not frames.is_unlocked("night"), "Night owl should still be locked")
|
|
if regular_index < 0 or night_index < 0:
|
|
return
|
|
|
|
# Regression: rebuilding the card grid while `pressed` is on the stack
|
|
# frees the emitting node under Godot. Watch the card from inside the
|
|
# signal, before the deferred frame change has a chance to run.
|
|
var card = profile.frame_grid.get_child(regular_index)
|
|
var probe := {"valid": false, "inside": false, "count": -1}
|
|
var watcher := func() -> void:
|
|
var valid := is_instance_valid(card)
|
|
probe["valid"] = valid
|
|
probe["inside"] = valid and card.is_inside_tree()
|
|
probe["count"] = profile.frame_grid.get_child_count()
|
|
|
|
card.pressed.connect(watcher)
|
|
var count_before: int = profile.frame_grid.get_child_count()
|
|
card.pressed.emit()
|
|
_check(bool(probe["valid"]) and bool(probe["inside"]), "frame card must stay alive while pressed emits")
|
|
_check(int(probe["count"]) == count_before, "frame grid must stay stable while pressed emits")
|
|
await process_frame
|
|
await process_frame
|
|
_check(profile.pending_frame == "regular", "frame card should update the preview")
|
|
profile._on_confirm()
|
|
await process_frame
|
|
_check(save.selected_frame() == "regular", "Confirm should apply the frame")
|
|
_check(profile.status_label.text.find("Profile updated") >= 0, "confirmation should be reported")
|
|
_check(profile.frame_grid.get_child_count() == count_before, "frame grid should stay stable after selection")
|
|
|
|
profile.pending_frame = "plain"
|
|
profile._build_portrait()
|
|
profile._build_grid()
|
|
profile._on_cancel()
|
|
await process_frame
|
|
_check(save.selected_frame() == "regular", "Cancel should not write to the save")
|
|
|
|
var locked_card = profile.frame_grid.get_child(night_index)
|
|
locked_card.pressed.emit()
|
|
await process_frame
|
|
_check(
|
|
profile.status_label.text.find(frames.requirement_text("night")) >= 0,
|
|
"locked frame should show its requirement"
|
|
)
|
|
_check(profile.pending_frame == "regular", "locked frame must not change the preview")
|
|
|
|
profile._set_tab("avatar")
|
|
await process_frame
|
|
_check(profile.frame_grid.get_child_count() > 10, "avatar tab should list portraits")
|
|
for i in range(profile.frame_grid.get_child_count()):
|
|
_check(
|
|
profile.frame_grid.get_child(i).mouse_filter == Control.MOUSE_FILTER_PASS,
|
|
"avatar card %d should pass swipes" % i
|
|
)
|
|
|
|
profile.streak_pressed.emit()
|
|
await process_frame
|
|
_check(main.current == "streak", "Profile should open the streak screen")
|
|
_check(main.streak.week_row.get_child_count() == 7, "streak screen should show a seven-day week")
|
|
_check(main.streak.current_label.text == str(save.daily_streak()), "streak number should match the save")
|
|
main.show_screen("profile", false)
|
|
|
|
|
|
func _test_daily(main, save) -> void:
|
|
main.show_screen("home", false)
|
|
var today := Daily.today_key()
|
|
var yesterday := Daily.key_from_day_number(Daily.day_number(today) - 1)
|
|
var daily: Dictionary = save._default_daily()
|
|
daily["last_completed"] = yesterday
|
|
daily["streak"] = 2
|
|
daily["best_streak"] = 3
|
|
save.data["daily"] = daily
|
|
save.save_game()
|
|
var streak_before: int = save.daily_streak()
|
|
var rooms_before: Array = (save.data["completed_rooms"] as Array).duplicate()
|
|
|
|
main._on_daily()
|
|
await process_frame
|
|
await process_frame
|
|
_check(main.game.daily_mode, "daily button should start daily mode")
|
|
_check(main.game.level_label.text == "Daily room", "daily mode should label the room")
|
|
_check(main.game.daily_key == today, "daily mode should carry today's key")
|
|
|
|
await _solve_board(main.game, "daily room")
|
|
_check(main.game.overlay.visible, "daily win overlay should appear after the timer")
|
|
_check(main.game.win_title.text == "Daily room complete!", "daily win title should be correct")
|
|
_check(main.game.win_next.text == "Back to lobby", "daily win button should say Back to lobby")
|
|
_check(save.daily_streak() == streak_before + 1, "daily streak should increment exactly once")
|
|
_check(save.daily_completed_today(), "today should be marked complete")
|
|
_check((save.data["completed_rooms"] as Array) == rooms_before, "daily must not touch completed rooms")
|
|
|
|
main.game.win_next.pressed.emit()
|
|
await process_frame
|
|
await process_frame
|
|
_check(main.current == "home", "Back to lobby should return to home")
|
|
_check(main.home.visible, "home should be visible after the daily win")
|
|
|
|
|
|
func _test_campaign(main, save) -> void:
|
|
main.show_screen("game", false)
|
|
main.game.start_level(0)
|
|
await process_frame
|
|
var room_id := str(main.game.current_level_id)
|
|
var guest: Dictionary = Guests.for_room(1)
|
|
var guest_id := str(guest.get("id", ""))
|
|
|
|
await _solve_board(main.game, "campaign room 1")
|
|
_check(main.game.overlay.visible, "campaign win overlay should appear")
|
|
_check(main.game.win_title.text == "Everyone checked in!", "campaign win title should be correct")
|
|
_check(main.game.win_next.text == "Next room", "campaign win button should say Next room")
|
|
_check((save.data["completed_rooms"] as Array).has(room_id), "campaign room should be recorded")
|
|
_check(guest_id != "" and save.is_guest_unlocked(guest_id), "room 1 should unlock a guest")
|
|
|
|
main.game.win_next.pressed.emit()
|
|
await process_frame
|
|
_check(not main.game.daily_mode, "next room should not be daily mode")
|
|
_check(main.game.level_index == 1, "next room should be room 2")
|
|
_check(main.game.level_label.text == "Room 2", "room 2 should be labelled correctly")
|
|
_check(not main.game.overlay.visible, "overlay should hide when room 2 starts")
|
|
|
|
|
|
func _test_guest_book(main) -> void:
|
|
main.show_screen("guest_book", false)
|
|
await process_frame
|
|
var book = main.guest_book
|
|
_check(book != null, "Guest Book missing")
|
|
if book == null:
|
|
return
|
|
var guest: Dictionary = Guests.all()[0]
|
|
book._show_detail(guest)
|
|
_check(book.detail_layer.visible, "guest detail should open")
|
|
_check(book.detail_name.text == str(guest.get("name", "")), "guest detail should name the guest")
|
|
book._try_close_detail()
|
|
_check(book.detail_layer.visible, "close should be guarded right after opening")
|
|
book._detail_opened_at -= 300
|
|
book._try_close_detail()
|
|
_check(not book.detail_layer.visible, "close should work after the guard")
|
|
main.show_screen("home", false)
|
|
|
|
|
|
func _solve_board(game, label: String) -> void:
|
|
var board = game.board
|
|
var solved := false
|
|
for i in range(12):
|
|
if Rules.is_valid(board.cells, board.regions) or game.win_shown:
|
|
solved = true
|
|
break
|
|
board.hint()
|
|
await process_frame
|
|
if not solved:
|
|
solved = Rules.is_valid(board.cells, board.regions) or game.win_shown
|
|
_check(solved, "%s should solve within 12 hints" % label)
|
|
await create_timer(0.6).timeout
|
|
await process_frame
|
|
|
|
|
|
func _restore_defaults(save) -> void:
|
|
save.reset_progress()
|
|
save.data["daily"] = save._default_daily()
|
|
save.data["last_room"] = 0
|
|
save.select_frame("plain")
|
|
save.set_setting("patterns", true)
|
|
save.set_setting("show_timer", true)
|
|
save.set_setting("reduce_motion", false)
|
|
save.set_setting("hold_seconds", 0.35)
|
|
save.set_setting("double_tap_place", true)
|
|
save.save_game()
|
|
_check(save.rooms_completed() == 0, "save progress should be restored")
|
|
_check(save.daily_data() == save._default_daily(), "save daily should be restored")
|
|
_check(save.selected_frame() == "plain", "save frame should be restored")
|