Preserve native interaction semantics
This commit is contained in:
@@ -75,6 +75,20 @@ fn runtime_preserves_multipart_file_upload_fallback_shape() {
|
||||
assert!(source.contains("if (body instanceof URLSearchParams) headers[\"Content-Type\"] = \"application/x-www-form-urlencoded;charset=UTF-8\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_preserves_native_form_controls_and_validation() {
|
||||
let source = hemx_js::RUNTIME_JS;
|
||||
|
||||
assert!(source.contains("if (form.reportValidity && !form.reportValidity()) return;"));
|
||||
assert!(source.contains(
|
||||
"return source && source !== form ? new FormData(form, source) : new FormData(form);"
|
||||
));
|
||||
assert!(source.contains("event.submitter || node"));
|
||||
assert!(source.contains("multipart/form-data"));
|
||||
assert!(!source.contains("compositionstart"));
|
||||
assert!(!source.contains("compositionend"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_uses_root_scoped_walks_not_dom_selector_apis() {
|
||||
let source = hemx_js::RUNTIME_JS;
|
||||
@@ -98,7 +112,7 @@ fn runtime_targets_generated_resources_not_response_selectors() {
|
||||
assert!(source.contains("return generatedTarget(scope, ref.resource.id)"));
|
||||
assert!(source.contains("function firstElement(scope, predicate)"));
|
||||
assert!(source.contains("function generatedResource(el, id)"));
|
||||
assert!(source.contains("return firstElement(scope, (el) => attrEquals(el, \"data-key\", key) && withinGeneratedResource(el, scope, id))"));
|
||||
assert!(source.contains("return firstElement(scope, (el) => attrEquals(el, \"data-hemx-key\", key) && withinGeneratedResource(el, scope, id))"));
|
||||
assert!(source.contains("if (node.hasAttribute && node.hasAttribute(ROOT)) continue"));
|
||||
assert!(source.contains("if (!applyOp(scope, op)) return"));
|
||||
assert!(!source.contains("canApplyOp"));
|
||||
@@ -129,11 +143,10 @@ fn runtime_interval_dispatch_avoids_duplicate_timers() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_supports_tiny_delay_and_revealed_scheduling() {
|
||||
fn runtime_supports_revealed_scheduling() {
|
||||
let source = hemx_js::RUNTIME_JS;
|
||||
|
||||
assert!(source.contains("data-hemx-delay"));
|
||||
assert!(source.contains("setTimeout(() => send(el, eventName, source), delay)"));
|
||||
assert!(!source.contains("data-hemx-delay"));
|
||||
assert!(source.contains("const revealObservers = new WeakMap()"));
|
||||
assert!(source.contains("const revealed = new WeakSet()"));
|
||||
assert!(source.contains("data-hemx-revealed"));
|
||||
@@ -238,7 +251,7 @@ fn runtime_clicking_submitter_schedules_form_submit() {
|
||||
);
|
||||
assert!(!source.contains("document.getElementById(el.getAttribute(\"form\"))"));
|
||||
assert!(source.contains(
|
||||
"const direct = closestInRoot(event.target, root, (el) => el.hasAttribute(HID))"
|
||||
"const direct = closestInRoot(event.target, root, (el) => el.hasAttribute(ACTION))"
|
||||
));
|
||||
assert!(source.contains("const submitter = closestInRoot(event.target, root, (el) =>"));
|
||||
assert!(source.contains("el.tagName === \"BUTTON\" && (!el.hasAttribute(\"type\") || el.getAttribute(\"type\") === \"submit\")"));
|
||||
@@ -309,6 +322,7 @@ fn runtime_exposes_page_swap_hooks() {
|
||||
assert!(source.contains("x-hemx-fingerprint"));
|
||||
assert!(source.contains("hemx:missing-content-slot"));
|
||||
assert!(source.contains("else location.href = href"));
|
||||
assert!(source.contains("if (!response.ok || !await applyResponse(response, root))"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -317,6 +331,7 @@ fn runtime_popstate_failed_partials_reload_instead_of_stale_ui() {
|
||||
|
||||
assert!(source.contains("if (mode === \"none\") location.reload();"));
|
||||
assert!(source.contains("if (root) navigateUrl(location.href, root, \"none\")"));
|
||||
assert!(source.contains("catch (_) {\n fallbackNavigation(href, mode);"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -338,7 +353,7 @@ fn runtime_refuses_partial_updates_on_fingerprint_mismatch() {
|
||||
|
||||
assert!(source.contains("function compatibleFingerprint(response, root)"));
|
||||
assert!(source.contains("const received = response.headers.get(\"x-hemx-fingerprint\")"));
|
||||
assert!(source.contains("const expected = root && root.getAttribute(FINGERPRINT)"));
|
||||
assert!(source.contains("const expected = root && root.getAttribute(BUILD)"));
|
||||
assert!(source.contains("if (!compatibleFingerprint(response, root))"));
|
||||
assert!(source.contains("location.reload()"));
|
||||
assert!(source.contains("if (expected && String(batch.fingerprint) !== expected)"));
|
||||
|
||||
Reference in New Issue
Block a user