Replace the broken test suite with working GdUnit4 tests
The previous tests never compiled: they used GUT's assert functions, Godot 3 APIs and reassigned autoload functions, so no test ran. - 90 tests: unit tests for the playlist, songs, player scoring, time formatting, search and the server client, plus integration tests that run MainWindow and SyncWindow against a fake server - Keybind tests check that Alt+<number> and Ctrl+Alt+<number> keep following the player rows while players are added and removed - run_tests.sh finds Godot and runs the suite headless (~10 seconds) - CI runs the tests before the build job in gitea-build.yaml; the separate test.yml used a GitHub action that does not exist - GdUnit4 is committed instead of ignored, since the project enables it, and .gitea/ is no longer ignored - Exported builds leave out tests/ and addons/gdUnit4/
This commit is contained in:
1 parent
56e9fe66d3
commit
c985a6ce5b
559 files changed
+32474
-2100
No files matched your search
@@ -0,0 +1,145 @@
|
||||
extends GdUnitTestSuite
|
||||
|
||||
var _server: FakeHttpTransport
|
||||
var _snapshot: AutoloadSnapshot
|
||||
var _runner: GdUnitSceneRunner
|
||||
var _window: Control
|
||||
|
||||
|
||||
func before_test() -> void:
|
||||
_snapshot = AutoloadSnapshot.take([Settings])
|
||||
Settings.currently_syncing = false
|
||||
_server = FakeHttpTransport.new().install()
|
||||
_server.respond_bytes("/sync", PackedByteArray())
|
||||
_runner = scene_runner("res://SyncWindow.tscn")
|
||||
_window = _runner.scene()
|
||||
|
||||
|
||||
func after_test() -> void:
|
||||
_server.uninstall()
|
||||
_snapshot.restore()
|
||||
|
||||
|
||||
func _node(unique_name: String) -> Control:
|
||||
return _window.get_node("%" + unique_name)
|
||||
|
||||
|
||||
func _finish_sync(result: Dictionary) -> void:
|
||||
_server.respond_json("/sync/progress", result)
|
||||
_runner.invoke("_on_sync_timeout")
|
||||
|
||||
|
||||
func _empty_result() -> Dictionary:
|
||||
return {
|
||||
"soundtracks_added": [],
|
||||
"soundtracks_re_added": [],
|
||||
"soundtracks_changed_title": {},
|
||||
"soundtracks_changed_content": [],
|
||||
"soundtracks_removed": [],
|
||||
"catched_errors": [],
|
||||
"total_time": "00:00:03",
|
||||
}
|
||||
|
||||
|
||||
func test_start_sync_asks_server_and_shows_progress() -> void:
|
||||
monitor_signals(_window, false)
|
||||
|
||||
_runner.invoke("start_sync")
|
||||
|
||||
assert_array(_server.requested_paths).contains_exactly(["/sync"])
|
||||
assert_bool(Settings.currently_syncing).is_true()
|
||||
assert_bool(_node("ProgressHBoxContainer").visible).is_true()
|
||||
assert_str(_node("SyncTitleLabel").text).is_equal("Sync in Progress")
|
||||
await assert_signal(_window).is_emitted("sync_started")
|
||||
|
||||
|
||||
func test_start_sync_does_nothing_while_already_syncing() -> void:
|
||||
Settings.currently_syncing = true
|
||||
|
||||
_runner.invoke("start_sync")
|
||||
|
||||
assert_array(_server.requested_paths).is_empty()
|
||||
|
||||
|
||||
func test_progress_updates_progress_bar() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
_server.respond_json("/sync/progress", {"progress": "42", "time_spent": "00:00:12"})
|
||||
|
||||
_runner.invoke("_on_sync_timeout")
|
||||
|
||||
assert_float(_node("SyncProgressBar").value).is_equal(42.0)
|
||||
assert_str(_node("SyncTime").text).is_equal("00:00:12")
|
||||
|
||||
|
||||
func test_finished_sync_shows_only_sections_with_changes() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
monitor_signals(_window, false)
|
||||
var result: Dictionary = _empty_result()
|
||||
result.soundtracks_added = ["Chrono Cross", "Xenogears"]
|
||||
result.soundtracks_removed = ["Bad Rip"]
|
||||
|
||||
_finish_sync(result)
|
||||
|
||||
assert_bool(_node("SoundtracksAddedVBox").visible).is_true()
|
||||
assert_bool(_node("SoundtracksRemovedVBox").visible).is_true()
|
||||
assert_bool(_node("SoundtracksReAddedVBox").visible).is_false()
|
||||
assert_bool(_node("SoundtracksChangedTitleVBox").visible).is_false()
|
||||
assert_bool(_node("NoChangesLabel").visible).is_false()
|
||||
# Header plus one label per soundtrack
|
||||
assert_int(_node("SoundtracksAddedVBox").get_child_count()).is_equal(3)
|
||||
assert_str(_node("SyncTime").text).is_equal("Total time: 00:00:03")
|
||||
assert_bool(Settings.currently_syncing).is_false()
|
||||
await assert_signal(_window).is_emitted("sync_finished")
|
||||
|
||||
|
||||
func test_separator_shown_only_between_visible_sections() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
var result: Dictionary = _empty_result()
|
||||
result.soundtracks_added = ["Chrono Cross"]
|
||||
result.soundtracks_removed = ["Bad Rip"]
|
||||
|
||||
_finish_sync(result)
|
||||
|
||||
assert_bool(_node("SoundtracksAddedSeparator").visible).is_true()
|
||||
assert_bool(_node("SoundtracksRemovedSeparator").visible).is_false()
|
||||
|
||||
|
||||
func test_changed_titles_list_old_and_new_title() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
var result: Dictionary = _empty_result()
|
||||
result.soundtracks_changed_title = {"FF7": "Final Fantasy VII"}
|
||||
|
||||
_finish_sync(result)
|
||||
|
||||
var vbox: Control = _node("SoundtracksChangedTitleVBox")
|
||||
assert_bool(vbox.visible).is_true()
|
||||
assert_str((vbox.get_child(1) as Label).text).is_equal(
|
||||
"FF7\nchanged title to\nFinal Fantasy VII")
|
||||
|
||||
|
||||
func test_no_changes_shows_no_changes_label() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
|
||||
_finish_sync(_empty_result())
|
||||
|
||||
assert_bool(_node("NoChangesLabel").visible).is_true()
|
||||
|
||||
|
||||
func test_errors_are_listed() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
var result: Dictionary = _empty_result()
|
||||
result.catched_errors = ["Could not read tags in broken.mp3"]
|
||||
|
||||
_finish_sync(result)
|
||||
|
||||
assert_bool(_node("CatchedErrorsVBox").visible).is_true()
|
||||
|
||||
|
||||
func test_reopening_after_sync_shows_result_without_syncing_again() -> void:
|
||||
_runner.invoke("start_sync")
|
||||
_finish_sync(_empty_result())
|
||||
|
||||
_runner.invoke("start_sync")
|
||||
|
||||
assert_int(_server.count("/sync")).is_equal(1)
|
||||
assert_str(_node("SyncTitleLabel").text).is_equal("Sync Result")
|
||||
Reference in new issue
Block a user