from __future__ import annotations

from django.test import TestCase
from django.urls import reverse

from core.models import Person, User


class OSINTWidgetActionTests(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            username="osint-widget-user",
            email="osint-widget@example.com",
            password="pw",
        )
        self.client.force_login(self.user)
        self.person = Person.objects.create(user=self.user, name="Widget Person")

    def test_people_widget_edit_actions_open_inside_widgets(self):
        response = self.client.get(reverse("people", kwargs={"type": "widget"}))

        self.assertEqual(200, response.status_code)
        content = response.content.decode("utf-8")
        self.assertIn(
            reverse(
                "person_update",
                kwargs={"type": "widget", "pk": self.person.pk},
            ),
            content,
        )
        self.assertIn('hx-target="#widgets-here"', content)
        self.assertIn('hx-swap="beforeend"', content)
        self.assertNotIn('hx-target="#windows-here"', content)
