Files
StarlightRadio/test_e2e.py
T
Xiao-no-love 5d5d5cce19 v2.2+v2.3: 前端增强与 UI 去 AI 味重构
v2.2 前端增强:
- 站内 HLS 收听页 (#pageLive),hls.js 本地化 vendor/hls.min.js
- 设置页 (缓存/配置/日志)
- 上传进度百分比 (XHR upload.onprogress)
- 资源列表排序 (时间/热度/名称 ×升降)
- 面板正在播放实时化 (接 playlist-update/song-finished,删死监听)
- 死代码清理 + forgetSong 内存泄漏修复 + CORS 非法头移除
- start.cmd 托管启动脚本 (set "VAR=val" 避免尾部空格)

v2.3 UI 去 AI 味 (依据 ibelick/ui-skills baseline-ui):
- 频道管理+切换合并为单一入口 #btnStreamMgr.channel-btn
  (删除 header 的 #streamSelect 下拉,弹窗内统一切换/删除/新建)
- 清除全部 CSS 渐变与 glow: 橙红 #ff5f6d→#ffc371、紫 #8b5cf6、
  径向光晕、缓存条渐变 → 全部改为 accent/token 纯色
- live 区、modal 区硬编码色统一归 CSS 变量 token

测试: api 16/16, e2e 17/17, write 5/5 全绿
2026-09-24 21:55:23 +08:00

62 lines
2.6 KiB
Python

import urllib.request, urllib.error, http.cookiejar, json, sys, re
BASE = "http://127.0.0.1:3000"
cj = http.cookiejar.CookieJar()
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
def call(path, method="GET", data=None, raw=False):
body = json.dumps(data).encode() if data is not None else None
req = urllib.request.Request(BASE + path, data=body, method=method)
if body: req.add_header("Content-Type", "application/json")
try:
r = op.open(req, timeout=10)
return r.status, r.read()
except urllib.error.HTTPError as e:
return e.code, e.read()
results = []
def check(name, cond, extra=""):
results.append((name, cond)); print(("PASS" if cond else "FAIL"), name, extra)
# 静态资源可达(不需要登录)
for path in ["/vendor/bootstrap.min.css", "/vendor/bootstrap-icons.css",
"/vendor/Sortable.min.js", "/vendor/bootstrap-icons.woff2",
"/css/style.css", "/js/app.js", "/login.html", "/favicon.ico"]:
st, _ = call(path)
check(f"静态 {path}", st == 200, f"got {st}")
# 登录
st, body = call("/api/auth/login", "POST", {"password": "test123"})
check("登录", st == 200 and json.loads(body).get("ok"), f"got {st}")
# 首页返回面板(含 vendor 引用)
st, body = call("/")
html = body.decode("utf-8", "ignore")
check("首页返回面板", st == 200 and "pageSearch" in html and "loginForm" not in html, f"got {st}")
check("面板引用本地vendor", "vendor/bootstrap.min.css" in html and "cdn.jsdelivr" not in html)
# 资源列表
st, body = call("/api/resources")
d = json.loads(body)
check("资源列表非空", st == 200 and len(d["list"]) >= 1, f"{len(d.get('list',[]))}")
# 检查封面字段(可能为空,本地化后是 /covers/ 或空)
covers = [x["albumImage"] for x in d["list"]]
print(" 封面字段样例:", covers[:2])
# 流列表
st, body = call("/api/streams")
d = json.loads(body)
check("流列表", st == 200 and len(d["list"]) >= 1, str([s["id"] for s in d["list"]]))
# 播放列表
st, body = call("/api/streams/main/playlist")
d = json.loads(body)
check("主频道播放列表", st == 200 and "list" in d, f"{len(d.get('list',[]))}项")
# 检查 index.html 是否有 import/stream 元素
check("HTML含频道按钮", 'id="btnStreamMgr"' in html and 'id="currentChannelName"' in html)
check("HTML含导入卡片", 'id="importCard"' in html or 'id="importFile"' in html)
check("HTML含登出按钮", 'id="btnLogout"' in html)
print("\n=== 汇总:", sum(1 for _,c in results if c), "/", len(results), "通过 ===")
sys.exit(0 if all(c for _,c in results) else 1)