Files
MusicPlayer/tests/integration/test_main_window.gd
T
Sansan c985a6ce5b Replace the broken test suite with working GdUnit4 tests
The previous tests never compiled: they used GUT's assert functions,
Godot 3 APIs and reassigned autoload functions, so no test ran.

- 90 tests: unit tests for the playlist, songs, player scoring, time
  formatting, search and the server client, plus integration tests
  that run MainWindow and SyncWindow against a fake server
- Keybind tests check that Alt+<number> and Ctrl+Alt+<number> keep
  following the player rows while players are added and removed
- run_tests.sh finds Godot and runs the suite headless (~10 seconds)
- CI runs the tests before the build job in gitea-build.yaml; the
  separate test.yml used a GitHub action that does not exist
- GdUnit4 is committed instead of ignored, since the project enables
  it, and .gitea/ is no longer ignored
- Exported builds leave out tests/ and addons/gdUnit4/
2026-10-06 08:32:56 +02:00

81 lines
2.7 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((_window.get_node("NextButton") as Button).disabled).is_false()
func test_low_played_mode_fetches_from_low_played_endpoint() -> void:
Settings.use_low_played_mode = true
_server.respond_bytes(
"/music/rand/low", FileAccess.get_file_as_bytes("res://tests/data/short.mp3"))
_runner.invoke("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("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 = _window.get_node("VBoxContainer/SoundtrackLabel")
_press("NextButton")
await _runner.simulate_frames(2)
assert_str(soundtrack_label.text).is_equal("????????")
_press("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("NextButton")
await _runner.simulate_frames(2)
_press("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("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()