Rebuild workspace widgets and behavioral graph views

This commit is contained in:
2026-03-13 16:48:24 +00:00
parent f8a6d1d41c
commit 57269770b5
47 changed files with 2951 additions and 1077 deletions

View File

@@ -0,0 +1,73 @@
from __future__ import annotations
from django.test import TestCase
from django.urls import reverse
from core.models import Person, PersonIdentifier, User
class BehavioralGraphViewTests(TestCase):
def setUp(self):
self.user = User.objects.create_user(
username="behavior-user",
email="behavior@example.com",
password="pw",
)
self.client.force_login(self.user)
self.person = Person.objects.create(user=self.user, name="Behavior Contact")
PersonIdentifier.objects.create(
user=self.user,
person=self.person,
service="signal",
identifier="+15551234567",
)
def test_behavioral_graph_widget_renders_without_chartjs(self):
response = self.client.get(
reverse(
"ai_workspace_insight_graphs",
kwargs={"type": "widget", "person_id": self.person.id},
)
)
self.assertEqual(200, response.status_code)
content = response.content.decode("utf-8")
self.assertIn("Behavioral Graphs", content)
self.assertIn("MS", content)
self.assertNotIn("chart.js", content.lower())
def test_behavioral_information_page_uses_ms_ps_copy(self):
response = self.client.get(
reverse(
"ai_workspace_information",
kwargs={"type": "page", "person_id": self.person.id},
)
)
self.assertEqual(200, response.status_code)
self.assertContains(response, "MS / PS Information")
self.assertContains(
response, "Current message-state and presence-state signals"
)
def test_ai_person_widget_exposes_behavioral_launcher_only(self):
response = self.client.get(
reverse(
"ai_workspace_person",
kwargs={"type": "widget", "person_id": self.person.id},
)
)
self.assertEqual(200, response.status_code)
content = response.content.decode("utf-8")
self.assertIn("Open MS / PS graphs, information, and help", content)
self.assertIn(
reverse(
"ai_workspace_insight_graphs",
kwargs={"type": "widget", "person_id": self.person.id},
),
content,
)
self.assertNotIn("/insights/platform/", content)
self.assertNotIn("/insights/stability_state/", content)
self.assertNotIn("/insights/commitment_inbound/", content)

View File

@@ -7,6 +7,7 @@ from django.test import TestCase
from django.urls import reverse
from core.models import ChatSession, Message, Person, PersonIdentifier, User
from core.views.compose import COMPOSE_ASSET_VERSION
class ComposeSendCapabilityTests(TestCase):
@@ -77,11 +78,26 @@ class ComposeSendCapabilityTests(TestCase):
self.assertEqual(200, response.status_code)
content = response.content.decode("utf-8")
self.assertIn("compose-panel.css", content)
self.assertIn("compose-panel-core.js", content)
self.assertIn("compose-panel-thread.js", content)
self.assertIn("compose-panel-send.js", content)
self.assertIn("compose-panel.js", content)
self.assertIn(
f"/static/css/compose-panel.css?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel-core.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel-thread.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel-send.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertNotIn("const initialTyping = JSON.parse(", content)
self.assertNotIn("data-drafts-url=", content)
self.assertNotIn("data-summary-url=", content)
@@ -104,14 +120,43 @@ class ComposeSendCapabilityTests(TestCase):
self.assertEqual(200, response.status_code)
content = response.content.decode("utf-8")
self.assertIn("data-gia-style-hrefs=", content)
self.assertIn("/static/css/compose-panel.css", content)
self.assertIn(
f"/static/css/compose-panel.css?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn("data-gia-script-srcs=", content)
self.assertIn("/static/js/compose-panel-core.js", content)
self.assertIn("/static/js/compose-panel-thread.js", content)
self.assertIn("/static/js/compose-panel-send.js", content)
self.assertIn("/static/js/compose-panel.js", content)
self.assertIn(
f"/static/js/compose-panel-core.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel-thread.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel-send.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn(
f"/static/js/compose-panel.js?v={COMPOSE_ASSET_VERSION}",
content,
)
self.assertIn('gs-id="widget-compose-widget-', content)
self.assertNotIn("<script defer src=\"/static/js/compose-panel.js\">", content)
self.assertNotIn("<link rel=\"stylesheet\" href=\"/static/css/compose-panel.css\">", content)
self.assertNotIn('data-gia-action="lock"', content)
self.assertIn('data-gia-action="snap-top"', content)
self.assertIn('data-gia-action="snap-bottom"', content)
def test_compose_workspace_history_widget_uses_shared_shell(self):
response = self.client.get(reverse("compose_workspace_history_widget"))
self.assertEqual(200, response.status_code)
content = response.content.decode("utf-8")
self.assertIn('gs-id="widget-compose-workspace-history"', content)
self.assertNotIn('data-gia-action="lock"', content)
self.assertIn('data-gia-action="snap-top"', content)
self.assertIn('data-gia-action="snap-bottom"', content)
def test_compose_contacts_dropdown_includes_workspace_link(self):
response = self.client.get(reverse("compose_contacts_dropdown"))
@@ -119,6 +164,11 @@ class ComposeSendCapabilityTests(TestCase):
self.assertEqual(200, response.status_code)
self.assertContains(response, reverse("compose_workspace"))
def test_removed_compose_quick_insights_endpoint_returns_404(self):
response = self.client.get("/compose/quick-insights/")
self.assertEqual(404, response.status_code)
@patch("core.views.compose._recent_manual_contacts")
def test_compose_contact_options_use_compact_service_map(self, mocked_recent_contacts):
mocked_recent_contacts.return_value = [
@@ -196,6 +246,57 @@ class ComposeSendCapabilityTests(TestCase):
self.assertIn("compose-row", str(payload.get("messages_html") or ""))
self.assertIn("Rendered thread row", str(payload.get("messages_html") or ""))
def test_compose_thread_before_ts_returns_older_window(self):
person = Person.objects.create(user=self.user, name="Older Contact")
identifier = PersonIdentifier.objects.create(
user=self.user,
person=person,
service="signal",
identifier="+15550001111",
)
session = ChatSession.objects.create(user=self.user, identifier=identifier)
oldest = Message.objects.create(
user=self.user,
session=session,
sender_uuid="contact",
text="Oldest message",
ts=1710000000000,
custom_author="CONTACT",
)
middle = Message.objects.create(
user=self.user,
session=session,
sender_uuid="contact",
text="Middle message",
ts=1710000001000,
custom_author="CONTACT",
)
Message.objects.create(
user=self.user,
session=session,
sender_uuid="contact",
text="Newest message",
ts=1710000002000,
custom_author="CONTACT",
)
response = self.client.get(
reverse("compose_thread"),
{
"service": "signal",
"identifier": "+15550001111",
"before_ts": middle.ts,
},
)
self.assertEqual(200, response.status_code)
payload = response.json()
html = str(payload.get("messages_html") or "")
self.assertIn("Oldest message", html)
self.assertNotIn("Middle message", html)
self.assertFalse(payload.get("has_older"))
self.assertEqual(str(oldest.ts), str(payload["messages"][0]["ts"]))
def test_compose_thread_payload_renders_reply_link_text_server_side(self):
person = Person.objects.create(user=self.user, name="Reply Contact")
identifier = PersonIdentifier.objects.create(

View File

@@ -0,0 +1,33 @@
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)