55 lines
2.3 KiB
Python
55 lines
2.3 KiB
Python
"""Contratos de conexion de la visibilidad de UI; no sustituyen al motor."""
|
|
|
|
from pathlib import Path
|
|
import re
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
UI_SCENES = {
|
|
"ui/hud/player_health_hud.tscn": ".",
|
|
"ui/hud/special_charge_hud.tscn": ".",
|
|
"ui/mobile_controls/mobile_controls.tscn": ".",
|
|
"levels/level_01.tscn": "TestHUD",
|
|
"levels/level_02.tscn": "LevelHUD",
|
|
}
|
|
|
|
|
|
class EditorUIResourceTests(unittest.TestCase):
|
|
def test_each_existing_overlay_has_a_visibility_component(self):
|
|
for relative, parent in UI_SCENES.items():
|
|
with self.subTest(scene=relative):
|
|
text = (ROOT / relative).read_text(encoding="utf-8")
|
|
self.assertIn('path="res://ui/editor_ui_visibility.gd"', text)
|
|
self.assertIn(
|
|
f'[node name="EditorVisibility" type="Node" parent="{parent}"]\n'
|
|
'script = ExtResource("editor_ui_visibility")', text,
|
|
)
|
|
|
|
def test_gameplay_ui_scripts_do_not_run_inside_the_editor(self):
|
|
for relative in (
|
|
"ui/hud/player_health_hud.gd",
|
|
"ui/hud/special_charge_hud.gd",
|
|
"ui/mobile_controls/mobile_controls.gd",
|
|
"player/player.gd",
|
|
):
|
|
with self.subTest(script=relative):
|
|
self.assertNotIn("@tool", (ROOT / relative).read_text(encoding="utf-8"))
|
|
|
|
def test_component_is_editor_aware_and_does_not_move_ui(self):
|
|
text = (ROOT / "ui/editor_ui_visibility.gd").read_text(encoding="utf-8")
|
|
self.assertTrue(text.startswith("@tool\n"))
|
|
self.assertIn("func _ready() -> void:\n\tset_process(Engine.is_editor_hint())", text)
|
|
self.assertIn("edited_scene_root == canvas_layer", text)
|
|
self.assertIn("@export var preview_in_editor: bool = false", text)
|
|
for property_name in ("position", "offset", "scale", "rotation", "layer"):
|
|
self.assertNotRegex(text, rf"canvas_layer\.{property_name}\s*=")
|
|
|
|
def test_component_does_not_modify_child_visibility(self):
|
|
text = (ROOT / "ui/editor_ui_visibility.gd").read_text(encoding="utf-8")
|
|
self.assertEqual(re.findall(r"^\s*(\w+)\.visible\s*=", text, re.MULTILINE), ["canvas_layer"])
|
|
self.assertNotIn("get_children()", text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|