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("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
|
||||
|
||||
+24
-14
@@ -1127,22 +1127,32 @@ fn main() {{
|
||||
|
||||
#[test]
|
||||
fn rejects_slhx_resources_inside_unkeyed_for() {
|
||||
let base = test_dir("slhx-build-unkeyed-for-test");
|
||||
let templates = base.join("templates");
|
||||
let out = base.join("out");
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
std::fs::create_dir_all(&templates).unwrap();
|
||||
std::fs::write(
|
||||
templates.join("todo.heml"),
|
||||
r#"<template h-for="todo in &self.todos"><li data-slhx-slot="todo_row">{+ todo.title +}</li></template>"#,
|
||||
)
|
||||
.unwrap();
|
||||
// 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 out = base.join("out");
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
std::fs::create_dir_all(&templates).unwrap();
|
||||
std::fs::write(templates.join("todo.heml"), template).unwrap();
|
||||
|
||||
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("data-slhx-slot=\"todo_row\""));
|
||||
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(resource));
|
||||
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user