"""HTMX auto-apply filter views return the results partial on HX-Request and
the full page on a normal GET (investor directory · product catalogue ·
partner directory). Guards the get_template_names() branch + partial wiring.
"""
import pytest
from django.contrib.auth import get_user_model
from django.urls import reverse

User = get_user_model()
pytestmark = pytest.mark.django_db

URLS = [
    ("smehub_investment:investor_directory", "investor-results"),
    ("smehub_marketplace:product_catalogue", "catalogue-results"),
    ("smehub_linkage:partner_directory", "partner-results"),
]


@pytest.fixture
def user():
    return User.objects.create_user(email="htmx-filter@example.com", password="x")


@pytest.mark.parametrize("url_name,wrapper_id", URLS)
def test_full_page_get(client, user, url_name, wrapper_id):
    client.force_login(user)
    resp = client.get(reverse(url_name))
    assert resp.status_code == 200
    body = resp.content.decode()
    # Full page carries the filter <form>, the results wrapper, and extends the layout.
    assert "<form" in body
    assert f'id="{wrapper_id}"' in body


@pytest.mark.parametrize("url_name,wrapper_id", URLS)
def test_htmx_get_returns_partial(client, user, url_name, wrapper_id):
    client.force_login(user)
    resp = client.get(reverse(url_name), HTTP_HX_REQUEST="true")
    assert resp.status_code == 200
    body = resp.content.decode()
    # Partial: no filter <form> and no results wrapper (those live in the full page only).
    assert "<form" not in body
    assert f'id="{wrapper_id}"' not in body
