Files
MusicPlayer/tests/integration/test_player_keybinds.gd
T
Sansan 8c1987807c Make the music list, player list and inspiration list their own scenes
MusicListPanel, PlayersPanel (was Players) and InspirationList (was
ScrollContainer) each get their own scene and script. They report what
happens through signals, and the quiz wires them to the playlist, the
music player, the log and the popups. Every node keeps its place on screen.

Screenshots of every UI state are pixel-identical to before, the layout
test still matches the original baseline, and each part is tested on its
own as well as through the quiz.
2026-10-06 10:27:35 +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] = _quiz.get_node(
"PlayersPanel/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])