"""Tests for studycraft.export.""" from pathlib import Path from studycraft.export import _build_css, _build_epub_css, _extract_toc, export_all from studycraft.themes import DARK _SAMPLE_MD = """\ # 📖 Practice Guide — Test Subject ## Chapter 1: Basics Some content here. | Term | Definition | |------|-----------| | Foo | A test term | ```python x = 42 ``` """ def test_export_creates_all_formats(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide") for fmt in ("md", "html", "docx", "epub"): assert fmt in paths, f"Missing format: {fmt}" assert paths[fmt].exists(), f"{fmt} file not created" assert paths[fmt].stat().st_size > 0, f"{fmt} file is empty" def test_md_has_toc_prepended(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide") content = paths["md"].read_text(encoding="utf-8") assert content.startswith("## Table of Contents") assert "x = 42" in content def test_html_has_syntax_highlighting(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide") html = paths["html"].read_text(encoding="utf-8") # codehilite wraps code blocks in a div with class="codehilite" assert "codehilite" in html # Pygments tokenizes Python: 'x' -> .n, '=' -> .o, '42' -> .mi assert '42' in html or 'class="mi"' in html def test_html_has_copy_button(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide") html = paths["html"].read_text(encoding="utf-8") assert "copy-btn" in html assert "navigator.clipboard.writeText" in html assert "Copied!" in html def test_html_has_toc_sidebar(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide") html = paths["html"].read_text(encoding="utf-8") assert "toc-sidebar" in html assert "Contents" in html def test_html_has_themed_css(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide", theme="dracula") html = paths["html"].read_text(encoding="utf-8") # Dracula bg color should appear in CSS assert "#282a36" in html # Dracula keyword color assert "#ff79c6" in html def test_html_structure(tmp_path: Path): paths = export_all(_SAMPLE_MD, tmp_path, base_name="Test_Guide") html = paths["html"].read_text(encoding="utf-8") assert "" in html assert "