Files
Jyotisha/frontend/tests/personal-report-export.test.ts
T
jesse-uxandClaude Code f125fae0a0
Independent Staging Quality Gate / validate (push) Failing after 11m16s
Independent Staging Quality Gate / publish (push) Skipped
feat(reports): streamline reader actions and center export dialog
Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-24 20:43:35 +08:00

51 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",
);
const documentViewSource = readFileSync(
new URL("../src/components/personal-report/personal-report-document-view.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/);
assert.doesNotMatch(documentViewSource, /dangerouslySetInnerHTML|srcDoc|<iframe/i);
});