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.
93 lines
2.4 KiB
GDScript
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_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)
|