generated from coulomb/repo-seed
Integrate whynot-design into Economic Observatory UI
Vendor whynot-design Layer 1 (tokens, CSS) and Layer 2 (<wn-*> components) via scripts/sync-whynot-design.sh with a pinned ref. Migrate the observatory shell to canonical web components, keep observatory-specific layout in styles.css, and add vendor integrity tests plus correct JS MIME types on the dev server.
This commit is contained in:
62
projects/coulomb-pricing/tests/test_ui_vendor.py
Normal file
62
projects/coulomb-pricing/tests/test_ui_vendor.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import threading
|
||||
from http.server import HTTPServer
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
VENDOR = ROOT / "ui" / "vendor" / "whynot-design"
|
||||
|
||||
REQUIRED_VENDOR_FILES = [
|
||||
VENDOR / ".whynot-design-ref",
|
||||
VENDOR / "colors_and_type.css",
|
||||
VENDOR / "components.css",
|
||||
VENDOR / "index.js",
|
||||
VENDOR / "elements" / "atoms.js",
|
||||
VENDOR / "elements" / "chrome.js",
|
||||
VENDOR / "elements" / "form.js",
|
||||
VENDOR / "elements" / "layout.js",
|
||||
VENDOR / "elements" / "icons.js",
|
||||
VENDOR / "elements" / "_styles.js",
|
||||
VENDOR / "tokens" / "colors.json",
|
||||
]
|
||||
|
||||
|
||||
def test_vendor_tree_is_complete() -> None:
|
||||
missing = [path for path in REQUIRED_VENDOR_FILES if not path.exists()]
|
||||
assert not missing, f"Missing vendored whynot-design files: {missing}"
|
||||
|
||||
|
||||
def test_vendor_ref_is_pinned() -> None:
|
||||
ref = (VENDOR / ".whynot-design-ref").read_text(encoding="utf-8").strip()
|
||||
assert len(ref) == 40
|
||||
|
||||
|
||||
def test_server_serves_vendor_modules() -> None:
|
||||
server_module = importlib.import_module("observatory.server")
|
||||
handler = server_module.ObservatoryHandler
|
||||
handler.data_dir = ROOT / "data"
|
||||
|
||||
httpd = HTTPServer(("127.0.0.1", 0), handler)
|
||||
port = httpd.server_address[1]
|
||||
thread = threading.Thread(target=httpd.serve_forever, daemon=True)
|
||||
thread.start()
|
||||
|
||||
try:
|
||||
import urllib.request
|
||||
|
||||
index = urllib.request.urlopen(f"http://127.0.0.1:{port}/", timeout=2)
|
||||
assert "wn-top-nav" in index.read().decode("utf-8")
|
||||
|
||||
module = urllib.request.urlopen(
|
||||
f"http://127.0.0.1:{port}/ui/vendor/whynot-design/index.js",
|
||||
timeout=2,
|
||||
)
|
||||
assert module.headers["Content-Type"].startswith("application/javascript")
|
||||
assert "defineAtoms" in module.read().decode("utf-8")
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
thread.join(timeout=2)
|
||||
Reference in New Issue
Block a user