test_s2_nav_link.py 1.68 KB
#!/usr/bin/env python3
"""Test S2: nav link to /messages in base.html."""
import subprocess, sys

def curl_page(path):
    r = subprocess.run(
        ["curl", "-s", f"http://127.0.0.1:5000{path}",
         "--connect-timeout", "5", "--max-time", "10"],
        capture_output=True, text=True, timeout=15
    )
    return r.stdout

PASS = FAIL = 0
def check(name, condition, detail=""):
    global PASS, FAIL
    if condition:
        PASS += 1
        print(f"  ✅ {name}")
    else:
        FAIL += 1
        print(f"  ❌ {name} -- {detail}")

# TC1: /messages page has link to /messages
html = curl_page("/messages")
check("TC1: /messages has <a href=\"/messages\">", 'href="/messages"' in html, "not found")

# TC2: link text contains 消息
check("TC2: nav link text contains 消息",
      'href="/messages"' in html and '消息' in html,
      "check text")

# TC3: existing 消息浏览 link still exists
check("TC3: existing / link still exists",
      'href="/"' in html and '消息浏览' in html,
      "existing link missing")

# TC4: JS escape check
check("TC4: No JS backslash bug", "style=\\\\\\'" not in html, "STYLE BACKSLASH BUG")
check("TC4b: No Jinja2 escaped quotes in template literal",
      'data-action=\\"' not in html, "JINJA2 ESCAPED QUOTES")

# TC5: / page still renders
html_root = curl_page("/")
check("TC5: GET / → 200 with content", len(html_root) > 1000, f"len={len(html_root)}")

# TC6: key JS functions exist on /messages
check("TC6: toggleDrawer exists", "toggleDrawer" in html, "missing")
check("TC6b: loadAccounts exists", "loadAccounts" in html, "missing")

print(f"\n{'='*40}")
print(f"Results: {PASS} passed, {FAIL} failed, {PASS+FAIL} total")
sys.exit(0 if FAIL == 0 else 1)