"""Smoke + regression tests for composing-html.
Run with: python -m pytest composing-html/tests -q
or python composing-html/tests/test_smoke.py (no pytest needed)
Covers every template builder with a representative spec, then asserts each
output:
- starts with ``
- parses cleanly with html.parser
- contains the expected content marker
- does NOT contain raw `
"
def test_table_does_not_emit_raw_script():
out = table(["x"], [[INJECT]])
assert "
after",
"variables": [{"name": "x", "default": ""}],
})
# Inside the inlined JS string literal, must be escaped to <\/.
# The plain literal `` must not appear except as the closing tag
# of the actual ")
assert closing_tags == 1, (
f"expected exactly one (the real closer); found {closing_tags}"
)
def test_flag_editor_escapes_id_in_attrs():
out = _build("editor.flag_editor", {
"title": "f",
"flags": [{"id": 'a"b', "label": "L", "default": True,
"requires": ['x"y']}],
})
# The injected " must be HTML-escaped inside both the data-id and
# data-requires attributes; the surrounding attribute uses double quotes.
assert 'data-id="a"b"' in out
assert """ in out # JSON " inside data-requires is escaped
def test_flag_editor_handles_missing_id():
out = _build("editor.flag_editor", {
"title": "f",
"flags": [{"label": "no-id", "default": False}],
})
assert "