Split the main window into TopBar and Quiz scenes

The quiz (song, playlist, players, music player and the popups opened from
it) moves into Quiz.tscn and the top panel into TopBar.tscn. The main window
keeps only the top bar, the quiz and the popups opened from the top bar, so
other views can be added next to the quiz later. Every node keeps its place
on screen.

Screenshots of every UI state before and after are pixel-identical, and a
layout test checks each node against a baseline taken before the split.
This commit is contained in:
Sansan committed 2026-10-06 10:02:22 +02:00
1 parent 75c59eb223
commit 3c7b4e5c9d
27 files changed
+3432 -980

No files matched your search

File diff suppressed because it is too large. Load diff
+16 -4
View File
@@ -11,6 +11,7 @@ var _server: FakeHttpTransport
var _snapshot: AutoloadSnapshot
var _runner: GdUnitSceneRunner
var _window: Control
var _quiz: Quiz
func before_test() -> void:
@@ -39,6 +40,7 @@ func before_test() -> void:
_before_window_starts()
_runner = scene_runner("res://MainWindow.tscn")
_window = _runner.scene()
_quiz = _window.get_node("Quiz")
# The debug build lowers the winning score on startup; keep it out of reach
Settings.winning_score = 20
@@ -61,8 +63,9 @@ func _next_song_is(info: Dictionary) -> void:
_server.respond_json("/music/info", info)
## Presses a button in the quiz.
func _press(button_path: String) -> void:
(_window.get_node(button_path) as Button).pressed.emit()
(_quiz.get_node(button_path) as Button).pressed.emit()
## Presses Next and waits until the first song is playing.
@@ -73,16 +76,16 @@ func _play_first_song() -> void:
## Adds a player through the name field, the same way the user does.
func _add_player(player_name: String) -> PlayerObject:
var name_field: TextEdit = _window.get_node(
var name_field: TextEdit = _quiz.get_node(
"Players/VBoxContainer/AddPlayerContainer/PlayerNameField")
name_field.text = player_name
_runner.invoke("add_player")
_quiz.add_player()
return Settings.player_array.back() if !Settings.player_array.is_empty() else null
## Returns the row in the player list that shows [param player_object].
func _player_row(player_object: PlayerObject) -> Player:
var rows: Node = _window.get_node(
var rows: Node = _quiz.get_node(
"Players/VBoxContainer/ScrollContainer/PlayersListVBoxContainer")
for row: Player in rows.get_children():
if row.player_object == player_object:
@@ -97,6 +100,15 @@ func _remove_player(player_object: PlayerObject) -> void:
await _runner.simulate_frames(1)
## Clicks at [param position], given in the window's 1920x1080 layout coordinates.
func _click_at(position: Vector2) -> void:
# The runner takes window pixels; the headless test window is much smaller than the
# layout, so convert like a real mouse position would be
_runner.set_mouse_position(_window.get_viewport().get_final_transform() * position)
await _runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await _runner.await_input_processed()
## Presses [param keys] together, e.g. [code][KEY_ALT, KEY_1][/code], then releases them.
func _press_keys(keys: Array[Key]) -> void:
for key: Key in keys:
+246
View File
@@ -0,0 +1,246 @@
class_name UiTour
extends RefCounted
## Walks the main window through a fixed set of states against a fake MusicServer:
## startup, players added, a song playing, every popup open and a sync.
##
## Used for screenshots ([code]tools/take_screenshots.gd[/code]) and for the layout
## test, so both look at exactly the same states. Nodes are looked up by name in the
## main window and in its Quiz and TopBar scenes, so the tour works no matter which of
## them a node lives in.
const SOUNDTRACKS: Array[String] = [
"Chrono Trigger", "Final Fantasy VI", "Secret of Mana", "Terranigma",
"Earthbound", "Super Metroid", "The Legend of Zelda: A Link to the Past",
"Donkey Kong Country 2", "Lufia II", "Illusion of Gaia",
]
const SONG_INFO: Dictionary = {
"SongNo": 0, "Soundtrack": "Chrono Trigger", "Song": "Corridors of Time",
}
const SYNC_PROGRESS: Dictionary = {"progress": 40, "time_spent": "00:00:02"}
const SYNC_RESULT: Dictionary = {
"soundtracks_added": ["Terranigma", "Lufia II"],
"soundtracks_re_added": [],
"soundtracks_changed_title": {"FF6": "Final Fantasy VI"},
"soundtracks_changed_content": ["Chrono Trigger"],
"soundtracks_removed": ["Old Soundtrack"],
"catched_errors": [],
"total_time": "00:00:03",
}
## Popups in the order the tour opens them.
const POPUPS: Array[String] = [
"Search", "SyncWindow", "SettingsWindow", "QRWindow", "NewCharacterSelect",
"ShortcutsWindow", "AboutWindow", "WinnerWindow", "Log", "StatisticsPopupPanel",
]
var _main: Control
func _init(main: Control) -> void:
_main = main
## Returns a fake server that answers every request the main window makes on the tour.
## Call [method FakeHttpTransport.install] before the main window is created.
static func make_server() -> FakeHttpTransport:
var server: FakeHttpTransport = FakeHttpTransport.new()
var mp3: PackedByteArray = FileAccess.get_file_as_bytes("res://tests/data/short.mp3")
server.respond_json("/music/all", SOUNDTRACKS)
server.respond_json("/music/all/order", SOUNDTRACKS)
server.respond_json("/music/list", [])
server.respond_json("/characters", [])
server.respond_bytes("/music/rand", mp3)
server.respond_bytes("/music/addQue", PackedByteArray())
server.respond_json("/music/info", SONG_INFO)
server.respond_bytes("/music/reset", PackedByteArray())
server.respond_bytes("/music/played?song=0", PackedByteArray())
server.respond_bytes("/sync", PackedByteArray())
server.respond_json("/sync/progress", SYNC_PROGRESS)
return server
## Puts Settings and Playlist in the state the tour expects. Call it before the main
## window is created.
static func prepare_autoloads() -> void:
Playlist.reset_playlist()
Playlist.first_song_played = false
Playlist.is_song_downloading = false
Settings.player_array.clear()
Settings.edit_players = false
Settings.currently_syncing = false
Settings.character_select_open = false
Settings.add_to_stats = true
Settings.hide_next_track = true
Settings.use_low_played_mode = false
Settings.winning_score = 20
# The inspiration list scrolls by itself, which would make every picture different
Settings.inspiration_list_speed = 0
## Runs the tour. [param on_state] is called (and awaited) with the name of each state
## and the popup that is open in it, or [code]null[/code] when no popup is open.
func run(on_state: Callable) -> void:
# The debug build lowers the winning score on startup; keep it out of reach
Settings.winning_score = 20
await _settle()
await on_state.call("startup", null)
_call("add_players")
await _settle()
await on_state.call("add_player_row", null)
_add_player("Crono")
_add_player("Marle")
_call("add_players")
await _settle()
await on_state.call("players_added", null)
_call("play_next_song")
await _settle()
_freeze_music_player()
_player_row(0).add_point()
_player_row(0).add_point()
_player_row(1).add_point()
_call("show_answer_pressed")
await _settle()
_freeze_music_player()
_fix_log_times()
await _settle()
await on_state.call("playing", null)
for popup_name: String in POPUPS:
var popup: Node = await _open_popup(popup_name)
await _settle()
await on_state.call("popup_" + popup_name, popup)
_close_popup(popup)
await _settle()
var sync_window: PopupWindow = _node("SyncWindow")
Settings.currently_syncing = false
sync_window.has_synced = false
sync_window.start_sync()
sync_window.sync_timer.stop()
sync_window._on_sync_timeout()
await _settle()
await on_state.call("sync_in_progress", sync_window)
sync_window.close()
await _settle()
await on_state.call("sync_buttons_locked", null)
_server().respond_json("/sync/progress", SYNC_RESULT)
sync_window._on_sync_timeout()
sync_window.open()
await _settle()
await on_state.call("sync_result", sync_window)
sync_window.close()
await _settle()
## Returns where every Control and Window in [param subtree] is on screen, keyed by its
## path from [param main]: [code]{"rect": [x, y, width, height], "visible": bool}[/code].
## Nodes added at runtime without a name are keyed by their index, e.g. [code]#2[/code],
## so the keys are the same on every run.
static func dump_layout(main: Node, subtree: Node) -> Dictionary:
var layout: Dictionary = {}
var path: String = String(main.get_path_to(subtree))
_dump_node(subtree, path, layout)
return layout
static func _dump_node(node: Node, path: String, layout: Dictionary) -> void:
if node is Control:
var rect: Rect2 = (node as Control).get_global_rect()
layout[path] = {"rect": _round_rect(rect), "visible": node.is_visible_in_tree()}
elif node is Window:
var window: Window = node
layout[path] = {
"rect": _round_rect(Rect2(window.position, window.size)),
"visible": window.visible,
}
for child: Node in node.get_children():
var key: String = "#%d" % child.get_index() if "@" in child.name \
else String(child.name)
_dump_node(child, key if path == "." else path + "/" + key, layout)
static func _round_rect(rect: Rect2) -> Array[float]:
return [snappedf(rect.position.x, 0.01), snappedf(rect.position.y, 0.01),
snappedf(rect.size.x, 0.01), snappedf(rect.size.y, 0.01)]
## Finds a node of the main window by [param node_name], whether it is a direct child
## of the main window or of its Quiz or TopBar scene.
func _node(node_name: String) -> Node:
for parent: Node in [_main, _main.get_node_or_null("Quiz"),
_main.get_node_or_null("TopBar")]:
if parent != null && parent.has_node(node_name):
return parent.get_node(node_name)
push_error("UiTour: no node named " + node_name)
return null
## Calls [param method] on the main window, or on its Quiz scene if that has it.
func _call(method: String, args: Array = []) -> Variant:
var quiz: Node = _main.get_node_or_null("Quiz")
var target: Node = quiz if quiz != null && quiz.has_method(method) else _main
return target.callv(method, args)
func _server() -> FakeHttpTransport:
return MusicServerClient.transport
func _settle() -> void:
for i: int in 4:
await _main.get_tree().process_frame
func _add_player(player_name: String) -> void:
(_node("Players").get_node("VBoxContainer/AddPlayerContainer/PlayerNameField") \
as TextEdit).text = player_name
_call("add_player")
func _player_row(index: int) -> Player:
return _node("Players").get_node(
"VBoxContainer/ScrollContainer/PlayersListVBoxContainer").get_child(index)
## Stops the song so the time and progress bar look the same on every run.
func _freeze_music_player() -> void:
var music_player: MusicPlayer = _node("MusicPlayer")
music_player.audio_player.stop()
music_player.sound_player.stop()
music_player.progress_slider.value = 0
music_player.music_time_label.text = "00:00 / 00:01"
## The log starts each row with the time of day; use a fixed time instead.
func _fix_log_times() -> void:
var log_window: PopupWindow = _node("Log")
for row: Label in log_window.log_box.get_children():
row.text = "12:00:00 " + row.text.substr(9)
func _open_popup(popup_name: String) -> Node:
var popup: Node = _node(popup_name)
match popup_name:
"SyncWindow":
# Opening the window starts a sync; show the empty window instead
popup.open()
"NewCharacterSelect":
popup.show_grid("Crono")
"WinnerWindow":
popup.show_winner(Settings.player_array[0])
"StatisticsPopupPanel":
_call("get_statistics")
_:
popup.open()
return popup
func _close_popup(popup: Node) -> void:
if popup is PopupWindow:
popup.close()
else:
popup.visible = false
+1
View File
@@ -0,0 +1 @@
uid://v42qdc68bn17
@@ -0,0 +1,98 @@
extends GdUnitTestSuite
## Checks that every node of the main window is where it was before the window was
## split into scenes.
##
## [code]tests/data/layout_baseline.json[/code] was written by
## [code]tools/take_screenshots.gd[/code] before the split. It holds the position, size
## and visibility of every node in each UiTour state, keyed by the node's old path. This
## test runs the same tour and compares, after moving each old path to where the node
## lives now.
const BASELINE_PATH: String = "res://tests/data/layout_baseline.json"
## Nodes that moved from the main window into the Quiz scene, by their old name.
const QUIZ_NODES: Array[String] = [
"Open", "FileDialog", "MusicListPanel", "ScrollContainer", "VBoxContainer",
"MusicPlayer", "Players", "ResetPlaylistButton", "ResetPointsButton", "SettingsButton",
"SoundTestButton", "ShowAnswerButton", "NextButton", "RepeatSongCheckButton",
"DebugLabel", "SettingsWindow", "NewCharacterSelect", "WinnerWindow", "Log",
]
## Nodes that moved from the main window into the TopBar scene, by their old name.
const TOP_BAR_NODES: Array[String] = [
"TopPanelContainer", "Title", "SearchButton", "SyncButton", "StatisticsButton",
"ShortcutsButton", "AboutButton", "QRButton",
]
## How far a node may be from its old place, in pixels.
const TOLERANCE: float = 0.5
var _snapshot: AutoloadSnapshot
var _server: FakeHttpTransport
var _main: Control
var _layout: Dictionary = {}
func before() -> void:
_snapshot = AutoloadSnapshot.take([Settings, Playlist])
UiTour.prepare_autoloads()
_server = UiTour.make_server().install()
# Laid out at the size the baseline was taken at, like the screenshots
var viewport: SubViewport = auto_free(SubViewport.new())
viewport.size = Vector2i(1920, 1080)
viewport.gui_embed_subwindows = true
Engine.get_main_loop().root.add_child(viewport)
_main = load("res://MainWindow.tscn").instantiate()
viewport.add_child(_main)
await UiTour.new(_main).run(func(state: String, popup: Node) -> void:
_layout[state] = UiTour.dump_layout(_main, _main if popup == null else popup))
func after() -> void:
_main.free()
await Engine.get_main_loop().process_frame
_server.uninstall()
_snapshot.restore()
## Where the node that used to be at [param old_path] in the main window is now.
static func new_path(old_path: String) -> String:
var first: String = old_path.get_slice("/", 0)
if first in QUIZ_NODES:
return "Quiz/" + old_path
if first in TOP_BAR_NODES:
return "TopBar/" + old_path
return old_path
func _baseline() -> Dictionary:
return JSON.parse_string(FileAccess.get_file_as_string(BASELINE_PATH))
func test_tour_has_the_same_states_as_the_baseline() -> void:
assert_array(_layout.keys()).contains_exactly_in_any_order(_baseline().keys())
func test_every_node_is_where_it_was() -> void:
var problems: Array[String] = []
var baseline: Dictionary = _baseline()
for state: String in baseline:
var actual: Dictionary = _layout.get(state, {})
for old_path: String in baseline[state]:
var path: String = new_path(old_path)
var expected: Dictionary = baseline[state][old_path]
if !actual.has(path):
problems.append("%s: %s is missing (was %s)" % [state, path, old_path])
continue
var rect: Array = actual[path].rect
for i: int in 4:
if absf(rect[i] - expected.rect[i]) > TOLERANCE:
problems.append("%s: %s is at %s, was %s"
% [state, path, rect, expected.rect])
break
if actual[path].visible != expected.visible:
problems.append("%s: %s visible is %s, was %s"
% [state, path, actual[path].visible, expected.visible])
assert_array(problems).override_failure_message(
"%d nodes moved:\n%s" % [problems.size(), "\n".join(problems.slice(0, 30))]) \
.is_empty()
@@ -0,0 +1 @@
uid://b2077235y1g0f
+16 -16
View File
@@ -7,7 +7,7 @@ func test_startup_loads_soundtracks_and_preloads_a_song() -> void:
assert_int(_server.count("/music/all")).is_equal(1)
assert_array(_server.requested_paths).contains(["/music/rand", "/music/addQue", "/music/info"])
assert_int(Playlist.song_object_array.size()).is_equal(1)
assert_bool((_window.get_node("NextButton") as Button).disabled).is_false()
assert_bool((_quiz.get_node("NextButton") as Button).disabled).is_false()
func test_low_played_mode_fetches_from_low_played_endpoint() -> void:
@@ -15,7 +15,7 @@ func test_low_played_mode_fetches_from_low_played_endpoint() -> void:
_server.respond_bytes(
"/music/rand/low", FileAccess.get_file_as_bytes("res://tests/data/short.mp3"))
_runner.invoke("fetch_song")
_quiz.fetch_song()
assert_int(_server.count("/music/rand/low")).is_equal(1)
@@ -33,7 +33,7 @@ func test_next_plays_preloaded_song_and_fetches_another() -> void:
func test_title_is_hidden_until_answer_is_shown() -> void:
var soundtrack_label: Label = _window.get_node("VBoxContainer/SoundtrackLabel")
var soundtrack_label: Label = _quiz.get_node("VBoxContainer/SoundtrackLabel")
_press("NextButton")
await _runner.simulate_frames(2)
@@ -81,13 +81,13 @@ func test_cannot_add_player_without_name() -> void:
func test_failed_song_download_is_retried_until_the_server_answers() -> void:
_window.song_fetch_retry_seconds = 0.05
_quiz.song_fetch_retry_seconds = 0.05
var songs_before: int = Playlist.song_object_array.size()
var mp3: PackedByteArray = FileAccess.get_file_as_bytes("res://tests/data/short.mp3")
_server.respond_bytes("/music/rand", PackedByteArray(), 503)
var rand_requests_before: int = _server.count("/music/rand")
_runner.invoke("fetch_song")
_quiz.fetch_song()
await await_millis(200)
assert_int(_server.count("/music/rand") - rand_requests_before).is_greater(1)
@@ -102,13 +102,13 @@ func test_failed_song_download_is_retried_until_the_server_answers() -> void:
func test_failed_song_info_retries_only_that_step() -> void:
_window.song_fetch_retry_seconds = 0.05
_quiz.song_fetch_retry_seconds = 0.05
var songs_before: int = Playlist.song_object_array.size()
_server.respond_bytes("/music/info", PackedByteArray(), 503)
var rand_before: int = _server.count("/music/rand")
var queue_before: int = _server.count("/music/addQue")
_runner.invoke("fetch_song")
_quiz.fetch_song()
await await_millis(200)
_next_song_is(SONG_INFO[1])
await await_millis(200)
@@ -124,7 +124,7 @@ func test_failed_song_info_retries_only_that_step() -> void:
func test_preloads_as_many_songs_as_the_cache_setting() -> void:
Playlist.number_of_tracks_to_preload = 3
_runner.invoke("fetch_song")
_quiz.fetch_song()
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_bool(Playlist.is_song_downloading).is_false()
@@ -132,7 +132,7 @@ func test_preloads_as_many_songs_as_the_cache_setting() -> void:
func test_playing_a_song_tops_the_cache_up_again() -> void:
Playlist.number_of_tracks_to_preload = 3
_runner.invoke("fetch_song")
_quiz.fetch_song()
await _play_first_song()
@@ -141,13 +141,13 @@ func test_playing_a_song_tops_the_cache_up_again() -> void:
func test_cache_keeps_filling_after_a_failed_download() -> void:
_window.song_fetch_retry_seconds = 0.05
_quiz.song_fetch_retry_seconds = 0.05
Playlist.number_of_tracks_to_preload = 3
var mp3: PackedByteArray = FileAccess.get_file_as_bytes("res://tests/data/short.mp3")
# One more download works, then the server stops answering
_server.fail_after("/music/rand", 1)
_runner.invoke("fetch_song")
_quiz.fetch_song()
await await_millis(150)
assert_int(Playlist.get_preloaded_songs()).is_equal(2)
@@ -165,11 +165,11 @@ func _open_settings() -> void:
func _close_settings() -> void:
(_window.get_node("SettingsWindow") as Control).visible = false
(_quiz.get_node("SettingsWindow") as Control).visible = false
func _press_settings_button(unique_name: String) -> void:
(_window.get_node("SettingsWindow").get_node("%" + unique_name) as Button).pressed.emit()
(_quiz.get_node("SettingsWindow").get_node("%" + unique_name) as Button).pressed.emit()
func test_raising_cache_size_does_not_download_while_settings_are_open() -> void:
@@ -224,12 +224,12 @@ func test_show_answer_before_first_song_does_not_reveal_next_song() -> void:
await _play_first_song()
assert_str((_window.get_node("VBoxContainer/SoundtrackLabel") as Label).text) \
assert_str((_quiz.get_node("VBoxContainer/SoundtrackLabel") as Label).text) \
.is_equal("????????")
func test_log_adds_one_row_per_point_with_padded_time() -> void:
var log_box: VBoxContainer = _window.get_node("%Log").get_node("%LogVBoxContainer")
var log_box: VBoxContainer = _quiz.get_node("%Log").get_node("%LogVBoxContainer")
var crono: PlayerObject = _add_player("Crono")
await _play_first_song()
@@ -243,7 +243,7 @@ func test_log_adds_one_row_per_point_with_padded_time() -> void:
func test_inspiration_list_alternates_row_backgrounds() -> void:
var rows: Array[Node] = _window.get_node("ScrollContainer/VBoxContainer").get_children()
var rows: Array[Node] = _quiz.get_node("ScrollContainer/VBoxContainer").get_children()
assert_int(rows.size()).is_equal(2)
assert_str((rows[0] as ListRow).text).is_equal("Chrono Trigger")
@@ -28,7 +28,7 @@ func test_next_plays_the_preloaded_song_after_a_slow_song_list() -> void:
func test_failed_song_list_is_retried_before_preloading() -> void:
_window.song_fetch_retry_seconds = 0.05
_quiz.song_fetch_retry_seconds = 0.05
_server.respond_json("/music/list", [], 503)
_server.release("/music/list")
+1 -1
View File
@@ -143,7 +143,7 @@ func test_player_list_shows_rows_in_player_order() -> void:
await _remove_player(_crono)
var robo: PlayerObject = _add_player("Robo")
var rows: Array[Node] = _window.get_node(
var rows: Array[Node] = _quiz.get_node(
"Players/VBoxContainer/ScrollContainer/PlayersListVBoxContainer").get_children()
assert_array(rows.map(func(row: Player) -> PlayerObject: return row.player_object)) \
+32 -27
View File
@@ -1,28 +1,27 @@
extends MainWindowTestSuite
## All popups share PopupWindow: clicking outside the panel closes them, the backdrop
## dims the window behind them, and the closing click does not reach the main window.
## The main window and the quiz each have their own popups and their own backdrop.
const POPUP_NODES: Array[String] = [
"Search", "SyncWindow", "SettingsWindow", "QRWindow", "NewCharacterSelect",
"ShortcutsWindow", "AboutWindow", "WinnerWindow", "Log",
## Popups opened from the top bar, in the main window.
const MAIN_POPUPS: Array[String] = [
"Search", "SyncWindow", "QRWindow", "ShortcutsWindow", "AboutWindow",
]
## Popups opened from the quiz, in the Quiz scene.
const QUIZ_POPUPS: Array[String] = [
"SettingsWindow", "NewCharacterSelect", "WinnerWindow", "Log",
]
func _popup(node_name: String) -> PopupWindow:
return _window.get_node(node_name)
return _quiz.get_node(node_name) if node_name in QUIZ_POPUPS \
else _window.get_node(node_name)
func _backdrop() -> ColorRect:
return _window.get_node("PopupBackdrop")
## Clicks at [param position], given in the window's 1920x1080 layout coordinates.
func _click_at(position: Vector2) -> void:
# The runner takes window pixels; the headless test window is much smaller than the
# layout, so convert like a real mouse position would be
_runner.set_mouse_position(_window.get_viewport().get_final_transform() * position)
await _runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await _runner.await_input_processed()
## The backdrop that shows behind [param popup].
func _backdrop(popup: PopupWindow = _popup("SettingsWindow")) -> ColorRect:
return popup.get_parent().get_node("PopupBackdrop")
## A point on screen outside the popup's panel.
@@ -32,34 +31,40 @@ func _outside(popup: PopupWindow) -> Vector2:
else Vector2(rect.position.x - 5, rect.position.y - 5)
func test_backdrop_is_hidden_without_popups() -> void:
assert_bool(_backdrop().visible).is_false()
func test_backdrops_are_hidden_without_popups() -> void:
assert_bool(_backdrop(_popup("SettingsWindow")).visible).is_false()
assert_bool(_backdrop(_popup("AboutWindow")).visible).is_false()
func test_backdrop_covers_the_whole_window() -> void:
_popup("SettingsWindow").open()
func test_backdrops_cover_the_whole_window() -> void:
for node_name: String in ["SettingsWindow", "AboutWindow"]:
var popup: PopupWindow = _popup(node_name)
popup.open()
assert_vector(_backdrop().get_global_rect().size).is_equal(_window.get_viewport_rect().size)
assert_object(_backdrop(popup).get_global_rect()).override_failure_message(
"%s: backdrop does not cover the window" % node_name) \
.is_equal(_window.get_viewport_rect())
popup.close()
func test_every_popup_is_a_popup_window() -> void:
for node_name: String in POPUP_NODES:
assert_object(_window.get_node(node_name)).is_instanceof(PopupWindow)
for node_name: String in MAIN_POPUPS + QUIZ_POPUPS:
assert_object(_popup(node_name)).is_instanceof(PopupWindow)
func test_every_popup_shows_backdrop_and_closes_on_outside_click() -> void:
for node_name: String in POPUP_NODES:
for node_name: String in MAIN_POPUPS + QUIZ_POPUPS:
var popup: PopupWindow = _popup(node_name)
popup.open()
await _runner.simulate_frames(1)
assert_bool(_backdrop().visible).override_failure_message(
assert_bool(_backdrop(popup).visible).override_failure_message(
"%s: backdrop not shown" % node_name).is_true()
await _click_at(_outside(popup))
assert_bool(popup.visible).override_failure_message(
"%s: not closed by outside click" % node_name).is_false()
assert_bool(_backdrop().visible).override_failure_message(
assert_bool(_backdrop(popup).visible).override_failure_message(
"%s: backdrop still shown" % node_name).is_false()
@@ -75,7 +80,7 @@ func test_click_inside_popup_keeps_it_open() -> void:
func test_closing_click_does_not_press_button_behind_popup() -> void:
var settings: PopupWindow = _popup("SettingsWindow")
var reset_button: Button = _window.get_node("ResetPlaylistButton")
var reset_button: Button = _quiz.get_node("ResetPlaylistButton")
settings.open()
await _runner.simulate_frames(1)
assert_bool(settings.panel.get_global_rect().intersects(reset_button.get_global_rect())) \
@@ -88,7 +93,7 @@ func test_closing_click_does_not_press_button_behind_popup() -> void:
func test_button_works_again_after_popup_closed() -> void:
var reset_button: Button = _window.get_node("ResetPlaylistButton")
var reset_button: Button = _quiz.get_node("ResetPlaylistButton")
await _click_at(reset_button.get_global_rect().get_center())
+195
View File
@@ -0,0 +1,195 @@
extends MainWindowTestSuite
## The main window holds the top bar, the quiz and the popups opened from the top bar.
## These tests check that the parts are where they belong and still work together:
## clicks reach the right scene, popups dim the whole window, and syncing, changing
## server and the keyboard shortcuts reach both the main window and the quiz.
const MAIN_WINDOW_CHILDREN: Array[String] = [
"TopBar", "Quiz", "PopupBackdrop", "Search", "SyncWindow", "QRWindow",
"ShortcutsWindow", "StatisticsPopupPanel", "AboutWindow",
]
const TOP_BAR_CHILDREN: Array[String] = [
"TopPanelContainer", "Title", "SyncButton", "SearchButton", "StatisticsButton",
"ShortcutsButton", "AboutButton", "QRButton",
]
## Each top bar button and the popup it opens in the main window.
const TOP_BAR_POPUPS: Dictionary = {
"SearchButton": "Search",
"SyncButton": "SyncWindow",
"StatisticsButton": "StatisticsPopupPanel",
"ShortcutsButton": "ShortcutsWindow",
"AboutButton": "AboutWindow",
"QRButton": "QRWindow",
}
func _top_bar_button(button_name: String) -> Button:
return _window.get_node("TopBar/" + button_name)
func _children(node: Node) -> Array[String]:
var names: Array[String] = []
for child: Node in node.get_children():
names.append(String(child.name))
return names
func _center(control: Control) -> Vector2:
return control.get_global_rect().get_center()
func test_main_window_holds_only_top_bar_quiz_and_its_popups() -> void:
assert_array(_children(_window)).contains_exactly_in_any_order(MAIN_WINDOW_CHILDREN)
func test_top_bar_is_drawn_below_the_quiz() -> void:
# The quiz popups' backdrop has to cover the top bar too
assert_int(_window.get_node("TopBar").get_index()) \
.is_less(_window.get_node("Quiz").get_index())
func test_top_bar_holds_only_title_and_buttons() -> void:
assert_array(_children(_window.get_node("TopBar"))) \
.contains_exactly_in_any_order(TOP_BAR_CHILDREN)
func test_quiz_and_top_bar_let_clicks_through_where_they_are_empty() -> void:
assert_int(_quiz.mouse_filter).is_equal(Control.MOUSE_FILTER_IGNORE)
assert_int((_window.get_node("TopBar") as Control).mouse_filter) \
.is_equal(Control.MOUSE_FILTER_IGNORE)
func test_clicking_each_top_bar_button_opens_its_popup() -> void:
for button_name: String in TOP_BAR_POPUPS:
var popup: Node = _window.get_node(TOP_BAR_POPUPS[button_name])
await _click_at(_center(_top_bar_button(button_name)))
assert_bool(popup.visible).override_failure_message(
"%s did not open %s" % [button_name, popup.name]).is_true()
if popup is PopupWindow:
popup.close()
else:
popup.visible = false
await _runner.simulate_frames(1)
func test_clicking_quiz_buttons_plays_and_shows_answer() -> void:
await _click_at(_center(_quiz.get_node("NextButton")))
await _runner.simulate_frames(2)
assert_int(Playlist.currently_playing_song).is_equal(0)
assert_str((_quiz.get_node("VBoxContainer/SoundtrackLabel") as Label).text) \
.is_not_equal("Chrono Trigger")
await _click_at(_center(_quiz.get_node("ShowAnswerButton")))
assert_str((_quiz.get_node("VBoxContainer/SoundtrackLabel") as Label).text) \
.is_equal("Chrono Trigger")
func test_quiz_popup_backdrop_covers_the_top_bar() -> void:
var settings: PopupWindow = _quiz.get_node("SettingsWindow")
settings.open()
await _runner.simulate_frames(1)
var backdrop: Control = _quiz.get_node("PopupBackdrop")
assert_bool(backdrop.visible).is_true()
assert_bool(backdrop.get_global_rect().encloses(
(_window.get_node("TopBar/TopPanelContainer") as Control).get_global_rect())) \
.is_true()
func test_click_on_top_bar_while_quiz_popup_is_open_only_closes_it() -> void:
var settings: PopupWindow = _quiz.get_node("SettingsWindow")
var search: PopupWindow = _window.get_node("Search")
settings.open()
await _runner.simulate_frames(1)
await _click_at(_center(_top_bar_button("SearchButton")))
assert_bool(settings.visible).is_false()
assert_bool(search.visible).is_false()
func test_sync_disables_quiz_buttons_until_finished() -> void:
_server.respond_bytes("/sync", PackedByteArray())
_server.respond_json("/sync/progress", {"progress": 10, "time_spent": "00:00:01"})
var sync_window: PopupWindow = _window.get_node("SyncWindow")
_top_bar_button("SyncButton").pressed.emit()
sync_window.sync_timer.stop()
for button_name: String in ["SoundTestButton", "ResetPlaylistButton", "ShowAnswerButton",
"NextButton"]:
assert_bool((_quiz.get_node(button_name) as Button).disabled) \
.override_failure_message(button_name + " not disabled").is_true()
assert_bool(_top_bar_button("SyncButton").disabled).is_false()
_server.respond_json("/sync/progress", UiTour.SYNC_RESULT)
var reloads_before: int = _server.count("/music/all/order")
sync_window._on_sync_timeout()
await _runner.simulate_frames(2)
for button_name: String in ["SoundTestButton", "ResetPlaylistButton", "ShowAnswerButton",
"NextButton"]:
assert_bool((_quiz.get_node(button_name) as Button).disabled) \
.override_failure_message(button_name + " still disabled").is_false()
# The search list in the main window and the quiz playlist are both reloaded
assert_int(_server.count("/music/all/order")).is_equal(reloads_before + 1)
assert_int(_server.count("/music/reset")).is_equal(1)
func test_changing_server_reloads_search_and_quiz() -> void:
var search_loads: int = _server.count("/music/all/order")
var inspiration_loads: int = _server.count("/music/all")
var player: PlayerObject = _add_player("Crono")
player.add_point()
_quiz.get_node("SettingsWindow").server_changed.emit()
assert_int(_server.count("/music/all/order")).is_equal(search_loads + 1)
assert_int(_server.count("/music/all")).is_equal(inspiration_loads + 1)
assert_int(_server.count("/music/reset")).is_equal(1)
assert_int(player.player_score).is_equal(0)
func test_alt_k_opens_shortcuts_and_alt_l_opens_log() -> void:
await _press_keys([KEY_ALT, KEY_K])
assert_bool((_window.get_node("ShortcutsWindow") as Control).visible).is_true()
await _press_keys([KEY_ALT, KEY_L])
assert_bool((_quiz.get_node("Log") as Control).visible).is_true()
func test_alt_down_lowers_the_volume() -> void:
var bus: int = AudioServer.get_bus_index("Master")
var volume_db: float = AudioServer.get_bus_volume_db(bus)
var slider: HSlider = _quiz.get_node("MusicPlayer").volume_slider
var volume: float = slider.value
await _press_keys([KEY_ALT, KEY_DOWN])
assert_float(slider.value).is_less(volume)
AudioServer.set_bus_volume_db(bus, volume_db)
func test_alt_enter_switches_fullscreen_and_settings_shows_it() -> void:
var settings: PopupWindow = _quiz.get_node("SettingsWindow")
var was_fullscreen: bool = Settings.fullscreen
await _press_keys([KEY_ALT, KEY_ENTER])
settings.open()
assert_bool(Settings.fullscreen).is_equal(!was_fullscreen)
assert_bool(settings.fullscreen_button.button_pressed).is_equal(!was_fullscreen)
await _press_keys([KEY_ALT, KEY_ENTER])
assert_bool(Settings.fullscreen).is_equal(was_fullscreen)
func test_statistics_counts_the_soundtracks() -> void:
_top_bar_button("StatisticsButton").pressed.emit()
assert_str((_window.get_node("StatisticsPopupPanel/StatisticsLabel") as Label).text) \
.is_equal("Total amount of soundtracks in the playlist: 2")
@@ -0,0 +1 @@
uid://c6lqhrfu02227
+2 -2
View File
@@ -12,7 +12,7 @@ func before_test() -> void:
func _stats_checkbox() -> CheckButton:
return _window.get_node("SettingsWindow").get_node("%AddToDatabaseCheckButton")
return _quiz.get_node("SettingsWindow").get_node("%AddToDatabaseCheckButton")
func test_winning_turns_statistics_off() -> void:
@@ -57,7 +57,7 @@ func test_songs_after_a_win_are_not_counted() -> void:
func test_winning_score_cannot_go_below_one() -> void:
_press("SettingsButton")
var lower_button: Button = _window.get_node("SettingsWindow").get_node("%LowerButton")
var lower_button: Button = _quiz.get_node("SettingsWindow").get_node("%LowerButton")
for i: int in 3:
lower_button.pressed.emit()