test: harden checked boundary coverage
Use DOM-aware rendered-text inspection for the v0 shell marker check and extend unkeyed h-for validation coverage from slots to handles. req: test/005 req: scope/001
This commit is contained in:
@@ -248,7 +248,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(document.select(&selector("script[src=\"/slhx.js\"]")).count(), 1);
|
assert_eq!(document.select(&selector("script[src=\"/slhx.js\"]")).count(), 1);
|
||||||
assert_eq!(document.select(&selector("main[data-slhx-root=\"docs\"]")).count(), 1);
|
assert_eq!(document.select(&selector("main[data-slhx-root=\"docs\"]")).count(), 1);
|
||||||
assert!(!html.contains("{+="));
|
assert!(
|
||||||
|
document.root_element().text().all(|text| !text.contains("{+=")),
|
||||||
|
"hemplate insertion markers must not leak into rendered text"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// req: html_safety/002 req: view/001 req: test/005
|
// req: html_safety/002 req: view/001 req: test/005
|
||||||
|
|||||||
+17
-7
@@ -1127,23 +1127,33 @@ fn main() {{
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_slhx_resources_inside_unkeyed_for() {
|
fn rejects_slhx_resources_inside_unkeyed_for() {
|
||||||
let base = test_dir("slhx-build-unkeyed-for-test");
|
// req: scope/001
|
||||||
|
for (case, template, resource) in [
|
||||||
|
(
|
||||||
|
"slot",
|
||||||
|
r#"<template h-for="todo in &self.todos"><li data-slhx-slot="todo_row">{+ todo.title +}</li></template>"#,
|
||||||
|
"data-slhx-slot=\"todo_row\"",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"handle",
|
||||||
|
r#"<template h-for="todo in &self.todos"><button data-slhx-handle="delete">Delete</button></template>"#,
|
||||||
|
"data-slhx-handle=\"delete\"",
|
||||||
|
),
|
||||||
|
] {
|
||||||
|
let base = test_dir(&format!("slhx-build-unkeyed-for-{case}-test"));
|
||||||
let templates = base.join("templates");
|
let templates = base.join("templates");
|
||||||
let out = base.join("out");
|
let out = base.join("out");
|
||||||
let _ = std::fs::remove_dir_all(&base);
|
let _ = std::fs::remove_dir_all(&base);
|
||||||
std::fs::create_dir_all(&templates).unwrap();
|
std::fs::create_dir_all(&templates).unwrap();
|
||||||
std::fs::write(
|
std::fs::write(templates.join("todo.heml"), template).unwrap();
|
||||||
templates.join("todo.heml"),
|
|
||||||
r#"<template h-for="todo in &self.todos"><li data-slhx-slot="todo_row">{+ todo.title +}</li></template>"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let err = app().template_dir(&templates).out_dir(&out).run().unwrap_err();
|
let err = app().template_dir(&templates).out_dir(&out).run().unwrap_err();
|
||||||
assert!(err.to_string().contains("inside an h-for without h-key"));
|
assert!(err.to_string().contains("inside an h-for without h-key"));
|
||||||
assert!(err.to_string().contains("data-slhx-slot=\"todo_row\""));
|
assert!(err.to_string().contains(resource));
|
||||||
|
|
||||||
let _ = std::fs::remove_dir_all(&base);
|
let _ = std::fs::remove_dir_all(&base);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generated_lowering_injects_progressive_form_handle_and_key() {
|
fn generated_lowering_injects_progressive_form_handle_and_key() {
|
||||||
|
|||||||
Reference in New Issue
Block a user