Files
MusicPlayer/tests/integration/test_music_list_panel.gd
Sansan d77b72159d Sort the scripts and scenes into folders
main/ holds the main window and top bar, quiz/ the quiz and its parts,
player/ the music player, popups/ every popup and what they share, data/ the
songs, players, playlist and settings, server/ the MusicServer client,
common/ the list row and GameLog, and themes/ the themes and style boxes.
2026-10-06 11:57:29 +02:00

80 lines
2.3 KiB
GDScript

extends GdUnitTestSuite
## The music list on its own: one row per song in the playlist, and clicking a row
## tells which song was clicked.
var _snapshot: AutoloadSnapshot
var _runner: GdUnitSceneRunner
var _panel: MusicListPanel
func before_test() -> void:
_snapshot = AutoloadSnapshot.take([Settings, Playlist])
Playlist.reset_playlist()
for i: int in 3:
var song: SongObject = SongObject.new()
song.song_number = i
song.soundtrack_title = "Soundtrack %d" % i
song.song_title = "Song %d" % i
song.has_played = true
Playlist.add_to_playlist(song)
_runner = scene_runner("res://quiz/MusicListPanel.tscn")
_panel = _runner.scene()
func after_test() -> void:
await await_idle_frame()
_snapshot.restore()
func _rows() -> Array[Node]:
return _panel.get_node("ScrollContainer/MusicList").get_children()
func test_starts_empty() -> void:
assert_array(_rows()).is_empty()
func test_refresh_shows_one_row_per_song_in_order() -> void:
_panel.refresh()
assert_array(_rows().map(func(row: SongRow) -> int: return row.song_object.song_number)) \
.contains_exactly([0, 1, 2])
func test_refresh_again_replaces_the_rows() -> void:
_panel.refresh()
Playlist.song_object_array.pop_back()
_panel.refresh()
assert_int(_rows().size()).is_equal(2)
func test_clicking_a_row_tells_which_song() -> void:
_panel.refresh()
await _runner.simulate_frames(2)
var signals: GdUnitSignalAssert = assert_signal(monitor_signals(_panel))
var row: Control = _rows()[1]
# The left end of the row is the song text, not one of the player icons
var target: Vector2 = row.get_global_rect().position + Vector2(20, row.size.y / 2)
_runner.set_mouse_position(_panel.get_viewport().get_final_transform() * target)
await _runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await _runner.await_input_processed()
await signals.is_emitted("song_clicked", [1])
func test_right_click_does_nothing() -> void:
_panel.refresh()
await _runner.simulate_frames(2)
var signals: GdUnitSignalAssert = assert_signal(monitor_signals(_panel))
var row: Control = _rows()[0]
_runner.set_mouse_position(_panel.get_viewport().get_final_transform()
* (row.get_global_rect().position + Vector2(20, row.size.y / 2)))
await _runner.simulate_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
await _runner.await_input_processed()
await signals.wait_until(200).is_not_emitted("song_clicked")