Files
MusicPlayer/tests/integration/test_player_keybinds.gd
T
Sansan 390da577d7 Name popups *Popup and give scripts, scenes and classes matching names
Every popup is now called *Popup instead of *Window in its file, root node,
node name, class and variable, and PopupWindow becomes BasePopup. Player is
PlayerRow, SongListObject is SongRow and Character is CharacterCard. Script
files are snake_case and scene files PascalCase, each matching its class or
root node, and LightGrayTheme.tres is light_gray_theme.tres.
2026-10-06 11:22:39 +02:00

153 lines
4.7 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: PlayerRow) -> PlayerObject: return row.player_object)) \
.contains_exactly([_marle, _lucca, robo])
assert_array(rows.map(func(row: PlayerRow) -> int: return row.list_index)) \
.contains_exactly([0, 1, 2])