Files
SupplierSystem/src/utils/pickingLabelPrint.test.ts
T
雨天 4033863537
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(分拣): 标签版式与旧秤端一致(含二维码)
旧秤端打的就是:分拣标签 / 客户 / 品名 / 重量(斤) / 日期 + 右上角商品条码二维码及其下码文,且不印订单号。本次把小程序与 Web 的标签版式改回逐项对齐该版式(50x30mm @8dot/mm),二维码内容回到商品条码,Web 纸宽 58mm 改 50x30mm。
2026-10-13 18:37:03 +08:00

54 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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('品名:&lt;b&gt;大葱&lt;/b&gt;');
expect(html).toContain('a&amp;b');
expect(html).not.toContain('订单号');
});
});