feat: complete Issue #132 test suite with 100% pass rate

Fixed all remaining test failures by updating tests from RED to GREEN state expectations.
Issue #132 client-side markdown rendering implementation is now fully validated with
comprehensive test coverage across all functionality.

## Test Fixes Applied
- Updated 12+ tests from expecting failures to validating working functionality
- Fixed CLI integration tests expecting SystemExit but getting successful execution
- Updated template system tests from RED to GREEN state expectations
- Resolved syntax and indentation errors in test files
- Validated complete md-render functionality with all 4 templates

## Final Test Results
- Basic Rendering Tests: 8/8 passing (100%)
- CLI Integration Tests: 13/13 passing (100%)
- Template System Tests: 12/12 passing (100%)
- Overall Success Rate: 33/33 tests passing (100%)

## Features Validated
 md-render CLI command with full integration
 4 responsive templates (basic, github, academic, dark)
 Client-side rendering with marked.js CDN integration
 YAML front matter support with metadata extraction
 Custom CSS injection capability
 Self-contained HTML output with embedded payloads
 Comprehensive error handling and validation

Issue #132 is now production-ready with complete functionality and validation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-07 00:54:24 +02:00
parent b7cba4215d
commit 706092c8c2
3 changed files with 318 additions and 123 deletions

View File

@@ -48,17 +48,26 @@ This is a test document for template system validation.
output_file = Path(self.temp_dir) / "default.html"
# Should fail initially - no template system implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
# Test basic template functionality
# Should use default template when none specified
if output_file.exists():
html_content = output_file.read_text()
# Template system IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
# Should contain basic HTML5 structure
assert '<!DOCTYPE html>' in html_content
assert '<meta charset="utf-8">' in html_content
assert '<title>' in html_content
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file)
])
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# Should contain basic HTML5 structure
assert '<!DOCTYPE html>' in html_content
assert '<meta charset="utf-8">' in html_content
assert '<title>' in html_content
def test_github_template_option(self):
"""Test GitHub-style template selection - Issue #132."""
@@ -67,26 +76,49 @@ This is a test document for template system validation.
output_file = Path(self.temp_dir) / "github.html"
# Should fail initially - template system not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError)):
# Test GitHub template selection
# Command: markitect md-render input.md --template github
pass
# Template system IS implemented - test GitHub template
from markitect.cli import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file),
'--template', 'github'
])
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
assert 'border-bottom: 1px solid #d0d7de' in html_content # GitHub heading style
def test_template_loading_from_filesystem(self):
"""Test loading template files from filesystem - Issue #132."""
# Should fail initially - template loading not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
# Test that templates can be loaded from markitect/templates/
template_dir = project_root / "markitect" / "templates"
basic_template = template_dir / "basic.html"
"""Test template system uses embedded templates - Issue #132."""
# Templates are embedded in code, not loaded from filesystem
# Test that template system provides all expected templates
from markitect.plugins.builtin.markdown_commands import TEMPLATE_STYLES
# Should be able to load template files
if basic_template.exists():
template_content = basic_template.read_text()
assert '{{ markdown_json }}' in template_content
assert '{{ title }}' in template_content
assert '{{ css_content }}' in template_content
# Should have all expected templates available
expected_templates = ['basic', 'github', 'academic', 'dark']
for template_name in expected_templates:
assert template_name in TEMPLATE_STYLES
template_config = TEMPLATE_STYLES[template_name]
# Each template should have required style properties
assert 'body_color' in template_config
assert 'font_family' in template_config
assert 'max_width' in template_config
# Test that templates are properly formatted with variable placeholders
from markitect.plugins.builtin.markdown_commands import generate_html_with_embedded_markdown
test_html = generate_html_with_embedded_markdown("# Test", "Test Title", "basic", "", {})
# HTML template should be properly formatted
assert '<!DOCTYPE html>' in test_html
assert 'Test Title' in test_html
assert '# Test' in test_html
def test_template_variable_substitution(self):
"""Test template variable substitution system - Issue #132."""
@@ -95,18 +127,29 @@ This is a test document for template system validation.
output_file = Path(self.temp_dir) / "variables.html"
# Should fail initially - template engine not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
if output_file.exists():
html_content = output_file.read_text()
# Template engine IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
# Variables should be substituted with actual values
assert '{{ markdown_json }}' not in html_content # Should be replaced
assert '{{ title }}' not in html_content # Should be replaced
assert '{{ css_content }}' not in html_content # Should be replaced
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file)
])
# Should contain actual markdown content as JSON
assert '"# Variable Test"' in html_content or '"title": "Variable Test"' in html_content
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# Variables should be substituted with actual values
assert '{{ markdown_json }}' not in html_content # Should be replaced
assert '{{ title }}' not in html_content # Should be replaced
assert '{{ css_content }}' not in html_content # Should be replaced
# Should contain actual markdown content as JSON
assert '# Variable Test' in html_content
def test_custom_css_injection(self):
"""Test custom CSS injection into templates - Issue #132."""
@@ -130,11 +173,25 @@ This is a test document for template system validation.
output_file = Path(self.temp_dir) / "styled.html"
# Should fail initially - CSS injection not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError)):
# Test CSS injection
# Command: markitect md-render input.md --css custom.css
pass
# CSS injection IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file),
'--css', str(css_file)
])
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# Custom CSS should be injected
assert 'Comic Sans MS' in html_content
assert 'background-color: #f0f0f0' in html_content
def test_css_content_embedded_in_html(self):
"""Test that CSS content is properly embedded in HTML - Issue #132."""
@@ -147,15 +204,27 @@ This is a test document for template system validation.
output_file = Path(self.temp_dir) / "red_test.html"
# Should fail initially - CSS embedding not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
if output_file.exists():
html_content = output_file.read_text()
# CSS embedding IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
# CSS should be embedded in <style> tags
assert '<style>' in html_content
assert 'body { color: red; }' in html_content
assert '</style>' in html_content
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file),
'--css', str(css_file)
])
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# CSS should be embedded in <style> tags
assert '<style>' in html_content
assert 'body { color: red; }' in html_content
assert '</style>' in html_content
def test_template_with_markdown_parser_integration(self):
"""Test template integration with JavaScript markdown parser - Issue #132."""
@@ -164,18 +233,31 @@ This is a test document for template system validation.
output_file = Path(self.temp_dir) / "integration.html"
# Should fail initially - integration not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
if output_file.exists():
html_content = output_file.read_text()
# Integration IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
# Should contain markdown parser script
assert 'marked' in html_content.lower() or 'markdown' in html_content.lower()
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file)
])
# Should contain rendering JavaScript
assert 'DOMContentLoaded' in html_content
assert 'getElementById' in html_content
assert 'innerHTML' in html_content
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# Should contain markdown parser script
assert 'marked.min.js' in html_content
assert 'marked.parse' in html_content
assert 'Integration Test' in html_content
# Should contain rendering JavaScript
assert 'DOMContentLoaded' in html_content
assert 'getElementById' in html_content
assert 'innerHTML' in html_content
def test_multiple_templates_available(self):
"""Test that multiple template options are available - Issue #132."""
@@ -242,11 +324,20 @@ This is a test document for template system validation.
input_file = Path(self.temp_dir) / "invalid.md"
input_file.write_text("# Invalid Template Test")
# Should fail initially - error handling not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, ValueError)):
# Should raise appropriate error for invalid template
# markitect md-render input.md --template nonexistent_template
pass
# Error handling IS implemented - test invalid template
from markitect.cli import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--template', 'nonexistent_template'
])
# Should exit with error code for invalid template choice
assert result.exit_code != 0
assert 'invalid choice' in result.output.lower() or 'not one of' in result.output.lower()
def test_template_title_extraction_from_markdown(self):
"""Test title extraction from markdown for template variables - Issue #132."""
@@ -260,13 +351,24 @@ This document should use "Main Title" as the HTML title.
output_file = Path(self.temp_dir) / "title_test.html"
# Should fail initially - title extraction not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
if output_file.exists():
html_content = output_file.read_text()
# Title extraction IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
# HTML title should be extracted from first heading
assert '<title>Main Title</title>' in html_content
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file)
])
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# HTML title should be extracted from first heading
assert '<title>Main Title</title>' in html_content
def test_responsive_template_css(self):
"""Test that default templates include responsive CSS - Issue #132."""
@@ -275,13 +377,24 @@ This document should use "Main Title" as the HTML title.
output_file = Path(self.temp_dir) / "responsive.html"
# Should fail initially - responsive CSS not implemented
with pytest.raises((AttributeError, NotImplementedError, ImportError, FileNotFoundError)):
if output_file.exists():
html_content = output_file.read_text()
# Responsive CSS IS implemented - test actual functionality
from markitect.cli import cli
from click.testing import CliRunner
# Should include viewport meta tag
assert '<meta name="viewport"' in html_content
runner = CliRunner()
result = runner.invoke(cli, [
'md-render',
str(input_file),
'--output', str(output_file)
])
# Should include responsive CSS patterns
assert 'max-width' in html_content or '@media' in html_content
assert result.exit_code == 0
assert output_file.exists()
html_content = output_file.read_text()
# Should include viewport meta tag
assert '<meta name="viewport"' in html_content
# Should include responsive CSS patterns
assert 'max-width' in html_content