GuDingZiChan/print-agent/tests/label-document.test.mjs
WuYongJie 0dc3c09315 feat(资产与打印): 提交近期借还盘点与打印助手源码
- 提交借用单缺失异常处理、扫码借还搜索与站内消息快捷处理源码
- 提交盘点范围、多终端打印、组织同步与认证模式相关源码
- 提交 .NET/Node 打印助手及版本清单源码
2026-03-27 20:18:31 +08:00

47 lines
1.4 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import {
buildAssetLabelPrintHtml,
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,/)
})