import { strict as assert } from "node:assert"; import test from "node:test"; import { buildXlsxWorkbook } from "../../apps/desktop/src/lib/xlsxExport.ts"; test("builds an xlsx workbook zip with worksheet data", () => { const workbook = buildXlsxWorkbook({ sheetName: "Users", columns: ["id", "name", "active"], rows: [ [1, "Ada & Bob", true], [2, null, false], ], }); const text = new TextDecoder().decode(workbook); assert.equal(workbook[0], 0x50); assert.equal(workbook[1], 0x4b); assert.match(text, /\[Content_Types\]\.xml/); assert.match(text, /xl\/worksheets\/sheet1\.xml/); assert.match(text, /name="Users"/); assert.match(text, /1<\/v><\/c>/); assert.match(text, /Ada & Bob/); assert.match(text, /1<\/v><\/c>/); }); test("sanitizes invalid sheet names", () => { const workbook = buildXlsxWorkbook({ sheetName: "bad/name:with*chars?and-a-very-long-tail", columns: ["value"], rows: [["ok"]], }); const text = new TextDecoder().decode(workbook); assert.match(text, /name="bad name with chars and-a-very-"/); });