feat(plugins): 4 个业务插件代码 + 前台公开页面改造
plugins/navManager:导航 CRUD + 导航分类 CRUD(独立 blueprint) plugins/friendManager:友情链接 CRUD plugins/aboutManager:关于本站 CRUD plugins/siteStats:访问统计主页 + JSON 接口 + /site/* GET 埋点 + nav 卡片点击埋点 applications/view/public/nav.py:导航聚合页 / 分类详情 / JSON 接口,支持 visit_count 注入 applications/view/public/about.py:关于本站公开页 applications/view/public/friend.py:友情链接公开页 templates/public/base.html:响应式首页(搜索框 / 分类抽屉 / 5 主题切换 / footer 隐私小字) templates/public/index.html / category.html:卡片右下角访问次数 templates/public/about.html / friend.html:关于 + 友链前台页 docs/plugins-development.md:插件开发完整指南(生命周期 + 4 个示例 + FAQ + framework 迁移) scripts/:探针与端到端验证脚本(probe_*/verify_*/test_*)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""验证点击卡片触发 sendBeacon,数据库 +1。"""
|
||||
from playwright.sync_api import sync_playwright
|
||||
from app import app
|
||||
from applications.extensions import db
|
||||
from applications.models import NavClick
|
||||
|
||||
with app.app_context():
|
||||
before = db.session.query(db.func.count(NavClick.id)).filter(NavClick.nav_id == 1).scalar()
|
||||
print('before click:', before)
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch()
|
||||
ctx = browser.new_context(viewport={'width': 1280, 'height': 800})
|
||||
page = ctx.new_page()
|
||||
page.goto('http://127.0.0.1:5000/site/', wait_until='networkidle')
|
||||
# 拦截请求,看是不是 POST
|
||||
reqs = []
|
||||
page.on('request', lambda r: reqs.append(r) if '/site/nav/1/click' in r.url else None)
|
||||
# 点击第一张卡片
|
||||
card = page.locator('.card[data-nav-id="1"]').first
|
||||
card.click(modifiers=['Meta']) # 按住 Meta 打开新标签,保持当前页
|
||||
page.wait_for_timeout(500)
|
||||
print('captured requests:', [(r.method, r.url) for r in reqs])
|
||||
browser.close()
|
||||
|
||||
with app.app_context():
|
||||
after = db.session.query(db.func.count(NavClick.id)).filter(NavClick.nav_id == 1).scalar()
|
||||
print('after click:', after)
|
||||
assert after == before + 1, f"Expected {before+1}, got {after}"
|
||||
print('PASS: beacon recorded click')
|
||||
Reference in New Issue
Block a user