""" Tests for template integration and rendering. This module tests that all HTML templates are properly integrated with FastAPI and can be rendered correctly. """ import pytest from fastapi.testclient import TestClient from src.server.fastapi_app import app class TestTemplateIntegration: """Test template integration with FastAPI.""" @pytest.fixture def client(self): """Create test client.""" return TestClient(app) def test_index_template_renders(self, client): """Test that index.html renders successfully.""" response = client.get("/") assert response.status_code == 200 assert response.headers["content-type"].startswith("text/html") assert b"AniWorld Manager" in response.content assert b"/static/css/styles.css" in response.content def test_login_template_renders(self, client): """Test that login.html renders successfully.""" response = client.get("/login") assert response.status_code == 200 assert response.headers["content-type"].startswith("text/html") assert b"Login" in response.content assert b"/static/css/styles.css" in response.content def test_setup_template_renders(self, client): """Test that setup.html renders successfully.""" response = client.get("/setup") assert response.status_code == 200 assert response.headers["content-type"].startswith("text/html") assert b"Setup" in response.content assert b"/static/css/styles.css" in response.content def test_queue_template_renders(self, client): """Test that queue.html renders successfully.""" response = client.get("/queue") assert response.status_code == 200 assert response.headers["content-type"].startswith("text/html") assert b"Download Queue" in response.content assert b"/static/css/styles.css" in response.content def test_error_template_404(self, client): """Test that 404 error page renders correctly.""" response = client.get("/nonexistent-page") assert response.status_code == 404 assert response.headers["content-type"].startswith("text/html") assert b"Error 404" in response.content or b"404" in response.content def test_static_css_accessible(self, client): """Test that static CSS files are accessible.""" response = client.get("/static/css/styles.css") assert response.status_code == 200 assert "text/css" in response.headers.get("content-type", "") def test_static_js_accessible(self, client): """Test that static JavaScript files are accessible.""" response = client.get("/static/js/app.js") assert response.status_code == 200 def test_templates_include_theme_switching(self, client): """Test that templates include theme switching functionality.""" response = client.get("/") assert response.status_code == 200 # Check for theme toggle button assert b"theme-toggle" in response.content # Check for data-theme attribute assert b'data-theme="light"' in response.content def test_templates_include_responsive_meta(self, client): """Test that templates include responsive viewport meta tag.""" response = client.get("/") assert response.status_code == 200 assert b'name="viewport"' in response.content assert b"width=device-width" in response.content def test_templates_include_font_awesome(self, client): """Test that templates include Font Awesome icons.""" response = client.get("/") assert response.status_code == 200 assert b"font-awesome" in response.content.lower() def test_all_templates_have_correct_structure(self, client): """Test that all templates have correct HTML structure.""" pages = ["/", "/login", "/setup", "/queue"] for page in pages: response = client.get(page) assert response.status_code == 200 content = response.content # Check for essential HTML elements assert b"" in content assert b"" in content assert b"" in content assert b"" in content def test_templates_load_required_javascript(self, client): """Test that index template loads all required JavaScript files.""" response = client.get("/") assert response.status_code == 200 content = response.content # Check for main app.js assert b"/static/js/app.js" in content # Check for localization.js assert b"/static/js/localization.js" in content def test_templates_load_ux_features_css(self, client): """Test that templates load UX features CSS.""" response = client.get("/") assert response.status_code == 200 assert b"/static/css/ux_features.css" in response.content def test_queue_template_has_websocket_script(self, client): """Test that queue template includes WebSocket support.""" response = client.get("/queue") assert response.status_code == 200 # Check for socket.io or WebSocket implementation assert ( b"socket.io" in response.content or b"WebSocket" in response.content ) def test_index_includes_search_functionality(self, client): """Test that index page includes search functionality.""" response = client.get("/") assert response.status_code == 200 content = response.content assert b"search-input" in content assert b"search-btn" in content def test_templates_accessibility_features(self, client): """Test that templates include accessibility features.""" response = client.get("/") assert response.status_code == 200 content = response.content # Check for ARIA labels or roles assert b"aria-" in content or b"role=" in content