42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { buildLocalBatchPrintHtml } from '../src/utils/localBatchPrint.ts'
|
|
|
|
const extractStyleBlock = (html: string) => {
|
|
const match = html.match(/<style>([\s\S]*?)<\/style>/)
|
|
return match?.[1] || ''
|
|
}
|
|
|
|
test('本地批量打印会为每张标签生成独立分页容器', () => {
|
|
const html = buildLocalBatchPrintHtml(
|
|
['data:image/png;base64,ZmFrZS0x', 'data:image/png;base64,ZmFrZS0y', 'data:image/png;base64,ZmFrZS0z'],
|
|
{
|
|
widthMm: 60,
|
|
heightMm: 40
|
|
}
|
|
)
|
|
|
|
const pageCount = (html.match(/class="print-page"/g) || []).length
|
|
const imageCount = (html.match(/class="qrcode-image"/g) || []).length
|
|
|
|
assert.equal(pageCount, 3, '每张标签都应拥有自己的分页容器')
|
|
assert.equal(imageCount, 3, '每张标签都应输出一张独立图片')
|
|
})
|
|
|
|
test('本地批量打印不再把 html/body 锁死为单页高度', () => {
|
|
const html = buildLocalBatchPrintHtml(['data:image/png;base64,ZmFrZS0x'], {
|
|
widthMm: 60,
|
|
heightMm: 40
|
|
})
|
|
|
|
const styles = extractStyleBlock(html)
|
|
const htmlBodyBlock = styles.match(/html, body\s*\{([\s\S]*?)\}/)?.[1] || ''
|
|
const printPageBlock = styles.match(/\.print-page\s*\{([\s\S]*?)\}/)?.[1] || ''
|
|
|
|
assert.doesNotMatch(htmlBodyBlock, /overflow\s*:\s*hidden/i)
|
|
assert.doesNotMatch(htmlBodyBlock, /height\s*:\s*40mm/i)
|
|
assert.match(printPageBlock, /break-after\s*:\s*page/i)
|
|
assert.match(printPageBlock, /page-break-after\s*:\s*always/i)
|
|
})
|