"""View-level smoke tests for the Repository search surface."""

from __future__ import annotations

import pytest
from django.test import Client
from django.urls import reverse

from apps.repository.search.views import SAMPLE_QUERIES_FALLBACK


@pytest.mark.django_db
def test_empty_search_seeds_top_queries_with_fallback(public_collection):
    """An empty-result search renders the editorial 'try these' chips.

    With no SearchEvent rows in the DB, the view must fall back to the
    module-level SAMPLE_QUERIES_FALLBACK so the empty state never goes blank.
    """
    client = Client()
    resp = client.get(reverse("repo_search:search") + "?q=zzzznoresultzzzz")

    assert resp.status_code == 200
    assert "top_queries" in resp.context
    assert list(resp.context["top_queries"]) == list(SAMPLE_QUERIES_FALLBACK)

    # Chips render in the template.
    body = resp.content.decode()
    for sample in SAMPLE_QUERIES_FALLBACK:
        assert f"?q={sample}" in body
