53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { strFromU8, unzipSync } from "fflate";
|
|
import { buildRecoveryWorkbook } from "../lib/recovery-workbook.ts";
|
|
|
|
const tinyPng = Uint8Array.from([
|
|
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
|
0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
|
]);
|
|
|
|
test("creates an xlsx archive whose pictures are embedded in worksheet cells", () => {
|
|
const workbook = buildRecoveryWorkbook({
|
|
sheetName: "数据回收",
|
|
headers: ["序号", "标题", "原图", "笔记截图"],
|
|
columnWidths: [8, 24, 24, 24],
|
|
rows: [
|
|
{
|
|
cells: [1, "测试笔记", "见图", "见图"],
|
|
images: [
|
|
{
|
|
column: 2,
|
|
image: {
|
|
bytes: tinyPng,
|
|
contentType: "image/png",
|
|
width: 1,
|
|
height: 1,
|
|
description: "原图1",
|
|
},
|
|
},
|
|
{
|
|
column: 3,
|
|
image: {
|
|
bytes: tinyPng,
|
|
contentType: "image/png",
|
|
width: 1,
|
|
height: 1,
|
|
description: "发布截图",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
const archive = unzipSync(workbook);
|
|
|
|
assert.ok(archive["xl/media/image1.png"]);
|
|
assert.ok(archive["xl/media/image2.png"]);
|
|
assert.match(strFromU8(archive["xl/worksheets/sheet1.xml"]), /<drawing r:id="rId1"\/>/);
|
|
assert.match(strFromU8(archive["xl/drawings/drawing1.xml"]), /oneCellAnchor/);
|
|
assert.match(strFromU8(archive["xl/drawings/_rels/drawing1.xml.rels"]), /image2\.png/);
|
|
});
|