mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-05-26 19:50:15 +00:00
71cf06cd1c
- Loosen test_ime_composition._ime_guarded_enter_pattern to accept the new _isImeEnter(e) helper (PR #1441 widened guard for Safari + 229 keyCode + manual _imeComposing flag). Original e.isComposing-only pattern still matches via alternation. - Add test_pr1441_ime_safari_guard.py (6 tests): pin the 3-guard helper, compositionstart sets manual flag, compositionend defers reset to next tick (Safari race), null-guard $('msg') for non-chat pages, send-Enter uses helper, dropdown-Enter uses helper. - Add test_japanese_locale.py (8 tests): mirror Chinese/Korean templates, block exists, representative translations, full key parity with English, no extra keys, duplicates mirror en exactly, placeholders preserved, arrow-function values mirrored, _label uses Japanese script.
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
import pathlib
|
|
import re
|
|
|
|
|
|
REPO_ROOT = pathlib.Path(__file__).parent.parent.resolve()
|
|
BOOT_JS = (REPO_ROOT / "static" / "boot.js").read_text(encoding="utf-8")
|
|
UI_JS = (REPO_ROOT / "static" / "ui.js").read_text(encoding="utf-8")
|
|
SESSIONS_JS = (REPO_ROOT / "static" / "sessions.js").read_text(encoding="utf-8")
|
|
|
|
|
|
def _ime_guarded_enter_pattern(event_var_pattern, require_no_shift=False):
|
|
"""Accept both the original `e.isComposing` guard AND the broader
|
|
`_isImeEnter(e)` helper introduced in PR #1441 (which folds in
|
|
`keyCode===229` and a manual `_imeComposing` flag for Safari).
|
|
"""
|
|
no_shift = rf"\s*&&\s*!\s*{event_var_pattern}\.shiftKey" if require_no_shift else ""
|
|
# Either: if(e.isComposing) ... OR if(_isImeEnter(e)) ...
|
|
guard = (
|
|
rf"if\s*\(\s*"
|
|
rf"(?:{event_var_pattern}\.isComposing"
|
|
rf"|_isImeEnter\(\s*{event_var_pattern}\s*\))"
|
|
rf"\s*\)\s*"
|
|
)
|
|
return (
|
|
rf"if\s*\(\s*{event_var_pattern}\.key\s*===\s*'Enter'{no_shift}\s*\)\s*\{{\s*"
|
|
+ guard +
|
|
rf"(?:\{{\s*return\s*;?\s*\}}|return\s*;?)"
|
|
)
|
|
|
|
|
|
def test_boot_chat_enter_send_respects_ime_composition():
|
|
assert re.search(
|
|
_ime_guarded_enter_pattern("e"),
|
|
BOOT_JS,
|
|
re.DOTALL,
|
|
), "Chat composer Enter handler must ignore IME composition Enter in static/boot.js"
|
|
assert re.search(
|
|
_ime_guarded_enter_pattern("e", require_no_shift=True),
|
|
BOOT_JS,
|
|
re.DOTALL,
|
|
), "Command dropdown Enter handler must ignore IME composition Enter in static/boot.js"
|
|
|
|
|
|
def test_ui_enter_submit_paths_respect_ime_composition():
|
|
assert re.search(
|
|
rf"document\.addEventListener\('keydown',e=>\{{[\s\S]*?{_ime_guarded_enter_pattern('e')}",
|
|
UI_JS,
|
|
re.DOTALL,
|
|
), \
|
|
"App dialog Enter handler must ignore IME composition Enter in static/ui.js"
|
|
assert re.search(
|
|
_ime_guarded_enter_pattern("e", require_no_shift=True),
|
|
UI_JS,
|
|
re.DOTALL,
|
|
), \
|
|
"Message edit Enter-to-save handler must ignore IME composition Enter in static/ui.js"
|
|
assert re.search(
|
|
rf"inp\.onkeydown=\(e2\)=>\{{\s*{_ime_guarded_enter_pattern('e2')}",
|
|
UI_JS,
|
|
re.DOTALL,
|
|
), \
|
|
"Workspace rename Enter handler must ignore IME composition Enter in static/ui.js"
|
|
|
|
|
|
def test_sessions_enter_submit_paths_respect_ime_composition():
|
|
matches = re.findall(
|
|
_ime_guarded_enter_pattern(r"e2?"),
|
|
SESSIONS_JS,
|
|
re.DOTALL,
|
|
)
|
|
assert len(matches) >= 3, \
|
|
"Session and project rename/create Enter handlers must ignore IME composition Enter in static/sessions.js"
|