ConusAI vendor v0.1.0-dev.20261027+9b1131fb
ci / gate (push) Waiting to run

This commit is contained in:
ConusAI vendor v0.1.0-dev.20261027+9b1131fb
2026-10-27 18:05:17 +00:00
commit 3102273ec7
538 changed files with 80203 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
import { describe, expect, it } from "vitest"
import { buildWorkbook } from "../core/xlsx.js"
import { unzip } from "./support/unzip.js"
describe("the workbook writer", () => {
const book = buildWorkbook("Approved lines", [
["Label", "Value", "Page"],
["Total", "12,50", 2],
])
const files = unzip(book)
it("writes the parts a spreadsheet application needs to open the file", () => {
expect([...files.keys()].sort()).toEqual([
"[Content_Types].xml",
"_rels/.rels",
"xl/_rels/workbook.xml.rels",
"xl/styles.xml",
"xl/workbook.xml",
"xl/worksheets/sheet1.xml",
])
expect(files.get("xl/workbook.xml")).toContain('<sheet name="Approved lines" sheetId="1" r:id="rId1"/>')
})
it("keeps text as text and a number as a number, in the cell it was given", () => {
const sheet = files.get("xl/worksheets/sheet1.xml") ?? ""
expect(sheet).toContain('<c r="A1" t="inlineStr" s="1"><is><t xml:space="preserve">Label</t></is></c>')
expect(sheet).toContain('<c r="B2" t="inlineStr"><is><t xml:space="preserve">12,50</t></is></c>')
expect(sheet).toContain('<c r="C2"><v>2</v></c>')
})
it("writes a formula-looking value as inert text, never as a formula", () => {
const sheet =
unzip(buildWorkbook("S", [['=HYPERLINK("http://x")', "+1+1", "@SUM(A1)", "-2+3"]])).get(
"xl/worksheets/sheet1.xml",
) ?? ""
expect(sheet).not.toContain("<f>")
expect(sheet.match(/t="inlineStr"/g)).toHaveLength(4)
expect(sheet).toContain("=HYPERLINK(&quot;http://x&quot;)")
})
it("escapes markup and drops characters XML cannot carry", () => {
const sheet = unzip(buildWorkbook("S", [["a<b>&\u0000c\u0007d"]])).get("xl/worksheets/sheet1.xml") ?? ""
expect(sheet).toContain("a&lt;b&gt;&amp;cd")
expect([...sheet].some((char) => char.charCodeAt(0) < 9)).toBe(false)
})
it("refuses a sheet name Excel would reject", () => {
for (const name of ["", "a/b", "x".repeat(32), "[a]", "a:b"]) {
expect(() => buildWorkbook(name, [])).toThrow(/sheet name/)
}
})
it("is byte-for-byte reproducible, so an export of the same lines is the same file", () => {
expect(Buffer.from(buildWorkbook("S", [["a"]])).equals(Buffer.from(buildWorkbook("S", [["a"]])))).toBe(true)
})
})