Repository Public
1// UQO Éval — exports génériques : feuilles, CSV, XLSX et PDF portent la mention UQO Éval et restituent les tableaux imbriqués.2import { describe, expect, it } from "vitest";3import ExcelJS from "exceljs";4import { exportResult, sheetsToCsv, toSheets, UQO_MENTION_FR } from "./export-generic";56const sample = {7 title: { fr: "Titre", en: "Title" }, n: 12, ok: true, nested: { a: 1, b: { c: "x" } },8 coefficients: [{ name: "intercept", value: 1.5, label: { fr: "Constante", en: "Intercept" } }, { name: "area", value: 0.25, label: { fr: "Aire", en: "Area" } }],9 series: [{ key: "valeur", points: [{ x: "2021", y: 1 }, { x: "2022", y: 2 }] }],10 plots: { big: new Array(10).fill({ x: 1 }) },11};1213describe("exports génériques UQO Éval", () => {14 it("transforme un résultat en feuilles : résumé, tableaux, tableaux imbriqués hissés, libellés bilingues, exclusions", () => {15 const sh = toSheets(sample, "fr", { skip: ["plots"] });16 expect(sh.map((s) => s.name)).toEqual(["Résumé", "coefficients", "series.valeur", "series"]);17 const sum = Object.fromEntries(sh[0].rows.map((r) => [r[0], r[1]]));18 expect(sum.title).toBe("Titre"); expect(sum.n).toBe(12); expect(sum.ok).toBe(1); expect(sum["nested.b.c"]).toBe("x");19 expect(sh[1].columns).toEqual(["name", "value", "label"]); expect(sh[1].rows[0]).toEqual(["intercept", 1.5, "Constante"]);20 expect(sh[2].rows).toEqual([["2021", 1], ["2022", 2]]);21 expect(toSheets(sample, "en", { skip: ["plots"] })[1].rows[0][2]).toBe("Intercept");22 });23 it("CSV : BOM, mention UQO Éval, titre, échappement", () => {24 const csv = sheetsToCsv(toSheets({ rows: [{ a: 'dit "bonjour", oui', b: 2 }] }, "fr"), { title: "Test, export", source: "/x", lang: "fr" });25 expect(csv.startsWith("# UQO Éval")).toBe(true); expect(csv).toContain("# Test, export"); expect(csv).toContain('"dit ""bonjour"", oui",2');26 });27 it("XLSX : feuille de couverture UQO Éval puis une feuille par tableau", async () => {28 const r = await exportResult(sample, "xlsx", { title: "Essai", source: "/x", lang: "fr" }, { skip: ["plots"] });29 expect(r.ext).toBe("xlsx"); const wb = new ExcelJS.Workbook(); await wb.xlsx.load(r.body as unknown as ArrayBuffer);30 expect(wb.worksheets.map((w) => w.name)).toEqual(["UQO Éval", "Résumé", "coefficients", "series.valeur", "series"]);31 const cover = wb.getWorksheet("UQO Éval")!; expect(String(cover.getCell("A1").value)).toBe("UQO Éval"); expect(String(cover.getCell("B6").value)).toBe(UQO_MENTION_FR);32 expect(wb.getWorksheet("coefficients")!.getCell("A2").value).toBe("intercept");33 });34 it("PDF : document valide portant le titre et la mention UQO Éval en pied de page", async () => {35 const r = await exportResult(sample, "pdf", { title: "Rapport d'essai", subtitle: "sous-titre", source: "/x", lang: "en" }, { skip: ["plots"] });36 expect(r.mime).toBe("application/pdf"); expect(r.body.subarray(0, 5).toString()).toBe("%PDF-"); expect(r.body.length).toBeGreaterThan(5000);37 });38 it("JSON : enveloppe _uqo_eval avec mention et titre", async () => {39 const r = await exportResult({ a: 1 }, "json", { title: "J", source: "/x", lang: "fr" });40 const j = JSON.parse(r.body.toString()); expect(j._uqo_eval.title).toBe("J"); expect(j._uqo_eval.mention).toBe(UQO_MENTION_FR); expect(j.a).toBe(1);41 });42});4344describe("ligatures JetBrains Mono", () => {45 it("un texte avec « // », « .. », « -- » dans la police mono s'exporte sans erreur (PDF)", async () => {46 const r = await exportResult({ url: "https://www.uqo-eval.app/x", code: "a--b..c->d", rows: [{ chemin: "../x//y" }] }, "pdf", { title: "Ligatures -- test", source: "https://www.uqo-eval.app/stats", lang: "fr" });47 expect(r.body.subarray(0, 5).toString()).toBe("%PDF-");48 });49});50