- 数据模型: vote/review/submission/claim/use_case/audience/collection/event (+tool 冗余统计列) - 社区: 投票(限流+原子toggle+API) / 评论(评分+优缺点+Helpful+聚合回写) / 提交(重复检测+审批发布) / 认领(Owner白名单编辑) - Ranking Engine: trending/popular/most-voted/most-saved/highest-rated/new/editors-choice (纯函数可测) - 发现体系: Use Case + Audience + Collection 三维发现 / /ai-tools-for / /best SEO 页 - Programmatic SEO: 页面生成器 / sitemap 270条 / AggregateRating/FAQPage/Breadcrumb/ItemList schema / alternatives + vs 对比页 - Analytics: event 事件流 + 外链跳转埋点 + /admin/analytics CTR 与搜索词分析 - Admin: submissions/claims/reviews/discovery/vote-audit/analytics 六个新后台 + 仪表盘扩展 - 主题系统: themes registry + 五套站点 (classic/product/editorial/niche/minimal) 构建期注入 - 认证: GitHub OAuth (env门控) + 登录回跳 redirect - i18n: 新增 7 个命名空间中英文案 (546 键一致) - 测试: bun test 32 用例 (ranking/slug/去重/SEO生成器) + Playwright e2e 脚本 - 种子: 14分类/16用例/9受众/40工具/6用户/投票/评论/6合集/7718事件
68 lines
3.0 KiB
TypeScript
68 lines
3.0 KiB
TypeScript
/**
|
|
* # 脚本 e2e-interaction
|
|
* 说明:端到端交互验证 —— 登录 → 投票 → 计数变化 → 退出登录态下投票被拦截。
|
|
*/
|
|
import { chromium } from "playwright";
|
|
|
|
const BASE = "http://localhost:3001";
|
|
const results: string[] = [];
|
|
|
|
const browser = await chromium.launch();
|
|
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
|
const page = await context.newPage();
|
|
|
|
// 1) 登录
|
|
await page.goto(`${BASE}/login`, { waitUntil: "domcontentloaded" });
|
|
await page.fill('input[name="email"], input[type="email"]', "alice@demo.dev");
|
|
await page.fill('input[name="password"], input[type="password"]', "password123");
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL(/dashboard|\/$/, { timeout: 15000 }).catch(() => {});
|
|
results.push(`登录后 URL: ${page.url()}`);
|
|
|
|
// 2) 打开工具详情页,记录票数
|
|
await page.goto(`${BASE}/tools/claude`, { waitUntil: "domcontentloaded" });
|
|
await page.waitForTimeout(1000);
|
|
const voteButton = page.locator("button", { hasText: /Upvote/ }).first();
|
|
const before = await voteButton.textContent();
|
|
results.push(`投票前按钮: ${(before ?? "").trim()}`);
|
|
|
|
// 3) 投票
|
|
await voteButton.click();
|
|
await page.waitForTimeout(1500);
|
|
const after = await voteButton.textContent();
|
|
results.push(`投票后按钮: ${(after ?? "").trim()}`);
|
|
results.push(`投票生效: ${(before ?? "") !== (after ?? "") ? "PASS" : "FAIL"}`);
|
|
|
|
// 4) 写评论
|
|
try {
|
|
const hasReviewForm = await page.locator('button:has-text("Write a review")').count();
|
|
results.push(`找到 Write a review 按钮: ${hasReviewForm}`);
|
|
if (hasReviewForm > 0) {
|
|
await page.locator('button:has-text("Write a review")').first().click();
|
|
await page.waitForTimeout(800);
|
|
await page.screenshot({ path: "/tmp/aidir-shots/e2e-review-form.png" });
|
|
// 选 5 星(表单内的大号星级)
|
|
await page.locator('form button[aria-label="5"]').first().click();
|
|
await page.locator("form textarea").first().fill("Interactive e2e test review - Claude handles long documents exceptionally well.");
|
|
await page.locator('form button:has-text("Publish review")').click();
|
|
await page.waitForTimeout(2000);
|
|
const reviewVisible = await page.locator("text=Interactive e2e test review").count();
|
|
results.push(`评论发布: ${reviewVisible > 0 ? "PASS" : "FAIL"}`);
|
|
}
|
|
} catch (error) {
|
|
await page.screenshot({ path: "/tmp/aidir-shots/e2e-debug.png" });
|
|
results.push(`评论步骤异常: ${String(error).slice(0, 100)}`);
|
|
}
|
|
|
|
// 5) 提交工具(重复检测)
|
|
await page.goto(`${BASE}/submit`, { waitUntil: "domcontentloaded" });
|
|
await page.fill('input[placeholder="ChatGPT"]', "ChatGPT");
|
|
await page.fill('input[type="url"]', "https://chatgpt.com");
|
|
await page.locator('input[type="url"]').blur();
|
|
await page.waitForTimeout(1200);
|
|
const dupVisible = await page.locator("text=already be listed").count();
|
|
results.push(`重复检测: ${dupVisible > 0 ? "PASS" : "FAIL"}`);
|
|
|
|
await browser.close();
|
|
console.log(results.join("\n"));
|