Add post-answer review and per-question loading
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
extends SceneTree
|
||||
|
||||
var failures := 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
_test_reference_normalization()
|
||||
_test_reference_url_filter()
|
||||
_test_correct_feedback_does_not_auto_advance()
|
||||
quit(1 if failures > 0 else 0)
|
||||
|
||||
|
||||
func _test_reference_normalization() -> void:
|
||||
var service = load("res://scripts/autoload/question_bank_service.gd").new()
|
||||
var references: Array = service._normalize_references([{
|
||||
"Title": "Clinical guideline",
|
||||
"Publisher": "Example Society",
|
||||
"Url": "https://example.org/guideline",
|
||||
"Supports": "Recommended management",
|
||||
"AccessedOn": "2026-07-14",
|
||||
"Reviewer": "reviewer"
|
||||
}])
|
||||
_assert(references.size() == 1, "a structured reference should be retained")
|
||||
_assert(references[0].get("title", "") == "Clinical guideline", "reference title should be normalized")
|
||||
_assert(references[0].get("accessed_on", "") == "2026-07-14", "reference access date should be normalized")
|
||||
service.free()
|
||||
|
||||
|
||||
func _test_reference_url_filter() -> void:
|
||||
var player = load("res://scripts/ui/question_player.gd").new()
|
||||
_assert(player._is_safe_reference_url("https://example.org/source"), "HTTPS references should be accepted")
|
||||
_assert(not player._is_safe_reference_url("http://example.org/source"), "HTTP references should be rejected")
|
||||
_assert(not player._is_safe_reference_url("javascript:alert(1)"), "script URLs should be rejected")
|
||||
player.references_container = VBoxContainer.new()
|
||||
player._show_references([
|
||||
{"title": "Clinical guideline", "publisher": "Example Society", "url": "https://example.org/source"},
|
||||
{"title": "Unsafe", "publisher": "Example", "url": "http://example.org/source"}
|
||||
])
|
||||
_assert(player.references_container.visible, "valid references should show the references section")
|
||||
_assert(player.references_container.get_child_count() == 2, "the section should contain a heading and one safe link")
|
||||
var link := player.references_container.get_child(1) as LinkButton
|
||||
_assert(link != null and link.text == "Clinical guideline - Example Society", "reference link text should identify its source")
|
||||
player.references_container.free()
|
||||
player.free()
|
||||
|
||||
|
||||
func _test_correct_feedback_does_not_auto_advance() -> void:
|
||||
var player = load("res://scripts/ui/question_player.gd").new()
|
||||
player.next_button = Button.new()
|
||||
player.skip_button = Button.new()
|
||||
player.feedback_fog = ColorRect.new()
|
||||
player.pending_correct_advance = false
|
||||
player._trigger_correct_feedback()
|
||||
_assert(not player.pending_correct_advance, "correct feedback must not schedule automatic advancement")
|
||||
player.next_button.free()
|
||||
player.skip_button.free()
|
||||
player.feedback_fog.free()
|
||||
player.free()
|
||||
|
||||
|
||||
func _assert(condition: bool, message: String) -> void:
|
||||
if condition:
|
||||
return
|
||||
failures += 1
|
||||
push_error(message)
|
||||
Reference in New Issue
Block a user