import { describe, expect, test } from "bun:test"; import { auditEvidenceFiles, auditFiledIssues, auditListTitle, auditSourceId, auditWorkOrderTitle } from "../src/lib/auditPresentation"; describe("filed audit snapshots", () => { test("restores the original source and all unique screenshot files", () => { const description = "[UI] 搜索不刷新\n\n来源:验证任务「Close Friends」(abc-123)\n\n证据:`en-search.png`\n证据:`de-search.png`\n证据:`en-search.png`"; expect(auditSourceId(description)).toBe("abc-123"); expect(auditEvidenceFiles(description)).toEqual(["en-search.png", "de-search.png"]); }); test("ordinary bug descriptions do not get an unrelated source section", () => { expect(auditSourceId("复现:点开来源任务 abc-123")).toBeNull(); expect(auditEvidenceFiles("代码位置:`Search.swift:12` ")).toEqual([]); }); test("long quoted titles are not cut before their available two lines", () => { const text = "在「Add to Highlight」页点「See reposts」后出现第二步引导「Tap to collapse」,此时点返回键、点空白处都没反应,用户必须先点那个折叠按钮才能离开页面"; expect(auditListTitle({ text })).toBe(text); expect(auditListTitle({ text })).not.toContain("…"); }); test("short list labels preserve the full issue snapshot", () => { const issue = { text: "搜索结果未刷新", detail: "点击清空后仍保留上一次的搜索结果,需要再次输入才刷新。" }; const before = JSON.stringify(issue); expect(auditListTitle(issue)).toBe("搜索结果未刷新"); expect(JSON.stringify(issue)).toBe(before); }); }); describe("read-only filed issue cards", () => { test("shows a saved expectation as text and keeps evidence collapsed separately", () => { const description = "来源:验证任务「报告」(abc)\n\n## P2 · 功能 · profile/search @ en\n清空搜索后未刷新\n\n**复现条件**:搜索后点击清空\n取证:界面仍保留旧结果\n**期望**:清空后显示全部成员\n第二行补充\n代码位置:`Search.swift:12`\n证据:`search.png`"; const [issue] = auditFiledIssues(description); expect(issue.headline).toBe("清空搜索后未刷新"); expect(issue.expected).toBe("清空后显示全部成员\n第二行补充"); expect(issue.evidence).toContain("界面仍保留旧结果"); expect(issue.evidence).not.toContain("清空后显示全部成员"); expect(issue.files).toEqual(["search.png"]); }); test("merged issues retain their own screenshots and omit empty expectations", () => { const issues = auditFiledIssues("## P1 · 功能 · page-a @ en\n问题 A\n证据:`a.png`\n\n## P3 · 布局 · page-b @ de\n问题 B\n**期望**: \n证据:`b.png`"); expect(issues.map((i) => i.files)).toEqual([["a.png"], ["b.png"]]); expect(issues.map((i) => i.expected)).toEqual(["", ""]); }); }); test("restores old truncated audit titles without rewriting unrelated work orders", () => { const description = "来源:验证任务「走查」(abc)\n\n## P2 · 功能 · dm @ en\n群聊 Notifications 当前选项没有选中\n证据:`dm.png`"; expect(auditWorkOrderTitle("[UI] 群聊 Notifications…", description)).toBe("[UI] 群聊 Notifications 当前选项没有选中"); expect(auditWorkOrderTitle("自定义标题", description)).toBe("自定义标题"); expect(auditWorkOrderTitle("其他问题…", "普通问题描述")).toBe("其他问题…"); }); describe("merged audit work orders", () => { test("parses every issue the merged renderer writes, with TOS screenshots and boxes", async () => { const { renderAuditFixDescription } = await import("@bbbug/shared/audit_fix_plan"); const iss = (n: number, text: string) => ({ n, sev: "P2" as const, cat: "组件规范", langs: ["en"], text, code: "a/B.kt", repro: "Inbox → Requests", cause: "图标资源传错" }); const report = { title: "走查", meta: [], langs: ["en"], blocked: [], totals: { issues: 2, instances: 2, bySev: {}, byCat: {} }, coverage: { ok: 0, issue: 0, missing: 0 }, pages: [{ id: "s1-dm/03-requests", surface: "面 1 · DM 私信", title: "消息请求页", coverage: ["issue" as const], issues: [iss(1, "返回是尖角。"), iss(2, "标题偏左。")] }], }; const g = { trusted: true, surface: "面 1 · DM 私信", title: "[UI] 返回是尖角 等 2 个问题 · DM 私信", sev: "P2" as const, picks: [{ pageId: "s1-dm/03-requests", n: 1, lang: "en" }, { pageId: "s1-dm/03-requests", n: 2, lang: "en" }] }; const description = renderAuditFixDescription(g, { data: { report, shots: [{ pageId: "s1-dm/03-requests", lang: "en", file: "a.png", boxes: { 1: [{ x: 1.9, y: 7.6, w: 9.7, h: 4.8 }] } }] }, source: { id: "553ebfef-ba45", title: "导航栏" }, notes: { "s1-dm/03-requests#2": { note: "左对齐 16dp" } }, files: { "a.png": "images/plan-11111111-1111-1111-1111-111111111111.png" }, }); expect(auditSourceId(description)).toBe("553ebfef-ba45"); const issues = auditFiledIssues(description); expect(issues.map((i) => [i.fid, i.severity, i.pageId, i.pageTitle, i.lang, i.headline])).toEqual([ ["F-01", "P2", "s1-dm/03-requests", "消息请求页", "en", "返回是尖角。"], ["F-02", "P2", "s1-dm/03-requests", "消息请求页", "en", "标题偏左。"], ]); expect(issues[0].image).toBe("https://voffline.byted.org/download/tos/schedule/streamline/img_upload/plan-11111111-1111-1111-1111-111111111111.png"); expect(issues[0].boxes).toEqual([{ x: 1.9, y: 7.6, w: 9.7, h: 4.8 }]); expect(issues[0].expected).toBe(""); expect(issues[1].expected).toBe("左对齐 16dp"); expect(issues[0].repro).toBe("Inbox → Requests"); expect(issues[0].cause).toBe("图标资源传错"); expect(issues[0].code).toBe("a/B.kt"); }); }); test("page titles that contain their own parentheses still parse", () => { const d = "来源:验证任务「x」(v-1)\n\n## F-38 · P2 · 布局 · `s3-story/10-post-page`(主拍发布页(Post)) @ en\n- 实际:发布按钮矮一截。\n- 期望:(复核人没写。按 TUX 规范)\n"; const [i] = auditFiledIssues(d); expect([i.fid, i.pageTitle, i.lang, i.headline, i.expected]).toEqual(["F-38", "主拍发布页(Post)", "en", "发布按钮矮一截。", ""]); });