58 lines
2.1 KiB
GDScript
58 lines
2.1 KiB
GDScript
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)
|