Files
MusicPlayer/tests/integration/test_player_keybinds.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

153 lines
4.9 KiB
GDScript

extends MainWindowTestSuite
## Alt+<number> gives a point to the player in that row of the player list and
## Ctrl+Alt+<number> takes one away. These tests check that the keybinds keep
## following the rows while players are added and removed, and that points always
## end up with the right player.
var _crono: PlayerObject
var _marle: PlayerObject
var _lucca: PlayerObject
func before_test() -> void:
super()
_crono = _add_player("Crono")
_marle = _add_player("Marle")
_lucca = _add_player("Lucca")
await _play_first_song()
func _song_points() -> Array[String]:
return Playlist.song_object_array[Playlist.currently_playing_song].players_given_point
func test_alt_number_gives_point_to_player_in_that_row() -> void:
await _give_point_with_keybind(2)
assert_array(_scores()).contains_exactly([0, 1, 0])
assert_array(_song_points()).contains_exactly([_marle.id])
func test_ctrl_alt_number_takes_point_from_player_in_that_row() -> void:
await _give_point_with_keybind(3)
await _give_point_with_keybind(3)
await _take_point_with_keybind(3)
assert_array(_scores()).contains_exactly([0, 0, 1])
func test_taking_last_point_removes_player_from_song() -> void:
await _give_point_with_keybind(1)
await _take_point_with_keybind(1)
assert_int(_crono.player_score).is_equal(0)
assert_array(_song_points()).is_empty()
func test_each_keybind_only_affects_its_own_player() -> void:
await _give_point_with_keybind(1)
await _give_point_with_keybind(3)
await _give_point_with_keybind(3)
assert_int(_crono.player_score).is_equal(1)
assert_int(_marle.player_score).is_equal(0)
assert_int(_lucca.player_score).is_equal(2)
assert_array(_song_points()).contains_exactly([_crono.id, _lucca.id])
func test_number_without_player_does_nothing() -> void:
await _give_point_with_keybind(4)
assert_array(_scores()).contains_exactly([0, 0, 0])
assert_array(_song_points()).is_empty()
func test_keybinds_move_up_when_first_player_is_removed() -> void:
await _remove_player(_crono)
await _give_point_with_keybind(1)
await _give_point_with_keybind(2)
await _give_point_with_keybind(2)
assert_int(_marle.player_score).is_equal(1)
assert_int(_lucca.player_score).is_equal(2)
assert_array(_song_points()).contains_exactly([_marle.id, _lucca.id])
func test_keybind_after_last_row_does_nothing_after_removal() -> void:
await _remove_player(_marle)
await _give_point_with_keybind(3)
assert_int(_crono.player_score).is_equal(0)
assert_int(_lucca.player_score).is_equal(0)
func test_removing_player_removes_only_their_points() -> void:
await _give_point_with_keybind(1)
await _give_point_with_keybind(2)
await _give_point_with_keybind(3)
await _remove_player(_marle)
assert_array(_song_points()).contains_exactly([_crono.id, _lucca.id])
assert_int(_crono.player_score).is_equal(1)
assert_int(_lucca.player_score).is_equal(1)
func test_new_player_gets_next_free_keybind_after_removal() -> void:
await _remove_player(_marle)
var robo: PlayerObject = _add_player("Robo")
await _give_point_with_keybind(2)
await _give_point_with_keybind(3)
assert_int(_lucca.player_score).is_equal(1)
assert_int(robo.player_score).is_equal(1)
assert_int(_crono.player_score).is_equal(0)
assert_array(_song_points()).contains_exactly([_lucca.id, robo.id])
func test_new_player_does_not_inherit_removed_players_points() -> void:
await _give_point_with_keybind(3)
await _remove_player(_lucca)
var robo: PlayerObject = _add_player("Robo")
assert_int(robo.player_score).is_equal(0)
assert_array(_song_points()).is_empty()
func test_points_follow_players_through_several_changes() -> void:
await _give_point_with_keybind(1)
await _remove_player(_crono)
var robo: PlayerObject = _add_player("Robo")
await _give_point_with_keybind(1)
await _remove_player(_marle)
var ayla: PlayerObject = _add_player("Ayla")
await _give_point_with_keybind(3)
await _give_point_with_keybind(2)
await _take_point_with_keybind(2)
# Rows are now: Lucca, Robo, Ayla
assert_array(Settings.player_array).contains_exactly([_lucca, robo, ayla])
assert_int(_lucca.player_score).is_equal(0)
assert_int(robo.player_score).is_equal(0)
assert_int(ayla.player_score).is_equal(1)
assert_array(_song_points()).contains_exactly([ayla.id])
func test_player_list_shows_rows_in_player_order() -> void:
await _remove_player(_crono)
var robo: PlayerObject = _add_player("Robo")
var rows: Array[Node] = _window.get_node(
"Players/VBoxContainer/ScrollContainer/PlayersListVBoxContainer").get_children()
assert_array(rows.map(func(row: Player) -> PlayerObject: return row.player_object)) \
.contains_exactly([_marle, _lucca, robo])
assert_array(rows.map(func(row: Player) -> int: return row.list_index)) \
.contains_exactly([0, 1, 2])