refactor: establish shared frontend shell
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -23,6 +23,7 @@ class FrontendContractTests(unittest.TestCase):
|
||||
def setUpClass(cls) -> None:
|
||||
cls.html = (STATIC_DIR / "index.html").read_text(encoding="utf-8")
|
||||
cls.script = (STATIC_DIR / "app.js").read_text(encoding="utf-8")
|
||||
cls.shell = (STATIC_DIR / "shared" / "shell.js").read_text(encoding="utf-8")
|
||||
cls.ui_core = (STATIC_DIR / "ui-core.js").read_text(encoding="utf-8")
|
||||
cls.design_system = (STATIC_DIR / "design-system.css").read_text(encoding="utf-8")
|
||||
cls.theme = (STATIC_DIR / "theme.css").read_text(encoding="utf-8")
|
||||
@@ -297,7 +298,7 @@ class FrontendContractTests(unittest.TestCase):
|
||||
self.assertIn('id="openTradeLogDialog"', self.html)
|
||||
self.assertIn('id="tradeLogDialog" class="settings-dialog trade-log-dialog"', self.html)
|
||||
self.assertIn('openModalDialog(elements.tradeLogDialog)', self.script)
|
||||
self.assertIn('document.querySelectorAll("dialog[open]")', self.script)
|
||||
self.assertIn('document.querySelectorAll("dialog[open]")', self.shell)
|
||||
self.assertIn('renderTradeLog();\n closeTradeLogDialog();', self.script)
|
||||
|
||||
def test_review_workspace_exposes_complete_watchlist_and_three_part_journal(self):
|
||||
|
||||
Reference in New Issue
Block a user