旧秤端打的就是:分拣标签 / 客户 / 品名 / 重量(斤) / 日期 + 右上角商品条码二维码及其下码文,且不印订单号。本次把小程序与 Web 的标签版式改回逐项对齐该版式(50x30mm @8dot/mm),二维码内容回到商品条码,Web 纸宽 58mm 改 50x30mm。
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
||
import { buildPickingLabelHtml, formatLabelWeightLine } from './pickingLabelPrint';
|
||
|
||
describe('formatLabelWeightLine(与旧秤端逐字一致)', () => {
|
||
it('重量单位统一换算为「斤」', () => {
|
||
expect(formatLabelWeightLine(12, '斤')).toBe('重量:12.00 斤');
|
||
expect(formatLabelWeightLine(6, 'kg')).toBe('重量:12.00 斤');
|
||
expect(formatLabelWeightLine(6, '公斤')).toBe('重量:12.00 斤');
|
||
expect(formatLabelWeightLine(1000, '克')).toBe('重量:2.00 斤');
|
||
});
|
||
|
||
it('计数单位展示数量', () => {
|
||
expect(formatLabelWeightLine(5, '瓶')).toBe('数量:5.00 瓶');
|
||
expect(formatLabelWeightLine(3, '')).toBe('数量:3.00 斤');
|
||
});
|
||
});
|
||
|
||
describe('buildPickingLabelHtml(分拣标签 · 浏览器打印)', () => {
|
||
it('50×30mm 纸宽,一签一分区', () => {
|
||
const html = buildPickingLabelHtml([{ itemName: '大葱', qty: 10, unit: '斤' }]);
|
||
expect(html).toContain('@page { size: 50.000mm 30.000mm; margin: 0; }');
|
||
expect(html).toContain('class="pick-label"');
|
||
expect(html).toContain('分拣标签');
|
||
});
|
||
|
||
it('多张标签 = 多页(一签一页)', () => {
|
||
const html = buildPickingLabelHtml([
|
||
{ itemName: 'a', qty: 1, unit: '斤' },
|
||
{ itemName: 'b', qty: 2, unit: '斤' },
|
||
]);
|
||
expect((html.match(/class="pick-label"/g) || []).length).toBe(2);
|
||
});
|
||
|
||
it('有 barcode 时内联二维码 SVG;无则不输出', () => {
|
||
const withQr = buildPickingLabelHtml([{ itemName: '大葱', qty: 1, unit: '斤', barcode: 'SKU-1' }]);
|
||
expect(withQr).toContain('class="t-qr"');
|
||
expect(withQr).toContain('<svg');
|
||
|
||
const withoutQr = buildPickingLabelHtml([{ itemName: '大葱', qty: 1, unit: '斤' }]);
|
||
expect(withoutQr).not.toContain('class="t-qr"');
|
||
expect(withoutQr).not.toContain('<svg');
|
||
});
|
||
|
||
it('字段带前缀、默认值与 HTML 转义;不出现订单号', () => {
|
||
const html = buildPickingLabelHtml([
|
||
{ itemName: '<b>大葱</b>', qty: 1, unit: '斤', companyName: '', barcode: 'a&b' },
|
||
]);
|
||
expect(html).toContain('客户:客户');
|
||
expect(html).toContain('品名:<b>大葱</b>');
|
||
expect(html).toContain('a&b');
|
||
expect(html).not.toContain('订单号');
|
||
});
|
||
});
|