46 lines
4.6 KiB
JavaScript
46 lines
4.6 KiB
JavaScript
'use strict';
|
|
const {test}=require('node:test'),assert=require('node:assert/strict');
|
|
const {receipt,uppercaseMoney,settings}=require('../printing');
|
|
const sample={number:'MM-INTERNAL-UNIQUE',paper_number:'20261017003',date:'2026-10-17',customer:'示例客户',salesperson:'助理',status:'delivered',total:216750,discount:1000,received:216750,refunded:0,balance:0,paymentMethods:['支付宝'],note:'客户备注',lines:[{name:'足金999',unit:'g',quantity:2200,pricingMode:'auto',goldPrice:94000,laborRate:4500,laborMode:'gram',baseSale:216700,sale:217750,charges:[{name:'编绳',amount:1050}]}]};
|
|
test('人民币大写按整数分覆盖零、角分、跨万亿及连续零',()=>{
|
|
for(const [value,text] of [[0,'零元整'],[1,'零元壹分'],[10,'零元壹角'],[105,'壹元零伍分'],[115,'壹元壹角伍分'],[1000,'壹拾元整'],[216750,'贰仟壹佰陆拾柒元伍角'],[203400,'贰仟零叁拾肆元整'],[1000000,'壹万元整'],[1000100,'壹万零壹元整'],[1001000,'壹万零壹拾元整'],[100000001,'壹佰万元零壹分'],[10001000101,'壹亿零壹万零壹元零壹分'],[100000000000,'壹拾亿元整'],[100000000000000,'壹兆元整']])assert.equal(uppercaseMoney(value),text,String(value));
|
|
for(const invalid of [-1,1.1,NaN,Infinity,'100',Number.MAX_SAFE_INTEGER+1])assert.throws(()=>uppercaseMoney(invalid));
|
|
});
|
|
test('客户单只保留纸单号、最终金额大小写和经办人,不显示优惠与收退款汇总',()=>{
|
|
const html=receipt(sample);
|
|
for(const hidden of ['系统单号','MM-INTERNAL-UNIQUE','整单优惠','累计收款','累计退款','客户确认','待收款','待退款'])assert.ok(!html.includes(hidden),hidden);
|
|
for(const visible of ['纸单号:20261017003','合计金额','¥2167.50','贰仟壹佰陆拾柒元伍角','经办人:助理','附加:编绳','10.50','支付宝'])assert.ok(html.includes(visible),visible);
|
|
assert.equal((html.match(/<section class="sheet /g)||[]).length,1);
|
|
});
|
|
test('正常客户单不标注预订或交付状态,草稿、取消和退货保留提示',()=>{
|
|
for(const mode of ['full','overlay'])for(const status of ['confirmed','delivered']){
|
|
const html=receipt({...sample,status},{},mode);
|
|
for(const hidden of ['预订单','待交付','销售单 · 已交付'])assert.ok(!html.includes(hidden),status+' '+hidden);
|
|
assert.ok(html.includes('<div class="meta secondary"><span>收款方式:支付宝</span></div>'));
|
|
}
|
|
for(const [status,notice] of [['draft','草稿 · 未确认'],['returned','退货单 · 已退货'],['cancelled','取消单 · 已取消']]){
|
|
const html=receipt({...sample,status});assert.ok(html.includes(notice),status);assert.ok(html.includes('收款方式:支付宝'));
|
|
}
|
|
});
|
|
test('注意事项按最新要求去掉维修承诺,取消退货仍注明原单金额',()=>{
|
|
const html=receipt(sample);
|
|
for(const text of ['国家法定机构检测合格','如无质量问题,概不退换','票据、标签、证书','珠宝首饰保养须知','避免接触水银、铅等金属','漂白剂、涂改液','最好每天清水清洗','首饰质量监督检验中心鉴定','凭本票无条件退换货'])assert.ok(html.includes(text),text);
|
|
assert.ok(!html.includes('免费维修'));assert.ok(!html.includes('仅收取配件费用'));
|
|
for(const status of ['returned','cancelled'])assert.ok(receipt({...sample,status}).includes('原单成交额'));
|
|
});
|
|
test('单页模板接受紧凑纸张和长备注,所有商品与收费完整保留',()=>{
|
|
const lines=Array.from({length:60},(_,i)=>({...sample.lines[0],name:'测试商品'+i,charges:[{name:'附加服务'+i,amount:100}]}));
|
|
const html=receipt({...sample,lines,note:'长备注'.repeat(80)},settings({width:241,height:140,rows:12,rowHeight:16}));
|
|
assert.equal((html.match(/<section class="sheet /g)||[]).length,1);assert.ok(html.includes('测试商品59'));assert.ok(html.includes('附加服务59'));assert.ok(html.includes('长备注'.repeat(80)));assert.ok(!html.includes('overflow:hidden'));assert.ok(html.includes('/print.js'));
|
|
for(const mode of ['full','overlay']){
|
|
const printed=receipt({...sample,lines},{},mode);
|
|
const numbers=[...printed.matchAll(/<tr><td>([^<]+)<\/td>/g)].map(m=>m[1]);
|
|
assert.deepEqual(numbers,Array.from({length:120},(_,i)=>String(i+1)));
|
|
assert.ok(!printed.includes('免费维修'));assert.ok(!printed.includes('仅收取配件费用'));
|
|
}
|
|
});
|
|
|
|
test('旧格式纸单号打印时去掉日期间隔符,保留账内原编号',()=>{
|
|
const old={...sample,paper_number:'20261017-003'};const html=receipt(old);assert.ok(html.includes('纸单号:20261017003'));assert.ok(!html.includes('20261017-003'));assert.equal(old.paper_number,'20261017-003');
|
|
});
|