test: loosen IME guard regression assertions
This commit is contained in:
@@ -8,36 +8,54 @@ UI_JS = (REPO_ROOT / "static" / "ui.js").read_text(encoding="utf-8")
|
|||||||
SESSIONS_JS = (REPO_ROOT / "static" / "sessions.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):
|
||||||
|
no_shift = rf"\s*&&\s*!\s*{event_var_pattern}\.shiftKey" if require_no_shift else ""
|
||||||
|
return (
|
||||||
|
rf"if\s*\(\s*{event_var_pattern}\.key\s*===\s*'Enter'{no_shift}\s*\)\s*\{{\s*"
|
||||||
|
rf"if\s*\(\s*{event_var_pattern}\.isComposing\s*\)\s*"
|
||||||
|
rf"(?:\{{\s*return\s*;?\s*\}}|return\s*;?)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_boot_chat_enter_send_respects_ime_composition():
|
def test_boot_chat_enter_send_respects_ime_composition():
|
||||||
assert re.search(
|
assert re.search(
|
||||||
r"if\(e\.key==='Enter'\)\{\s*if\(e\.isComposing\)\{return;\}",
|
_ime_guarded_enter_pattern("e"),
|
||||||
BOOT_JS,
|
BOOT_JS,
|
||||||
|
re.DOTALL,
|
||||||
), "Chat composer Enter handler must ignore IME composition Enter in static/boot.js"
|
), "Chat composer Enter handler must ignore IME composition Enter in static/boot.js"
|
||||||
assert re.search(
|
assert re.search(
|
||||||
r"if\(e\.key==='Enter'&&!e\.shiftKey\)\{\s*if\(e\.isComposing\)\{return;\}",
|
_ime_guarded_enter_pattern("e", require_no_shift=True),
|
||||||
BOOT_JS,
|
BOOT_JS,
|
||||||
|
re.DOTALL,
|
||||||
), "Command dropdown Enter handler must ignore IME composition Enter in static/boot.js"
|
), "Command dropdown Enter handler must ignore IME composition Enter in static/boot.js"
|
||||||
|
|
||||||
|
|
||||||
def test_ui_enter_submit_paths_respect_ime_composition():
|
def test_ui_enter_submit_paths_respect_ime_composition():
|
||||||
assert re.search(
|
assert re.search(
|
||||||
r"document\.addEventListener\('keydown',e=>\{[\s\S]*?if\(e\.key==='Enter'\)\{\s*if\(e\.isComposing\) return;",
|
rf"document\.addEventListener\('keydown',e=>\{{[\s\S]*?{_ime_guarded_enter_pattern('e')}",
|
||||||
UI_JS,
|
UI_JS,
|
||||||
|
re.DOTALL,
|
||||||
), \
|
), \
|
||||||
"App dialog Enter handler must ignore IME composition Enter in static/ui.js"
|
"App dialog Enter handler must ignore IME composition Enter in static/ui.js"
|
||||||
assert "if(e.key==='Enter' && !e.shiftKey) { if(e.isComposing) return; e.preventDefault();" in 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"
|
"Message edit Enter-to-save handler must ignore IME composition Enter in static/ui.js"
|
||||||
assert re.search(
|
assert re.search(
|
||||||
r"inp\.onkeydown=\(e2\)=>\{\s*if\(e2\.key==='Enter'\)\{\s*if\(e2\.isComposing\)\{return;\}",
|
rf"inp\.onkeydown=\(e2\)=>\{{\s*{_ime_guarded_enter_pattern('e2')}",
|
||||||
UI_JS,
|
UI_JS,
|
||||||
|
re.DOTALL,
|
||||||
), \
|
), \
|
||||||
"Workspace rename Enter handler must ignore IME composition Enter in static/ui.js"
|
"Workspace rename Enter handler must ignore IME composition Enter in static/ui.js"
|
||||||
|
|
||||||
|
|
||||||
def test_sessions_enter_submit_paths_respect_ime_composition():
|
def test_sessions_enter_submit_paths_respect_ime_composition():
|
||||||
matches = re.findall(
|
matches = re.findall(
|
||||||
r"if\(e2?\.key==='Enter'\)\{\s*if\(e2?\.isComposing\)\{return;\}",
|
_ime_guarded_enter_pattern(r"e2?"),
|
||||||
SESSIONS_JS,
|
SESSIONS_JS,
|
||||||
|
re.DOTALL,
|
||||||
)
|
)
|
||||||
assert len(matches) >= 3, \
|
assert len(matches) >= 3, \
|
||||||
"Session and project rename/create Enter handlers must ignore IME composition Enter in static/sessions.js"
|
"Session and project rename/create Enter handlers must ignore IME composition Enter in static/sessions.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user