diff --git a/playlist.gd b/playlist.gd index 13b459a..bb338fb 100644 --- a/playlist.gd +++ b/playlist.gd @@ -36,6 +36,9 @@ func set_last_played_answered() -> void: song_object_array[latest_played_song].is_answered = true func song_is_answered(song_no: int = currently_playing_song) -> void: + # Nothing is playing yet (-1); a negative index would answer the last, unplayed song + if song_no < 0 || song_no >= song_object_array.size(): + return print("show_answer_pressed song_object: ", song_object_array[song_no]._to_string()) song_object_array[song_no].is_answered = true if Settings.add_to_stats: diff --git a/tests/integration/test_main_window.gd b/tests/integration/test_main_window.gd index 49c7f52..9c0c26d 100644 --- a/tests/integration/test_main_window.gd +++ b/tests/integration/test_main_window.gd @@ -214,3 +214,15 @@ func test_closing_settings_with_full_cache_downloads_nothing() -> void: _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("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((_window.get_node("VBoxContainer/SoundtrackLabel") as Label).text) \ + .is_equal("????????") diff --git a/tests/unit/test_playlist.gd b/tests/unit/test_playlist.gd index 69aa659..cb63409 100644 --- a/tests/unit/test_playlist.gd +++ b/tests/unit/test_playlist.gd @@ -182,3 +182,20 @@ func test_current_titles_are_hidden_until_answered() -> void: 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()