Files
MusicPlayer/tests/unit/test_playlist.gd
T
Sansan e1e05f3904
Build / test (push) Successful in 38s
Build / build (push) Successful in 1m12s
Show a graph of the game on the Winner popup
The Winner popup now shows every player's score after each song as a
step line, with the winning score marked, and three facts under it: the
longest streak, the longest standstill and the song most players scored
on. The data comes from the points each song already records, through
the new ScoreHistory. The popup grows to 1600x920 with the graph across
the full width, so a 60-song game with five players stays readable.

Reset points now starts a new game: it clears the points on the songs
and the graph starts after the song that was playing. Songs already on
the server at startup count as an earlier game.

The screenshot tour has a long five-player game, and only the Winner
popup differs from before.
2026-10-07 10:40:46 +02:00

223 lines
6.0 KiB
GDScript

extends GdUnitTestSuite
## Playlist: moving through the songs, answering them and keeping points.
var _server: FakeHttpTransport
var _add_to_stats: bool
var _is_debug: bool
func before_test() -> void:
_server = FakeHttpTransport.new().install()
_add_to_stats = Settings.add_to_stats
_is_debug = Settings.is_debug
Settings.add_to_stats = false
Settings.is_debug = false
Playlist.reset_playlist()
Playlist.number_of_tracks_to_preload = 1
func after_test() -> void:
Playlist.reset_playlist()
Settings.add_to_stats = _add_to_stats
Settings.is_debug = _is_debug
_server.uninstall()
func _add_songs(count: int) -> Array[SongObject]:
var songs: Array[SongObject] = []
for i: int in count:
var song: SongObject = SongObject.new()
song.song_number = i
song.soundtrack_title = "Soundtrack %d" % i
song.song_title = "Song %d" % i
Playlist.add_to_playlist(song)
songs.append(song)
return songs
func test_set_latest_played_song_advances() -> void:
_add_songs(3)
Playlist.set_latest_played_song()
assert_int(Playlist.latest_played_song).is_equal(1)
func test_set_latest_played_song_stops_at_last_song() -> void:
_add_songs(2)
Playlist.set_latest_played_song()
Playlist.set_latest_played_song()
Playlist.set_latest_played_song()
assert_int(Playlist.latest_played_song).is_equal(1)
func test_get_next_song_returns_latest_played() -> void:
var songs: Array[SongObject] = _add_songs(3)
Playlist.latest_played_song = 2
assert_object(Playlist.get_next_song()).is_same(songs[2])
func test_update_last_played_song_points_past_existing_songs() -> void:
_add_songs(4)
Playlist.update_last_played_song()
assert_int(Playlist.latest_played_song).is_equal(4)
func test_preloaded_songs_counts_unplayed_songs() -> void:
var songs: Array[SongObject] = _add_songs(3)
songs[0].has_played = true
assert_int(Playlist.get_preloaded_songs()).is_equal(2)
func test_should_preload_more_songs_when_below_target() -> void:
var songs: Array[SongObject] = _add_songs(1)
songs[0].has_played = true
assert_bool(Playlist.should_preload_more_songs()).is_true()
func test_should_not_preload_more_songs_when_target_reached() -> void:
_add_songs(1)
assert_bool(Playlist.should_preload_more_songs()).is_false()
func test_get_playlist_hides_unplayed_songs() -> void:
var songs: Array[SongObject] = _add_songs(3)
songs[0].has_played = true
assert_array(Playlist.get_playlist()).contains_exactly([songs[0]])
func test_get_playlist_shows_everything_in_debug() -> void:
Settings.is_debug = true
var songs: Array[SongObject] = _add_songs(2)
assert_array(Playlist.get_playlist()).contains_exactly(songs)
func test_song_is_answered_marks_song() -> void:
var songs: Array[SongObject] = _add_songs(2)
Playlist.song_is_answered(1)
assert_bool(songs[1].is_answered).is_true()
assert_bool(songs[0].is_answered).is_false()
func test_song_is_answered_reports_to_stats_when_enabled() -> void:
Settings.add_to_stats = true
_add_songs(2)
Playlist.song_is_answered(1)
assert_array(_server.requested_paths).contains_exactly(["/music/played?song=1"])
func test_song_is_answered_does_not_report_when_stats_disabled() -> void:
_add_songs(2)
Playlist.song_is_answered(1)
assert_array(_server.requested_paths).is_empty()
func test_points_are_recorded_on_current_song() -> void:
var songs: Array[SongObject] = _add_songs(2)
Playlist.set_currently_playing_song(1)
Playlist.add_point("lucca-id")
Playlist.add_point("crono-id")
assert_array(songs[1].players_given_point).contains_exactly(["lucca-id", "crono-id"])
assert_array(songs[0].players_given_point).is_empty()
func test_remove_point_from_current_song() -> void:
var songs: Array[SongObject] = _add_songs(1)
Playlist.set_currently_playing_song(0)
Playlist.add_point("crono-id")
Playlist.add_point("marle-id")
Playlist.remove_point("crono-id")
assert_array(songs[0].players_given_point).contains_exactly(["marle-id"])
func test_remove_player_removes_only_that_players_points() -> void:
var songs: Array[SongObject] = _add_songs(2)
songs[0].players_given_point.assign(["crono-id", "marle-id"])
songs[1].players_given_point.assign(["crono-id"])
Playlist.remove_player_from_list("marle-id")
assert_array(songs[0].players_given_point).contains_exactly(["crono-id"])
assert_array(songs[1].players_given_point).contains_exactly(["crono-id"])
func test_clear_points_empties_every_song() -> void:
var songs: Array[SongObject] = _add_songs(2)
songs[0].players_given_point.assign(["crono-id", "marle-id"])
songs[1].players_given_point.assign(["crono-id"])
Playlist.clear_points()
assert_array(songs[0].players_given_point).is_empty()
assert_array(songs[1].players_given_point).is_empty()
func test_reset_playlist_starts_a_new_game() -> void:
_add_songs(3)
Playlist.game_start_song = 2
Playlist.reset_playlist()
assert_int(Playlist.game_start_song).is_equal(0)
func test_reset_playlist_clears_songs_and_position() -> void:
_add_songs(3)
Playlist.latest_played_song = 2
Playlist.set_currently_playing_song(1)
Playlist.reset_playlist()
assert_array(Playlist.song_object_array).is_empty()
assert_int(Playlist.latest_played_song).is_equal(0)
assert_int(Playlist.currently_playing_song).is_equal(-1)
func test_current_titles_are_hidden_until_answered() -> void:
var songs: Array[SongObject] = _add_songs(1)
Playlist.set_currently_playing_song(0)
assert_str(Playlist.get_current_soundtrack_title()).is_equal("????????")
songs[0].is_answered = true
assert_str(Playlist.get_current_soundtrack_title()).is_equal("Soundtrack 0")
assert_str(Playlist.get_current_song_title()).is_equal("Song 0")
func test_answering_when_nothing_is_playing_does_nothing() -> void:
Settings.add_to_stats = true
var songs: Array[SongObject] = _add_songs(2)
Playlist.song_is_answered()
assert_bool(songs[0].is_answered).is_false()
assert_bool(songs[1].is_answered).is_false()
assert_array(_server.requested_paths).is_empty()
func test_answering_with_empty_playlist_does_nothing() -> void:
Playlist.song_is_answered()
assert_array(_server.requested_paths).is_empty()