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")