from __future__ import annotations import unittest from pathlib import Path from govoplan_postbox.backend.manifest import manifest REPOSITORY_ROOT = Path(__file__).resolve().parents[1] class PostboxInterfaceDocumentationContractTests(unittest.TestCase): def test_route_and_contributed_surfaces_remain_declared(self) -> None: frontend = manifest.frontend self.assertIsNotNone(frontend) self.assertEqual( {"/postbox"}, {route.path for route in frontend.routes}, # type: ignore[union-attr] ) self.assertEqual( { "postbox.admin.templates", "postbox.inbox.directory", "postbox.inbox.messages", "postbox.quick_access.messages", "postbox.widget.inbox", }, {surface.id for surface in frontend.view_surfaces}, # type: ignore[union-attr] ) self.assertTrue(all(item.icon == "inbox" for item in manifest.nav_items)) def test_topics_publish_stable_help_privacy_and_consequence_metadata(self) -> None: topics = {topic.id: topic for topic in manifest.documentation} self.assertIn("postbox.function-bound-containers", topics) self.assertIn("postbox.reference.fields-and-consequences", topics) guide = topics["postbox.function-bound-containers"] self.assertIn("postbox.inbox.messages", guide.metadata["help_contexts"]) self.assertIn("postbox.state.unavailable", guide.metadata["help_contexts"]) self.assertGreaterEqual(len(guide.metadata["privacy_notes"]), 3) reference = topics["postbox.reference.fields-and-consequences"] self.assertIn("postbox.field.classification", reference.metadata["help_contexts"]) self.assertIn("postbox.action.delete-grouping", reference.metadata["help_contexts"]) self.assertIn("archive_postbox", reference.metadata["consequence_classes"]) self.assertIn("withdraw_or_expire", reference.metadata["consequence_classes"]) quick_tool = manifest.frontend.quick_access_tools[0] self.assertEqual(("postbox.message",), quick_tool.returned_reference_kinds) self.assertEqual("postbox.quick_access.messages", quick_tool.help_context_id) self.assertEqual("/postbox", quick_tool.full_page_path) def test_quick_access_is_bounded_and_owner_launched(self) -> None: quick_access = ( REPOSITORY_ROOT / "webui/src/features/postbox/PostboxQuickAccess.tsx" ).read_text(encoding="utf-8") page = ( REPOSITORY_ROOT / "webui/src/features/postbox/PostboxPage.tsx" ).read_text(encoding="utf-8") self.assertIn("const MESSAGE_LIMIT = 7", quick_access) self.assertIn('"unread"', quick_access) self.assertIn('kind: "message"', quick_access) self.assertIn("launchContext.actingContext", quick_access) self.assertIn("quickAccessLaunchState(launchContext)", quick_access) self.assertIn('parameters.get("quickAction") !== "compose"', page) self.assertIn("openComposeFor(postbox)", page) if __name__ == "__main__": unittest.main()