Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/pdf-report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ function allAnswers(d: Diagnostic, value: AnswerValue) {

const PDF_MAGIC = "%PDF-";

// Read the leading bytes as a string without spreading the typed array.
// `String.fromCharCode(...bytes.slice(0, 5))` trips TS2802 under TypeScript
// 5.7+ (Uint8Array became generic); Array.from with a map callback avoids the
// iteration requirement.
function magic(bytes: Uint8Array, len = 5): string {
return Array.from(bytes.slice(0, len), (b) => String.fromCharCode(b)).join("");
}

describe.each(listDiagnostics())("buildReportPdf — $id", (diagnostic) => {
it("produces a valid, non-trivial PDF for a weak result", () => {
const result = scoreDiagnostic(diagnostic, allAnswers(diagnostic, 0));
const bytes = new Uint8Array(buildReportPdf(diagnostic, result));
const head = String.fromCharCode(...bytes.slice(0, 5));
const head = magic(bytes);
expect(head).toBe(PDF_MAGIC);
expect(bytes.byteLength).toBeGreaterThan(2000);
});

it("produces a valid PDF for a strong result (no bottleneck playbook edge)", () => {
const result = scoreDiagnostic(diagnostic, allAnswers(diagnostic, 4));
const bytes = new Uint8Array(buildReportPdf(diagnostic, result));
expect(String.fromCharCode(...bytes.slice(0, 5))).toBe(PDF_MAGIC);
expect(magic(bytes)).toBe(PDF_MAGIC);
expect(bytes.byteLength).toBeGreaterThan(2000);
});

Expand All @@ -34,6 +42,6 @@ describe.each(listDiagnostics())("buildReportPdf — $id", (diagnostic) => {
});
const result = scoreDiagnostic(diagnostic, answers);
const bytes = new Uint8Array(buildReportPdf(diagnostic, result));
expect(String.fromCharCode(...bytes.slice(0, 5))).toBe(PDF_MAGIC);
expect(magic(bytes)).toBe(PDF_MAGIC);
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"e2e": "playwright test",
"screenshot": "node scripts/screenshot.mjs"
Expand Down
Loading