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_quiz_parts_are_their_own_scenes() -> void: for node_name: String in ["MusicListPanel", "PlayersPanel", "InspirationList"]: assert_str(_quiz.get_node(node_name).scene_file_path) \ .is_equal("res://%s.tscn" % node_name) 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_clicking_a_song_in_the_music_list_plays_it() -> void: _next_song_is(SONG_INFO[1]) await _play_first_song() _press("NextButton") # Changing song waits a moment for the old one to stop await get_tree().create_timer(0.7).timeout assert_int(Playlist.currently_playing_song).is_equal(1) var rows: Array[Node] = _quiz.get_node("MusicListPanel/ScrollContainer/MusicList") \ .get_children() var first_row: Control = rows.filter( func(row: SongListObject) -> bool: return row.song_object.song_number == 0)[0] await _click_at(first_row.get_global_rect().position + Vector2(20, first_row.size.y / 2)) await get_tree().create_timer(0.7).timeout assert_int(Playlist.currently_playing_song).is_equal(0) func test_points_from_the_player_list_reach_the_song_and_log() -> void: await _play_first_song() var crono: PlayerObject = _add_player("Crono") (_player_row(crono).get_node("HBoxContainer/AddPoint") as BaseButton).pressed.emit() assert_array(Playlist.song_object_array[0].players_given_point).contains_exactly([crono.id]) assert_int((_quiz.get_node("%Log").get_node("%LogVBoxContainer") as Node).get_child_count()) \ .is_equal(1) func test_character_button_in_the_player_list_picks_a_new_character() -> void: var crono: PlayerObject = _add_player("Crono") var character_select: PopupWindow = _quiz.get_node("NewCharacterSelect") (_player_row(crono).get_node("HBoxContainer/Character") as BaseButton).pressed.emit() assert_bool(character_select.visible).is_true() var texture: ImageTexture = ImageTexture.create_from_image( Image.create(4, 4, false, Image.FORMAT_RGBA8)) character_select.new_new_character_selected.emit(texture) assert_object(crono.character).is_same(texture) 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")