' in l][0]
+
+ # Count leading spaces
+ p_indent = len(p_line) - len(p_line.lstrip())
+ div_indent = len(div_line) - len(div_line.lstrip())
+
+ assert p_indent > div_indent
+
+ def test_print_dom_tree_max_depth(self):
+ """Test that max_depth limits tree traversal."""
+ html = "
"
+ doc = parse_html(html)
+
+ tree_shallow = print_dom_tree(doc, max_depth=2)
+ tree_deep = print_dom_tree(doc, max_depth=10)
+
+ # Shallow should be shorter
+ assert len(tree_shallow) < len(tree_deep)
+ assert "..." in tree_shallow
+
+ def test_generate_dot_graph_text_escaping(self):
+ """Test that special characters in text are escaped."""
+ html = '
Text with "quotes" and newlines\n
'
+ doc = parse_html(html)
+
+ dot = generate_dot_graph(doc)
+
+ # Should have escaped quotes
+ assert '\\"' in dot or 'quotes' in dot
+ # Should not have raw newlines breaking the DOT format
+ lines = dot.split('\n')
+ # All lines should be valid (no line starts with unexpected characters)
+ for line in lines:
+ if line.strip():
+ assert not line.strip().startswith('"') or line.strip().endswith(';') or line.strip().endswith(']')
+
+ def test_generate_dot_graph_long_text_truncation(self):
+ """Test that very long text nodes are truncated."""
+ long_text = "A" * 100
+ html = f"
{long_text}
"
+ doc = parse_html(html)
+
+ dot = generate_dot_graph(doc)
+
+ # Should contain truncation marker
+ assert "..." in dot
diff --git a/tests/test_dom_graph_page.py b/tests/test_dom_graph_page.py
new file mode 100644
index 0000000..6bfa931
--- /dev/null
+++ b/tests/test_dom_graph_page.py
@@ -0,0 +1,67 @@
+"""Tests for DOM graph page rendering."""
+
+import pytest
+from src.templates import render_dom_graph_page
+from pathlib import Path
+import tempfile
+import os
+
+
+class TestDOMGraphPage:
+ def test_render_dom_graph_page_svg(self):
+ """Test rendering page with SVG graph."""
+ # Create temporary SVG file
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.svg', delete=False) as f:
+ f.write('
')
+ temp_path = f.name
+
+ try:
+ html = render_dom_graph_page(temp_path)
+
+ assert html
+ assert "DOM" in html
+ assert "Visualization" in html or "Graph" in html
+ assert '