Files
Live_RC/tests/pdf_flags.test.js
T

29 lines
1.4 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import { COUNTRIES } from "../src/country_flags.js";
const require = createRequire(import.meta.url);
const { buildStyledPdf } = require("../server/pdf_render.js");
const { PDF_FLAG_CODES } = require("../server/pdf_flags.js");
const pdf = (flags) => buildStyledPdf({ title: "Final", filename: "x.pdf", theme: "classic", sections: [{ title: "A-final", headers: ["Pos", "Förare", "Resultat"], rows: [["1", "Anders Larsson", "20/5:01"], ["2", "Roy Gjemble", "20/5:04"], ["3", "Kim Lee", "19/5:00"]], flags }] }).toString("latin1");
test("PDF: a driver's flag is drawn before the name; no country, no flag", () => {
const sweden = "0.000 0.416 0.655 rg"; // #006aa7
const norway = "0.729 0.047 0.184 rg"; // #ba0c2f
const withFlags = pdf(["SE", "NO", ""]);
assert.ok(withFlags.includes(sweden), "Swedish blue");
assert.ok(withFlags.includes(norway), "Norwegian red");
assert.ok(!pdf([]).includes(sweden), "no flags sent: none drawn");
});
test("PDF: a country without a drawn flag shows its code instead", () => {
assert.match(pdf(["GB", "", ""]), /\(GB\) Tj/);
});
test("every flag the PDF draws is a country the app knows", () => {
const known = new Set(COUNTRIES.map(([code]) => code));
for (const code of PDF_FLAG_CODES) assert.ok(known.has(code), code);
});