# app/modules/messaging/tests/integration/test_email_logs_page.py
"""
Integration tests for admin email logs page route (HTML rendering).

Tests the page route at:
    GET /admin/email-logs

Authentication: Uses super_admin_headers fixture (real JWT login).
"""

import pytest

BASE = "/admin"


@pytest.mark.integration
@pytest.mark.email
class TestAdminEmailLogsPage:
    """Tests for GET /admin/email-logs."""

    def test_page_renders(self, client, super_admin_headers):
        """Email logs page returns HTML."""
        response = client.get(
            f"{BASE}/email-logs",
            headers=super_admin_headers,
        )
        assert response.status_code == 200
        assert "text/html" in response.headers["content-type"]

    def test_page_contains_alpine_component(self, client, super_admin_headers):
        """Page HTML references the emailLogsPage Alpine component."""
        response = client.get(
            f"{BASE}/email-logs",
            headers=super_admin_headers,
        )
        assert b"emailLogsPage" in response.content

    def test_page_includes_js(self, client, super_admin_headers):
        """Page HTML includes the email-logs.js script."""
        response = client.get(
            f"{BASE}/email-logs",
            headers=super_admin_headers,
        )
        assert b"email-logs.js" in response.content

    def test_page_requires_auth(self, client):
        """Unauthenticated request is redirected."""
        response = client.get(
            f"{BASE}/email-logs",
            follow_redirects=False,
        )
        # Should redirect to login or return 401/403
        assert response.status_code in (301, 302, 303, 307, 401, 403)
