51 lines
2.5 KiB
TypeScript
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);
|
|
});
|