import test from 'node:test' import assert from 'node:assert/strict' import { buildAssetLabelPrintHtml, buildRenderedLabelImagePrintHtml, formatLabelDate, splitCodeForDisplay } from '../src/services/labelDocument.js' test('splitCodeForDisplay 会优先按连接符拆分较长编码', () => { const lines = splitCodeForDisplay('JS-PC-210188888') assert.deepEqual(lines, ['JS-PC-', '210188888']) }) test('formatLabelDate 会统一输出 YYYY-MM-DD', () => { assert.equal(formatLabelDate('2026/3/5 09:00:00'), '2026-03-05') assert.equal(formatLabelDate('2026-03-25T00:00:00.000Z'), '2026-03-25') assert.equal(formatLabelDate(''), '') }) test('buildAssetLabelPrintHtml 会生成可直接静默打印的 60x40 标签文档', async () => { const html = await buildAssetLabelPrintHtml({ companyName: '常州简尚家具有限公司', items: [ { id: 1, equipment_code: 'JS-PC-2101', equipment_name: '办公主机', equipment_type: '主机', purchase_date: '2026-03-01T00:00:00.000Z', department: { name: '行政部' } } ] }) assert.match(html, /@page\s*\{\s*size:\s*60mm 40mm;/) assert.match(html, /常州简尚家具有限公司/) assert.match(html, /JS-PC-2101/) assert.match(html, /主机/) assert.match(html, /2026-03-01/) assert.match(html, /行政部/) assert.match(html, /data:image\/png;base64,/) }) test('buildRenderedLabelImagePrintHtml 会按网页成品 PNG 逐张分页,直接复用网页最终版式', () => { const html = buildRenderedLabelImagePrintHtml({ images: ['data:image/png;base64,ZmFrZS0x', 'data:image/png;base64,ZmFrZS0y'] }) assert.match(html, /@page\s*\{\s*size:\s*60mm 40mm;/) assert.equal((html.match(/class="print-page"/g) || []).length, 2) assert.match(html, /data:image\/png;base64,ZmFrZS0x/) assert.match(html, /data:image\/png;base64,ZmFrZS0y/) })