feat: Integrate HTML templates with FastAPI
- Created template_helpers.py for centralized template rendering - Added ux_features.css for enhanced UX styling - Implemented JavaScript modules for: - Keyboard shortcuts (Ctrl+K, Ctrl+R navigation) - User preferences persistence - Undo/redo functionality (Ctrl+Z/Ctrl+Y) - Mobile responsive features - Touch gesture support - Accessibility features (ARIA, focus management) - Screen reader support - Color contrast compliance (WCAG) - Multi-screen support - Updated page_controller.py and error_controller.py to use template helpers - Created comprehensive template integration tests - All templates verified: index.html, login.html, setup.html, queue.html, error.html - Maintained responsive layout and theme switching - Updated instructions.md (removed completed task) - Updated infrastructure.md with template integration details
This commit is contained in:
86
tests/unit/test_template_helpers.py
Normal file
86
tests/unit/test_template_helpers.py
Normal file
@@ -0,0 +1,86 @@
|
||||
"""
|
||||
Tests for template helper utilities.
|
||||
|
||||
This module tests the template helper functions.
|
||||
"""
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
from src.server.utils.template_helpers import (
|
||||
get_base_context,
|
||||
list_available_templates,
|
||||
validate_template_exists,
|
||||
)
|
||||
|
||||
|
||||
class TestTemplateHelpers:
|
||||
"""Test template helper utilities."""
|
||||
|
||||
def test_get_base_context(self):
|
||||
"""Test that base context is created correctly."""
|
||||
request = Mock()
|
||||
context = get_base_context(request, "Test Title")
|
||||
|
||||
assert "request" in context
|
||||
assert context["request"] == request
|
||||
assert context["title"] == "Test Title"
|
||||
assert context["app_name"] == "Aniworld Download Manager"
|
||||
assert context["version"] == "1.0.0"
|
||||
|
||||
def test_get_base_context_default_title(self):
|
||||
"""Test that default title is used."""
|
||||
request = Mock()
|
||||
context = get_base_context(request)
|
||||
|
||||
assert context["title"] == "Aniworld"
|
||||
|
||||
def test_validate_template_exists_true(self):
|
||||
"""Test template validation for existing template."""
|
||||
# index.html should exist
|
||||
exists = validate_template_exists("index.html")
|
||||
assert exists is True
|
||||
|
||||
def test_validate_template_exists_false(self):
|
||||
"""Test template validation for non-existing template."""
|
||||
exists = validate_template_exists("nonexistent.html")
|
||||
assert exists is False
|
||||
|
||||
def test_list_available_templates(self):
|
||||
"""Test listing available templates."""
|
||||
templates = list_available_templates()
|
||||
|
||||
# Should be a list
|
||||
assert isinstance(templates, list)
|
||||
|
||||
# Should contain at least the main templates
|
||||
expected_templates = [
|
||||
"index.html",
|
||||
"login.html",
|
||||
"setup.html",
|
||||
"queue.html",
|
||||
"error.html"
|
||||
]
|
||||
for expected in expected_templates:
|
||||
assert expected in templates, (
|
||||
f"{expected} not found in templates list"
|
||||
)
|
||||
|
||||
def test_list_available_templates_only_html(self):
|
||||
"""Test that only HTML files are listed."""
|
||||
templates = list_available_templates()
|
||||
|
||||
for template in templates:
|
||||
assert template.endswith(".html")
|
||||
|
||||
@pytest.mark.parametrize("template_name", [
|
||||
"index.html",
|
||||
"login.html",
|
||||
"setup.html",
|
||||
"queue.html",
|
||||
"error.html"
|
||||
])
|
||||
def test_all_required_templates_exist(self, template_name):
|
||||
"""Test that all required templates exist."""
|
||||
assert validate_template_exists(template_name), \
|
||||
f"Required template {template_name} does not exist"
|
||||
Reference in New Issue
Block a user