59 lines
2.2 KiB
Rust
59 lines
2.2 KiB
Rust
#[test]
|
|
fn runtime_posts_urlencoded_forms_by_default() {
|
|
let source = slhx_js::RUNTIME_JS;
|
|
|
|
assert!(source.contains("new URLSearchParams()"));
|
|
assert!(source.contains("multipart/form-data"));
|
|
assert!(source.contains("const body = method === \"GET\" || method === \"HEAD\" ? undefined : requestBody(data, multipart)"));
|
|
assert!(source.contains("application/x-www-form-urlencoded;charset=UTF-8"));
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_handles_get_forms_without_request_body() {
|
|
let source = slhx_js::RUNTIME_JS;
|
|
|
|
assert!(source.contains("function requestUrl(form, data, method)"));
|
|
assert!(source.contains("method === \"GET\" || method === \"HEAD\" ? undefined : requestBody"));
|
|
assert!(source.contains("if (method === \"GET\") url.search = urlEncoded(data).toString()"));
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_supports_queued_request_policy() {
|
|
let source = slhx_js::RUNTIME_JS;
|
|
|
|
assert!(source.contains("const queues = new WeakMap()"));
|
|
assert!(source.contains("policy === \"queue\""));
|
|
assert!(source.contains("const base = queues.get(target) || active.done"));
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_exposes_page_swap_hooks() {
|
|
let source = slhx_js::RUNTIME_JS;
|
|
|
|
assert!(source.contains("data-slhx-nav"));
|
|
assert!(source.contains("data-slhx-boost"));
|
|
assert!(source.contains("history.pushState"));
|
|
assert!(source.contains("popstate"));
|
|
assert!(source.contains("x-slhx-title"));
|
|
assert!(source.contains("x-slhx-fingerprint"));
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_keeps_form_field_targets_separate_from_error_targets() {
|
|
let source = slhx_js::RUNTIME_JS;
|
|
|
|
assert!(source.contains("function fieldTarget(scope, id, field)"));
|
|
assert!(source.contains("[data-fid=\"${id}\"] [name=\"${escapedField}\"]"));
|
|
assert!(source.contains("function formErrorTarget(scope, id, field)"));
|
|
assert!(source.contains("[data-slhx-error-for=\"${escapedField}\"]"));
|
|
}
|
|
|
|
#[test]
|
|
fn runtime_preflights_batches_before_applying_ops() {
|
|
let source = slhx_js::RUNTIME_JS;
|
|
|
|
assert!(source.contains("const missingTarget = batch.ops.map((op) => canApplyOp(scope, op)).find(Boolean)"));
|
|
assert!(source.contains("function canApplyOp(scope, op)"));
|
|
assert!(source.contains("for (const op of batch.ops) applyOp(scope, op)"));
|
|
}
|