feat(print): styled PDF export and printouts with branded header, real tables and podium marks (1.72.0)

This commit is contained in:
larssand committed 2026-11-06 22:52:02 +01:00
1 parent c4375daa93
commit 7c25f23ad0
8 files changed
+504 -372

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createRequire } from "node:module";
const { buildStyledPdf } = createRequire(import.meta.url)("../server/pdf_render.js");
const base = { title: "Resultat", subtitle: "", brandName: "Klubben", brandTagline: "", footer: "RC RaceCore", theme: "classic", logoDataUrl: "" };
test("the PDF has real tables: Helvetica fonts, a filled header row, podium marks and page numbers", () => {
const rows = Array.from({ length: 70 }, (_, i) => [String(i + 1), `Förare ${i + 1}`, String(20 - (i % 5)), "0:14.812"]);
const pdf = buildStyledPdf({ ...base, sections: [{ title: "A-final", headers: ["Pos", "Förare", "Varv", "Bästa varv"], rows }] }).toString("latin1");
assert.ok(pdf.includes("/BaseFont /Helvetica ") && pdf.includes("/BaseFont /Helvetica-Bold"), "Helvetica and Helvetica-Bold");
assert.ok(!pdf.includes("Courier"), "no typewriter font any more");
assert.ok(pdf.includes("0.831 0.686 0.216 rg"), "gold mark for the winner");
assert.match(pdf, /\/Count 2 /, "70 rows run onto a second page");
assert.equal((pdf.match(/\(Bästa varv\) Tj/g) || []).length, 2, "the table header repeats on the new page");
assert.ok(pdf.includes("(1 / 2) Tj") && pdf.includes("(2 / 2) Tj"), "page numbers");
});
test("a long name is shortened with … instead of running into the next column", () => {
const pdf = buildStyledPdf({ ...base, sections: [{ title: "", headers: ["Pos", "Förare", ...Array.from({ length: 14 }, (_, i) => `R${i + 1}`)], rows: [["1", "A".repeat(120), ...Array.from({ length: 14 }, () => "(100)")]] }] });
assert.ok(pdf.includes(Buffer.from([0x85])), "ellipsis as a WinAnsi byte");
});
+1
View File
@@ -46,3 +46,4 @@ import "./public_training_refresh.test.js";
import "./list_sorting.test.js";
import "./sync_status.test.js";
import "./decoder_diagnostics.test.js";
import "./pdf_render.test.js";