Files
MusicPlayer/tests/integration/test_inspiration_list.gd
Sansan 222d231b1b
Build / test (push) Successful in 1m2s
Build / build (push) Successful in 1m12s
Add offline mode: play from a music folder instead of the server
Settings has a Music folder row. A folder with subfolders is played as
soundtracks: Next picks a random subfolder and a random song in it, the
subfolder is the answer's soundtrack and the file name without its type the
song. The inspiration list and Search show the subfolders.

A folder with songs and no subfolders is a prepared quiz, played once in order
(natural sort) or at random, showing only the song title. It has no winning
score: after the last song Next becomes Show winner, and the players with the
most points win, ties included.

While a folder is used nothing but the characters is asked from the server:
Sync, QR, Statistics, the update check and play counting are off. Characters
fall back to the cached pictures when the server can't be reached. mp3, ogg and
wav play; other files and broken ones are skipped.

The old local playback code, the hidden Open button and the hidden Local toggle
are removed. Next now waits for the song to start before preparing the next one.
2026-10-07 23:07:47 +02:00

93 lines
2.4 KiB
GDScript

extends GdUnitTestSuite
## The inspiration list on its own: it shows every soundtrack from the server and
## scrolls by itself.
const SOUNDTRACKS: Array[String] = ["Chrono Trigger", "Final Fantasy VI", "Secret of Mana"]
var _snapshot: AutoloadSnapshot
var _server: FakeHttpTransport
var _runner: GdUnitSceneRunner
var _list: InspirationList
func before_test() -> void:
_snapshot = AutoloadSnapshot.take([Settings])
Settings.inspiration_list_speed = 0
_server = FakeHttpTransport.new().install()
_server.respond_json("/music/all", SOUNDTRACKS)
_runner = scene_runner("res://quiz/InspirationList.tscn")
_list = _runner.scene()
func after_test() -> void:
await await_idle_frame()
_server.uninstall()
_snapshot.restore()
func _rows() -> Array[Node]:
return _list.get_node("VBoxContainer").get_children()
func _texts() -> Array:
return _rows().map(func(row: ListRow) -> String: return row.text)
func test_load_soundtracks_shows_every_soundtrack_in_order() -> void:
_list.load_soundtracks()
assert_array(_texts()).contains_exactly(SOUNDTRACKS)
assert_array(_list.soundtracks).contains_exactly(SOUNDTRACKS)
func test_rows_alternate_backgrounds() -> void:
_list.load_soundtracks()
var rows: Array[Node] = _rows()
assert_that((rows[0] as ListRow).get_theme_stylebox("panel")) \
.is_not_equal((rows[1] as ListRow).get_theme_stylebox("panel"))
assert_that((rows[0] as ListRow).get_theme_stylebox("panel")) \
.is_equal((rows[2] as ListRow).get_theme_stylebox("panel"))
func test_loading_again_replaces_the_rows() -> void:
_list.load_soundtracks()
_server.respond_json("/music/all", ["Terranigma"])
_list.load_soundtracks()
assert_array(_texts()).contains_exactly(["Terranigma"])
func test_failed_load_keeps_the_rows() -> void:
_list.load_soundtracks()
_server.respond_bytes("/music/all", PackedByteArray(), 500)
_list.load_soundtracks()
assert_array(_texts()).contains_exactly(SOUNDTRACKS)
func _long_list() -> Array[String]:
var names: Array[String] = []
for i: int in 40:
names.append("Soundtrack %d" % i)
return names
func test_scrolls_down_by_itself() -> void:
_list.show_soundtracks(_long_list())
Settings.inspiration_list_speed = 5
await _runner.simulate_frames(30, 16)
assert_int(_list.scroll_vertical).is_greater(0)
func test_does_not_scroll_at_speed_zero() -> void:
_list.show_soundtracks(_long_list())
await _runner.simulate_frames(30, 16)
assert_int(_list.scroll_vertical).is_equal(0)