Files
MusicPlayer/tests/unit/test_playlist.gd
T
Sansan ab338b0696 Add GdUnit4 testing framework with comprehensive test coverage
- Add GdUnit4 v6.2.1 framework in addons/gdUnit4/
- Create test directory structure (tests/unit/, tests/integration/, tests/mocks/)
- Add unit tests for MusicPlayer.gd (8 tests)
- Add unit tests for MainWindow.gd (15+ tests)
- Add unit tests for Settings.gd (5 tests)
- Add unit tests for Playlist.gd (11 tests)
- Add integration tests for full flow (10+ tests)
- Add MockHTTPRequest for HTTP request mocking
- Add TestHelpers with utility functions
- Add Gitea Actions CI workflow (.gitea/workflows/test.yml)
- Add .runsettings for GdUnit4 CLI configuration
- Add run_tests.sh for convenient test execution
- Add TESTING.md with comprehensive documentation
- Add TESTING_PLAN.md with implementation details
- Update .gitignore for test artifacts
- Enable GdUnit4 plugin in project.godot

Features:
- Test button functionality (play, pause, search, sync, etc.)
- Mock REST API requests to server
- Test complete application flows
- Run tests in CI (headless mode)
- Run tests in GUI for visual feedback
- JUnit XML and HTML test reports

Generated by OpenCode AI assistant.
2026-10-06 08:32:55 +02:00

174 lines
4.2 KiB
GDScript

class_name PlaylistTest
extends GdUnitTestSuite
func test_add_to_playlist_increases_size():
Playlist.clear_song_list()
var initial_size = Playlist.song_object_array.size()
var song_obj = TestHelpers.create_test_song_object()
Playlist.add_to_playlist(song_obj)
assert_eq(Playlist.song_object_array.size(), initial_size + 1)
func test_get_next_song_returns_correct_song():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1, "Soundtrack 1", "Song 1")
var song2 = TestHelpers.create_test_song_object(2, "Soundtrack 2", "Song 2")
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
Playlist.latest_played_song = 0
var next_song = Playlist.get_next_song()
assert_eq(next_song, song1)
func test_set_latest_played_song_increments():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1)
var song2 = TestHelpers.create_test_song_object(2)
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
Playlist.latest_played_song = 0
Playlist.set_latest_played_song()
assert_eq(Playlist.latest_played_song, 1)
func test_set_latest_played_song_does_not_exceed_bounds():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song1)
Playlist.latest_played_song = 0
Playlist.set_latest_played_song()
Playlist.set_latest_played_song()
assert_eq(Playlist.latest_played_song, 0)
func test_get_preloaded_songs_returns_correct_count():
Playlist.clear_song_list()
var song1 = TestHelpers.create_test_song_object(1)
var song2 = TestHelpers.create_test_song_object(2)
var song3 = TestHelpers.create_test_song_object(3)
song1.has_played = true
song2.has_played = false
song3.has_played = false
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
Playlist.add_to_playlist(song3)
assert_eq(Playlist.get_preloaded_songs(), 2)
func test_should_preload_more_songs():
Playlist.clear_song_list()
Playlist.number_of_tracks_to_preload = 2
var song1 = TestHelpers.create_test_song_object(1)
var song2 = TestHelpers.create_test_song_object(2)
song1.has_played = true
song2.has_played = false
Playlist.add_to_playlist(song1)
Playlist.add_to_playlist(song2)
assert_true(Playlist.should_preload_more_songs())
var song3 = TestHelpers.create_test_song_object(3)
Playlist.add_to_playlist(song3)
assert_false(Playlist.should_preload_more_songs())
func test_song_is_answered_sets_flag():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.currently_playing_song = 0
assert_false(song.is_answered)
Playlist.song_is_answered()
assert_true(song.is_answered)
func test_add_point_to_song():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.currently_playing_song = 0
Playlist.add_point(0)
assert_true(song.players_given_point.has(0))
func test_remove_point_from_song():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.currently_playing_song = 0
Playlist.add_point(0)
Playlist.remove_point(0)
assert_false(song.players_given_point.has(0))
func test_get_song_returns_correct_stream():
Playlist.clear_song_list()
var expected_stream = TestHelpers.create_mock_audio_stream()
var song = TestHelpers.create_test_song_object(1)
song.song = expected_stream
Playlist.add_to_playlist(song)
var retrieved_stream = Playlist.get_song(0)
assert_eq(retrieved_stream, expected_stream)
func test_reset_playlist_clears_all():
Playlist.clear_song_list()
var song = TestHelpers.create_test_song_object(1)
Playlist.add_to_playlist(song)
Playlist.latest_played_song = 1
Playlist.currently_playing_song = 0
Playlist.reset_playlist()
assert_eq(Playlist.song_object_array.size(), 0)
assert_eq(Playlist.latest_played_song, 0)
assert_eq(Playlist.currently_playing_song, -1)
func test_clear_song_list_removes_all():
Playlist.clear_song_list()
Playlist.add_to_playlist(TestHelpers.create_test_song_object(1))
Playlist.add_to_playlist(TestHelpers.create_test_song_object(2))
Playlist.clear_song_list()
assert_eq(Playlist.song_object_array.size(), 0)