Files
KSP_project/tests/test_guanghan_topology_demo.py
T
2026-07-15 12:21:34 +08:00

93 lines
3.7 KiB
Python

from __future__ import annotations
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
HTML_PATH = ROOT / "data" / "wiki" / "guanghan_topology_demo.html"
class GuanghanTopologySourceTests(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.html = HTML_PATH.read_text(encoding="utf-8")
def test_topology_is_rendered_from_snapshot_layout(self) -> None:
self.assertNotIn('<g class="topology-node"', self.html)
self.assertNotIn("GROUP_MEMBERS", self.html)
self.assertNotIn("data-conn=", self.html)
self.assertIn("currentData.layout", self.html)
self.assertIn("currentData.connections", self.html)
self.assertIn("function renderTopology", self.html)
def test_radiators_are_dynamic_layout_decorations(self) -> None:
self.assertNotIn('<g class="radiator">', self.html)
self.assertIn("decorations.radiator", self.html)
self.assertIn("function createRadiator", self.html)
def test_future_expansion_anchors_remain_source_comments(self) -> None:
for direction in ("north", "east", "west"):
self.assertIn(
f"FUTURE_EXPANSION_ANCHOR:{direction}",
self.html,
)
self.assertNotIn("未来北部十字结构", self.html)
self.assertNotIn("未来东部十字结构", self.html)
self.assertNotIn("未来西部十字结构", self.html)
def test_page_uses_same_origin_api(self) -> None:
self.assertIn("new URL('.', window.location.href).pathname", self.html)
self.assertIn("replace(/\\/$/, '')", self.html)
self.assertNotIn("http://localhost:5000", self.html)
def test_page_uses_database_presentation_payload(self) -> None:
self.assertIn("getPresentation", self.html)
self.assertIn("?.presentation", self.html)
self.assertIn("nodeStyles", self.html)
self.assertIn("edgeStyles", self.html)
self.assertIn("decorationStyles", self.html)
self.assertIn("legendItems", self.html)
def test_canvas_is_square_and_page_defaults_to_light(self) -> None:
self.assertIn('viewBox="0 0 1900 1900"', self.html)
self.assertIn("payload.layout.canvasWidth", self.html)
self.assertIn("payload.layout.canvasHeight", self.html)
self.assertIn("color-scheme: light", self.html)
self.assertNotIn("color-scheme: dark", self.html)
def test_business_visual_semantics_are_not_css_hardcoded(self) -> None:
forbidden = [
".connection.structural",
".connection.pressurized",
".connection.utility",
".node-card { fill:",
".core-card { fill:",
".power-card { fill:",
".power-node-card { fill:",
".vehicle-card { fill:",
"function connectionClass",
]
for token in forbidden:
self.assertNotIn(token, self.html)
def test_legend_is_rendered_from_presentation_payload(self) -> None:
self.assertIn('id="legend"', self.html)
self.assertNotIn("结构直连</span>", self.html)
self.assertNotIn("加压走道</span>", self.html)
self.assertNotIn("燃料 / 供电</span>", self.html)
self.assertNotIn("大型折叠散热面板</span>", self.html)
self.assertIn("renderLegend", self.html)
def test_controls_use_api_navigation_and_safe_text(self) -> None:
self.assertIn("/api/v1/bases/guanghan/missions", self.html)
self.assertNotIn("return ['BL-01'", self.html)
self.assertIn("popstate", self.html)
self.assertIn("Asia/Shanghai", self.html)
self.assertNotIn(".innerHTML =", self.html)
self.assertIn("replaceChildren", self.html)
if __name__ == "__main__":
unittest.main()