docs: 添加详细需求说明和前端检查清单(防止丢失功能的强制机制)

This commit is contained in:
maoshen
2026-04-15 01:29:46 +00:00
parent 35664f9d56
commit 418104aed1
3 changed files with 241 additions and 9 deletions

104
test_frontend.py Normal file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env python3
"""
日记系统前端功能自动化测试
每次修改前端后必须运行此测试
"""
import requests
import sys
BASE_URL = 'http://127.0.0.1:8001'
API_BASE = f'{BASE_URL}/api'
def test_api_endpoints():
"""测试 API 接口"""
print("📡 测试 API 接口...")
tests = [
('日记统计', f'{API_BASE}/entries/stats/', 200),
('日记列表', f'{API_BASE}/entries/', 200),
('今日日记', f'{API_BASE}/entries/today/', 200),
('最近日记', f'{API_BASE}/entries/recent/', 200),
('经验总结', f'{API_BASE}/experiences/recent/', 200),
]
passed = 0
failed = 0
for name, url, expected_status in tests:
try:
resp = requests.get(url, timeout=5)
if resp.status_code == expected_status:
print(f"{name}: {resp.status_code}")
passed += 1
else:
print(f"{name}: 期望 {expected_status}, 实际 {resp.status_code}")
failed += 1
except Exception as e:
print(f"{name}: {str(e)}")
failed += 1
return passed, failed
def test_frontend_page():
"""测试前端页面"""
print("\n🌐 测试前端页面...")
try:
resp = requests.get(BASE_URL, timeout=5)
if resp.status_code == 200:
content = resp.text
# 检查关键功能是否存在
checks = [
('日历组件', 'calendar'),
('统计面板', 'stat-'),
('Tab 切换', 'tab-'),
('日记列表', 'diary'),
('经验总结', 'experience'),
('选择日期函数', 'selectDate'),
('渲染日历函数', 'renderCalendar'),
]
passed = 0
failed = 0
for name, keyword in checks:
if keyword in content:
print(f"{name}: 存在")
passed += 1
else:
print(f"{name}: 缺失 (关键词:{keyword})")
failed += 1
return passed, failed
else:
print(f" ❌ 页面访问失败:{resp.status_code}")
return 0, 1
except Exception as e:
print(f" ❌ 页面访问错误:{str(e)}")
return 0, 1
def main():
print("=" * 60)
print("🧪 日记系统前端功能测试")
print("=" * 60)
api_passed, api_failed = test_api_endpoints()
page_passed, page_failed = test_frontend_page()
total_passed = api_passed + page_passed
total_failed = api_failed + page_failed
print("\n" + "=" * 60)
print(f"📊 测试结果:{total_passed} 通过,{total_failed} 失败")
print("=" * 60)
if total_failed > 0:
print("\n⚠️ 有功能测试失败,请检查后再部署!")
sys.exit(1)
else:
print("\n✅ 所有测试通过,可以部署!")
sys.exit(0)
if __name__ == '__main__':
main()