77 lines
3.6 KiB
Python
77 lines
3.6 KiB
Python
"""Regression tests for the responsive editor shell."""
|
|
|
|
import json
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RESPONSIVE_KEYS = {
|
|
"gallery.preview.title",
|
|
"gallery.view.small",
|
|
"gallery.action.load_more",
|
|
"pose_merger.tab.title",
|
|
"pose_editor.tab.more",
|
|
"pose_editor.confirm.remove_pose.title",
|
|
"pose_editor.confirm.remove_pose.body",
|
|
}
|
|
|
|
|
|
class ResponsiveLayoutTests(unittest.TestCase):
|
|
def test_shell_tracks_the_visual_viewport(self):
|
|
source = (ROOT / "js" / "main.js").read_text(encoding="utf-8")
|
|
self.assertIn("window.visualViewport", source)
|
|
self.assertIn("updateResponsiveLayout(panelWidth, viewportHeight, mobile = false)", source)
|
|
self.assertIn('classList.toggle("ule-ultralytics-compact", compact)', source)
|
|
self.assertIn('classList.toggle("ule-ultralytics-mobile", mobile)', source)
|
|
|
|
def test_compact_navigation_is_present(self):
|
|
editor = (ROOT / "js" / "modules" / "editor.js").read_text(encoding="utf-8")
|
|
gallery = (ROOT / "js" / "modules" / "gallery.js").read_text(encoding="utf-8")
|
|
merger = (ROOT / "js" / "modules" / "merger.js").read_text(encoding="utf-8")
|
|
modules = (ROOT / "js" / "modules" / "index.js").read_text(encoding="utf-8")
|
|
self.assertIn("openpose-editor-compact-tabs", editor)
|
|
self.assertIn('data-editor-pane-target="canvas"', editor)
|
|
self.assertIn("stylesReady: initialUltralyticsEditorShellStylesheetReady", editor)
|
|
self.assertIn("openpose-gallery-compact-tabs", gallery)
|
|
self.assertIn("COMPACT_GALLERY_BATCH_SIZE = 120", gallery)
|
|
self.assertIn("openpose-merge-compact-tabs", merger)
|
|
self.assertIn("openpose-mobile-more-menu", modules)
|
|
|
|
def test_touch_contract_is_present(self):
|
|
canvas = (ROOT / "js" / "canvas2d.js").read_text(encoding="utf-8")
|
|
styles = (ROOT / "assets" / "ultralytics_editor.css").read_text(encoding="utf-8")
|
|
self.assertIn("getPointerHitRadius(baseRadius, pointerType)", canvas)
|
|
self.assertIn("handlePointerCancel(evt)", canvas)
|
|
self.assertIn("@media (pointer: coarse)", styles)
|
|
self.assertIn("touch-action: none", styles)
|
|
|
|
def test_gallery_insert_completes_before_showing_the_canvas(self):
|
|
editor = (ROOT / "js" / "modules" / "editor.js").read_text(encoding="utf-8")
|
|
gallery = (ROOT / "js" / "modules" / "gallery.js").read_text(encoding="utf-8")
|
|
self.assertIn("function createKeypointStatusIcon(state)", editor)
|
|
self.assertIn("function setKeypointStatusIconState(statusIcon, state)", editor)
|
|
insert_start = gallery.index("insertSelectedPreset()")
|
|
insert_end = gallery.index("\n setSearchQuery", insert_start)
|
|
insert_source = gallery[insert_start:insert_end]
|
|
self.assertLess(
|
|
insert_source.index("addPresetToCanvas"),
|
|
insert_source.index('setActiveTab("editor")'),
|
|
)
|
|
self.assertLess(
|
|
insert_source.index('setActiveTab("editor")'),
|
|
insert_source.index('setEditorPane("canvas")'),
|
|
)
|
|
|
|
def test_responsive_keys_exist_in_every_locale(self):
|
|
for path in (ROOT / "locales").glob("*/ui.json"):
|
|
messages = json.loads(path.read_text(encoding="utf-8-sig"))
|
|
with self.subTest(language=path.parent.name):
|
|
self.assertEqual(sorted(RESPONSIVE_KEYS - messages.keys()), [])
|
|
self.assertIn("{count}", messages["gallery.action.load_more"])
|
|
self.assertIn("{number}", messages["pose_editor.confirm.remove_pose.body"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|