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.
93 lines
2.5 KiB
GDScript
93 lines
2.5 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://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_from_server_shows_every_soundtrack_in_order() -> void:
|
|
_list.load_from_server()
|
|
|
|
assert_array(_texts()).contains_exactly(SOUNDTRACKS)
|
|
assert_array(_list.soundtracks).contains_exactly(SOUNDTRACKS)
|
|
|
|
|
|
func test_rows_alternate_backgrounds() -> void:
|
|
_list.load_from_server()
|
|
|
|
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_from_server()
|
|
_server.respond_json("/music/all", ["Terranigma"])
|
|
|
|
_list.load_from_server()
|
|
|
|
assert_array(_texts()).contains_exactly(["Terranigma"])
|
|
|
|
|
|
func test_failed_load_keeps_the_rows() -> void:
|
|
_list.load_from_server()
|
|
_server.respond_bytes("/music/all", PackedByteArray(), 500)
|
|
|
|
_list.load_from_server()
|
|
|
|
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)
|