refactor: establish shared frontend shell

This commit is contained in:
leefer
2026-07-29 21:38:38 +08:00
parent e177f21d1c
commit 8d617cfa17
8 changed files with 380 additions and 173 deletions
+41 -1
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import json
import re
import unittest
from pathlib import Path
@@ -21,17 +22,56 @@ class FrontendBoundaryTests(unittest.TestCase):
def test_shared_dependencies_load_before_application(self) -> None:
html = (STATIC / "index.html").read_text(encoding="utf-8")
pages_position = html.index('/pages.config.js')
state_position = html.index('/shared/state.js')
api_position = html.index('/shared/api.js')
shell_position = html.index('/shared/shell.js')
app_position = html.index('/app.js')
self.assertLess(pages_position, state_position)
self.assertLess(state_position, api_position)
self.assertLess(api_position, app_position)
self.assertLess(api_position, shell_position)
self.assertLess(shell_position, app_position)
def test_application_state_is_created_through_shared_boundary(self) -> None:
app = (STATIC / "app.js").read_text(encoding="utf-8")
self.assertIn("const state = window.XiaobaiState.create({", app)
self.assertNotIn("const state = {", app)
def test_runtime_page_registry_matches_governance_registry(self) -> None:
expected = json.loads(
(ROOT / "config" / "pages.config.json").read_text(encoding="utf-8")
)["pages"]
runtime = (STATIC / "pages.config.js").read_text(encoding="utf-8")
rows = re.findall(
r'^\s*\["([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", (true|false)\],$',
runtime,
re.MULTILINE,
)
actual = [
{
"id": row[0],
"title": row[1],
"feature": row[2],
"group": row[3],
"access": row[4],
"default": row[5] == "true",
"desktop_scroll": "page",
"mobile_layout": "dedicated",
}
for row in rows
]
self.assertEqual(actual, expected)
def test_shell_owns_navigation_and_page_mounting(self) -> None:
app = (STATIC / "app.js").read_text(encoding="utf-8")
shell = (STATIC / "shared" / "shell.js").read_text(encoding="utf-8")
self.assertNotIn("function syncNavigationState", app)
self.assertNotIn("function initializeApplicationShell", app)
self.assertIn("function syncNavigation(viewId)", shell)
self.assertIn("function mount(viewId, mountOptions = {})", shell)
self.assertIn("function openModalDialog(dialog)", shell)
self.assertNotIn('document.querySelectorAll(".module-tab").forEach', app)
if __name__ == "__main__":
unittest.main()