Files
Jyotisha/frontend/tests/personal-report-export.test.ts
T
jesse-uxandGrok (agent loop) 1f9947a0d7 删除三个无调用方接口和约 3000 行前端死代码
关掉未登录就会触发约 20 秒计算的入口,并记下 BUG-1342。普通导出的逐字节锁保留。自测 tsc 0 错,lint 0 error / 123 warning,改到的前端测试 fail=0,两份 Python 测试通过,test:db 失败 13 条与 Windows 已知清单一致。

Co-Authored-By: Grok (agent loop)
2026-10-14 08:39:32 +08:00

48 lines
2.5 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { detectPrintRestriction } from "../src/lib/client-report-export.ts";
const exportSource = readFileSync(
new URL("../src/lib/client-report-export.ts", import.meta.url),
"utf8",
);
const actionsSource = readFileSync(
new URL("../src/components/personal-report/report-actions.tsx", import.meta.url),
"utf8",
);
const pageSource = readFileSync(
new URL("../src/components/personal-report/personal-report-page.tsx", import.meta.url),
"utf8",
);
// TASK-report-reader-actions D2 retires the print helper's four tests, not Ctrl+P.
// Old/new assertions and test-name mapping are recorded in the task PROGRESS.
test("detectPrintRestriction flags WeChat in-app browser and nothing else", () => {
assert.equal(detectPrintRestriction("Mozilla/5.0 MicroMessenger/8.0.49").restricted, true);
assert.equal(detectPrintRestriction("Mozilla/5.0 (iPhone) Safari").restricted, false);
assert.equal(detectPrintRestriction(undefined).restricted, false);
assert.equal(detectPrintRestriction("MicroMessenger").message,
"微信内置浏览器可能无法完整打印,请在系统浏览器中打开本页后打印。");
});
test("client export never touches a server PDF pipeline", () => {
assert.doesNotMatch(exportSource, /api\/report_artifact/);
assert.doesNotMatch(exportSource, /html2canvas|jsPDF|jspdf|playwright|puppeteer|chromium/i);
assert.doesNotMatch(exportSource, /canvas|base64/i);
assert.doesNotMatch(exportSource, /\bfetch\s*\(/);
assert.doesNotMatch(exportSource, /window\.print|document\.fonts|document\.title/);
assert.doesNotMatch(exportSource, /printPersonalReport|isPrintSupported|safeReportFilename/);
});
test("the Markdown report keeps print layout support without a reader print button", () => {
assert.match(pageSource, /longformMarkdown/);
assert.match(pageSource, /PersonalReportMarkdownView/);
assert.doesNotMatch(pageSource, /PersonalReportDocumentView/);
assert.match(pageSource, /<style media="print">\{"@page \{ size: A4;/);
assert.match(pageSource, /<style media="print">\{REPORT_SHELL_PRINT_CSS\}/);
assert.doesNotMatch(actionsSource, /printPersonalReport|PERSONAL_REPORT_PRINT_LABEL|Printer|isPrintSupported/);
// 原值: document-view 源码不得出现 dangerouslySetInnerHTML、srcDoc、<iframe
// 新值: 删掉这条。pageSource 不得出现 PersonalReportDocumentView 的断言保留
// 原因: 旧阅读页文件已删除,页面仍不得挂回它
});