"""안내문 발송 화면(index.html)을 진짜 ERP 셸로 렌더 — 브라우저 테스트용(2026-10-27).
python tests/js/render_outreach.py # → tests/js/.out/outreach.html
화면 데이터는 실제 router._view 로 만든다(저장소 없이 줄만 가짜).
"""
from __future__ import annotations
import os
import sys
import jinja2
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, ROOT)
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
from app.modules.outreach import store # noqa: E402
from app.modules.outreach.router import _view # noqa: E402
def main() -> None:
os.makedirs(OUT_DIR, exist_ok=True)
env = jinja2.Environment(loader=jinja2.FileSystemLoader([
os.path.join(ROOT, "app", "templates"), os.path.join(ROOT, "app", "modules", "outreach", "templates")]), autoescape=True)
t = {**store.normalize_template(None), "updated_by": "", "updated_at": "", "is_default": True}
base = {"id": 0, "memo": "", "status": "대기", "sent_at": "", "sent_by": "", "sent_via": "", "last_error": ""}
raw = [
{**base, "id": 1, "kind": "email", "handle": "kim@miras.co.kr", "address": "kim@miras.co.kr", "name": "김철수"},
{**base, "id": 2, "kind": "instagram", "handle": "mira.kitchen", "address": "@mira.kitchen", "name": "미라"},
{**base, "id": 3, "kind": "email", "handle": "noname@miras.co.kr", "address": "noname@miras.co.kr", "name": ""},
{**base, "id": 4, "kind": "email", "handle": "done@miras.co.kr", "address": "done@miras.co.kr", "name": "보냄씨",
"status": "보냄", "sent_at": "2026-10-27T10:00:00+09:00", "sent_via": "gmail"},
]
ctx = {"user": {"email": "me@miras.co.kr", "name": "나", "picture": ""}, "is_admin": False, "nav_items": [],
"page_title": "안내문 발송", "page_subtitle": "", "template": t, "images": [], "rows": [_view(r, t) for r in raw],
"logs": [], "gmail": {"available": True, "connected": True, "email": "me@miras.co.kr"}, "msg": ""}
with open(os.path.join(OUT_DIR, "outreach.html"), "w", encoding="utf-8") as f:
f.write(env.get_template("outreach/index.html").render(**ctx))
if __name__ == "__main__":
main()