from __future__ import annotations

import pytest
from django.template.loader import render_to_string


@pytest.mark.django_db
def test_share_buttons_partial_renders_all_targets():
    url = "https://example.com/alumni/42/"
    title = "Aisha Mwangi"
    text = "Soil systems researcher"
    html = render_to_string(
        "components/share_buttons.html",
        {"share_url": url, "share_title": title, "share_text": text},
    )
    # Each target shares to the right destination.
    assert "linkedin.com/sharing" in html
    assert "twitter.com/intent/tweet" in html
    assert "wa.me/?text=" in html
    assert "mailto:" in html
    # The URL is interpolated in encoded form (urlencode preserves /).
    assert "https%3A//example.com/alumni/42/" in html
    # Spaces in the share text are %20-encoded.
    assert "Soil%20systems%20researcher" in html
    # Title is URL-encoded into the mailto subject.
    assert "Aisha%20Mwangi" in html
    # Copy button surfaces the bare URL via data attribute.
    assert f'data-copy-url="{url}"' in html
