Files
MusicPlayer/tests/integration/test_main_window.gd
SansanandClaude Opus 5.5 06421bb63e
Build / test (push) Successful in 1m50s
Build / build (push) Successful in 1m14s
Change soundtrack covers from the app and show the cover with the answer
Cover menu in the soundtrack popup ("Change cover"):
- Choose picture uploads a JPEG, PNG or WebP picture (up to 10 MB).
- Pick by ID uses a game's cover on SteamGridDB or an anime's on AniList.
- Remove cover deletes it, so the server searches for a new one.
- The server's reason is shown when it refuses a change.
After a change the new cover time is fetched, and the popup, the
statistics card and the quiz show the new cover.

Quiz: once the answer is shown, the soundtrack's cover shows to the left of
the titles. Cover and titles are centered together, left and right and up
and down, and each title keeps to two lines. Cover times come from the
soundtrack list, and songs keep their soundtrack's UUID, also in saves.

Requests can now send any body with its content type, and every 2xx answer
counts as success. Cover frames are 2:3 like the server's covers. Small
copies of real covers are used by the tests and screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 23:32:09 +02:00

243 lines
8.2 KiB
GDScript

extends MainWindowTestSuite
## Main window flows: startup, playing songs and resetting.
func test_startup_loads_soundtracks_and_preloads_a_song() -> void:
assert_int(_server.count("/music/list")).is_equal(1)
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((_quiz.get_node("SongControls/NextButton") as Button).disabled).is_false()
func test_low_played_mode_fetches_from_low_played_endpoint() -> void:
Settings.random_mode = Settings.RandomMode.LOW_PLAYED
_server.respond_bytes(
"/music/rand/low", FileAccess.get_file_as_bytes("res://tests/data/short.mp3"))
_quiz.song_loader.fetch_song()
assert_int(_server.count("/music/rand/low")).is_equal(1)
func test_next_plays_preloaded_song_and_fetches_another() -> void:
_next_song_is(SONG_INFO[1])
_press("SongControls/NextButton")
await _runner.simulate_frames(2)
assert_int(Playlist.currently_playing_song).is_equal(0)
assert_bool(Playlist.song_object_array[0].has_played).is_true()
assert_int(Playlist.song_object_array.size()).is_equal(2)
assert_int(_server.count("/music/rand")).is_equal(2)
func test_title_is_hidden_until_answer_is_shown() -> void:
var soundtrack_label: Label = _quiz.get_node("NowPlaying/Titles/SoundtrackLabel")
_press("SongControls/NextButton")
await _runner.simulate_frames(2)
assert_str(soundtrack_label.text).is_equal("????????")
_press("SongControls/ShowAnswerButton")
assert_str(soundtrack_label.text).is_equal("Chrono Trigger")
assert_int(_server.count("/music/played?song=0")).is_equal(1)
func test_reset_playlist_clears_server_and_preloads_again() -> void:
_press("SongControls/NextButton")
await _runner.simulate_frames(2)
_press("QuizToolbar/ResetPlaylistButton")
assert_int(_server.count("/music/reset")).is_equal(1)
assert_int(Playlist.currently_playing_song).is_equal(-1)
assert_int(Playlist.song_object_array.size()).is_equal(1)
assert_bool(Playlist.song_object_array[0].has_played).is_false()
func test_reset_points_sets_all_scores_to_zero() -> void:
_add_player("Crono").add_point()
_add_player("Marle").add_point()
_press("QuizToolbar/ResetPointsButton")
assert_int(Settings.player_array[0].player_score).is_equal(0)
assert_int(Settings.player_array[1].player_score).is_equal(0)
func test_cannot_add_more_than_max_players() -> void:
for i: int in Settings.MAX_NUMBER_OF_PLAYERS + 1:
_add_player("Player %d" % i)
assert_int(Settings.player_array.size()).is_equal(Settings.MAX_NUMBER_OF_PLAYERS)
func test_cannot_add_player_without_name() -> void:
_add_player("")
assert_array(Settings.player_array).is_empty()
func test_failed_song_download_is_retried_until_the_server_answers() -> void:
_quiz.song_loader.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")
_quiz.song_loader.fetch_song()
await await_millis(200)
assert_int(_server.count("/music/rand") - rand_requests_before).is_greater(1)
assert_int(Playlist.song_object_array.size()).is_equal(songs_before)
assert_bool(Playlist.is_song_downloading).is_true()
_server.respond_bytes("/music/rand", mp3)
await await_millis(200)
assert_int(Playlist.song_object_array.size()).is_equal(songs_before + 1)
assert_bool(Playlist.is_song_downloading).is_false()
func test_failed_song_info_retries_only_that_step() -> void:
_quiz.song_loader.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")
_quiz.song_loader.fetch_song()
await await_millis(200)
_next_song_is(SONG_INFO[1])
await await_millis(200)
# The song was downloaded and queued once; only the info request was repeated
assert_int(_server.count("/music/rand") - rand_before).is_equal(1)
assert_int(_server.count("/music/addQue") - queue_before).is_equal(1)
assert_int(Playlist.song_object_array.size()).is_equal(songs_before + 1)
assert_str(Playlist.song_object_array.back().song_title).is_equal("Dancing Mad")
assert_bool(Playlist.is_song_downloading).is_false()
func test_preloads_as_many_songs_as_the_cache_setting() -> void:
Playlist.number_of_tracks_to_preload = 3
_quiz.song_loader.fetch_song()
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_bool(Playlist.is_song_downloading).is_false()
func test_playing_a_song_tops_the_cache_up_again() -> void:
Playlist.number_of_tracks_to_preload = 3
_quiz.song_loader.fetch_song()
await _play_first_song()
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_int(Playlist.song_object_array.size()).is_equal(4)
func test_cache_keeps_filling_after_a_failed_download() -> void:
_quiz.song_loader.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)
_quiz.song_loader.fetch_song()
await await_millis(150)
assert_int(Playlist.get_preloaded_songs()).is_equal(2)
assert_bool(Playlist.is_song_downloading).is_true()
_server.respond_bytes("/music/rand", mp3)
await await_millis(150)
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
assert_bool(Playlist.is_song_downloading).is_false()
func _open_settings() -> void:
(_window.get_node("TopBar/%SettingsButton") as Button).pressed.emit()
func _close_settings() -> void:
(_window.get_node("SettingsPopup") as Control).visible = false
func _press_settings_button(unique_name: String) -> void:
(_window.get_node("SettingsPopup").get_node("%" + unique_name) as Button).pressed.emit()
func test_raising_cache_size_does_not_download_while_settings_are_open() -> void:
var downloads_before: int = _server.count("/music/rand")
_open_settings()
_press_settings_button("IncreaseCacheButton")
_press_settings_button("IncreaseCacheButton")
assert_int(Playlist.number_of_tracks_to_preload).is_equal(3)
assert_int(_server.count("/music/rand")).is_equal(downloads_before)
func test_closing_settings_fills_cache_to_new_size() -> void:
_open_settings()
_press_settings_button("IncreaseCacheButton")
_press_settings_button("IncreaseCacheButton")
_close_settings()
assert_int(Playlist.get_preloaded_songs()).is_equal(3)
func test_changing_cache_size_back_and_forth_downloads_only_what_is_needed() -> void:
var downloads_before: int = _server.count("/music/rand")
_open_settings()
for i: int in 5:
_press_settings_button("IncreaseCacheButton")
_press_settings_button("LowerCacheButton")
_press_settings_button("IncreaseCacheButton")
_close_settings()
assert_int(_server.count("/music/rand") - downloads_before).is_equal(1)
assert_int(Playlist.get_preloaded_songs()).is_equal(2)
func test_closing_settings_with_full_cache_downloads_nothing() -> void:
var downloads_before: int = _server.count("/music/rand")
_open_settings()
_close_settings()
assert_int(_server.count("/music/rand")).is_equal(downloads_before)
func test_show_answer_before_first_song_does_not_reveal_next_song() -> void:
_press("SongControls/ShowAnswerButton")
assert_bool(Playlist.song_object_array[0].is_answered).is_false()
assert_int(_server.count("/music/played?song=-1")).is_equal(0)
await _play_first_song()
assert_str((_quiz.get_node("NowPlaying/Titles/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("%LogPopup").get_node("%LogVBoxContainer")
var crono: PlayerObject = _add_player("Crono")
await _play_first_song()
crono.add_point()
crono.minus_point()
assert_int(log_box.get_child_count()).is_equal(2)
var time_pattern: RegEx = RegEx.create_from_string("^\\d\\d:\\d\\d:\\d\\d Crono got a point$")
assert_object(time_pattern.search((log_box.get_child(0) as ListRow).text)).is_not_null()
assert_str((log_box.get_child(1) as ListRow).text).ends_with("Crono lost a point")