Files
ewoooc/tests/test_frontend_v2_assets.py

81 lines
3.3 KiB
Python

from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_frontend_v2_shell_assets_exist_and_are_indexed():
assert (ROOT / "web/static/css/ewoooc-tokens.css").exists()
assert (ROOT / "web/static/css/ewoooc-shell.css").exists()
assert (ROOT / "templates/ewoooc_base.html").exists()
assert (ROOT / "templates/components/_ewoooc_shell.html").exists()
agents = (ROOT / "AGENTS.md").read_text(encoding="utf-8")
constitution = (ROOT / "CONSTITUTION.md").read_text(encoding="utf-8")
roadmap = (ROOT / "docs/guides/frontend_upgrade_roadmap.md").read_text(encoding="utf-8")
assert "docs/guides/frontend_upgrade_roadmap.md" in agents
assert "前端 V2 視覺基準" in constitution
assert "禁止用 mock data" in roadmap
def test_frontend_v2_shell_uses_real_runtime_context():
shell = (ROOT / "templates/components/_ewoooc_shell.html").read_text(encoding="utf-8")
base = (ROOT / "templates/ewoooc_base.html").read_text(encoding="utf-8")
assert "scheduler_stats" in shell
assert "session.get('username')" in shell
assert "next_run|default(None)" in shell
assert "components/_ewoooc_shell.html" in base
forbidden_markers = [
"mockProducts",
"mockData",
"fake",
"假商品",
"假 KPI",
]
combined = shell + "\n" + base
assert all(marker not in combined for marker in forbidden_markers)
def test_dashboard_v2_is_feature_flagged_and_uses_real_dashboard_data():
route_source = (ROOT / "routes/dashboard_routes.py").read_text(encoding="utf-8")
dashboard = (ROOT / "templates/dashboard_v2.html").read_text(encoding="utf-8")
assert "request.args.get('ui') == 'v2'" in route_source
assert "template_name = 'dashboard_v2.html'" in route_source
assert "get_full_dashboard_data()" in route_source
assert "MockRecord" not in route_source
assert "{% for item in items %}" in dashboard
assert "mockProducts" not in dashboard
assert "假商品" not in dashboard
def test_edm_dashboard_v2_is_feature_flagged_and_uses_real_campaign_data():
route_source = (ROOT / "routes/edm_routes.py").read_text(encoding="utf-8")
template = (ROOT / "templates/edm_dashboard_v2.html").read_text(encoding="utf-8")
assert route_source.count("request.args.get('ui') == 'v2'") == 5
assert "template_name = 'edm_dashboard_v2.html'" in route_source
assert "{% for slot, stats in slot_stats.items() %}" in template
assert "{% for item in items %}" in template
assert "scheduler_stats.get(task_key, [])" in template
assert "mock" not in template.lower()
assert "假商品" not in template
def test_vendor_stockout_v2_is_feature_flagged_and_uses_real_vendor_data():
route_source = (ROOT / "routes/vendor_routes.py").read_text(encoding="utf-8")
template = (ROOT / "web/templates/vendor_stockout_index_v2.html").read_text(encoding="utf-8")
assert "request.args.get('ui') == 'v2'" in route_source
assert "vendor_stockout_index_v2.html" in route_source
assert "_get_vendor_dashboard_stats()" in route_source
assert "session.query(VendorStockout).count()" in route_source
assert "EmailSendLog" in route_source
assert "stats.get('pending_stockouts'" in template
assert "stats.get('email_success_rate'" in template
assert "mock" not in template.lower()
assert "" not in template