Improve question review and image handling
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
extends SceneTree
|
||||
|
||||
var failures := 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
_test_loaded_media_navigation()
|
||||
_test_zoom_limits()
|
||||
_test_image_question_detection()
|
||||
quit(1 if failures > 0 else 0)
|
||||
|
||||
|
||||
func _test_loaded_media_navigation() -> void:
|
||||
var player = load("res://scripts/ui/question_player.gd").new()
|
||||
player.question_media_items = [
|
||||
{"loaded": true},
|
||||
{"loaded": false},
|
||||
{"loaded": true}
|
||||
]
|
||||
_assert(player._find_loaded_media_index(0, 1) == 2, "navigation should skip images that have not loaded")
|
||||
_assert(player._find_loaded_media_index(2, -1) == 0, "back navigation should preserve source order")
|
||||
_assert(player._find_loaded_media_index(2, 1) == -1, "navigation should stop at the final image")
|
||||
player.free()
|
||||
|
||||
|
||||
func _test_zoom_limits() -> void:
|
||||
var player = load("res://scripts/ui/question_player.gd").new()
|
||||
player.media_viewer_scroll = ScrollContainer.new()
|
||||
player.media_viewer_scroll.size = Vector2(800, 600)
|
||||
player.media_viewer_center = CenterContainer.new()
|
||||
player.media_viewer_texture = TextureRect.new()
|
||||
player.media_viewer_zoom_label = Label.new()
|
||||
var image := Image.create(100, 50, false, Image.FORMAT_RGBA8)
|
||||
player.media_viewer_texture.texture = ImageTexture.create_from_image(image)
|
||||
player._set_media_viewer_zoom(20.0)
|
||||
_assert(is_equal_approx(player.media_viewer_zoom, 4.0), "zoom should be capped at 400 percent")
|
||||
player._set_media_viewer_zoom(0.01)
|
||||
_assert(is_equal_approx(player.media_viewer_zoom, 0.25), "zoom should be capped at 25 percent")
|
||||
player.media_viewer_scroll.free()
|
||||
player.media_viewer_center.free()
|
||||
player.media_viewer_texture.free()
|
||||
player.media_viewer_zoom_label.free()
|
||||
player.free()
|
||||
|
||||
|
||||
func _test_image_question_detection() -> void:
|
||||
var service = load("res://scripts/autoload/question_bank_service.gd").new()
|
||||
_assert(not service._contains_question_with_media([{"id": "plain", "media": []}]), "plain questions should not satisfy an image-only request")
|
||||
_assert(service._contains_question_with_media([{"id": "image", "media": ["/media/example"]}]), "questions with media should satisfy an image-only request")
|
||||
service.free()
|
||||
|
||||
|
||||
func _assert(condition: bool, message: String) -> void:
|
||||
if condition:
|
||||
return
|
||||
failures += 1
|
||||
push_error(message)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b34pl1b02ehr6
|
||||
@@ -7,6 +7,7 @@ func _initialize() -> void:
|
||||
_test_reference_normalization()
|
||||
_test_reference_url_filter()
|
||||
_test_correct_feedback_does_not_auto_advance()
|
||||
_test_correct_review_locks_answer_interactions()
|
||||
quit(1 if failures > 0 else 0)
|
||||
|
||||
|
||||
@@ -58,6 +59,21 @@ func _test_correct_feedback_does_not_auto_advance() -> void:
|
||||
player.free()
|
||||
|
||||
|
||||
func _test_correct_review_locks_answer_interactions() -> void:
|
||||
var player = load("res://scripts/ui/question_player.gd").new()
|
||||
player.current_answer = {"is_correct": true}
|
||||
player.selected_choice = "A"
|
||||
player.presented_choices = [{"id": "A", "text": "First"}, {"id": "B", "text": "Second"}]
|
||||
player._select_choice(1)
|
||||
_assert(player.selected_choice == "A", "correct review should reject answer selection changes")
|
||||
var right_click := InputEventMouseButton.new()
|
||||
right_click.button_index = MOUSE_BUTTON_RIGHT
|
||||
right_click.pressed = true
|
||||
player._choice_gui_input(right_click, 1)
|
||||
_assert(player.eliminated.is_empty(), "correct review should reject answer strike-through changes")
|
||||
player.free()
|
||||
|
||||
|
||||
func _assert(condition: bool, message: String) -> void:
|
||||
if condition:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user