固定销售单据为241×140毫米并自动缩放长单

This commit is contained in:
summer committed 2026-10-22 12:59:56 +08:00
1 parent b9154a752d
commit 5265a2e568
8 files changed
+70 -24

No files matched your search

+11 -8
View File
@@ -1,6 +1,6 @@
'use strict';
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path'),vm=require('node:vm');
const {receipt,settings}=require('../printing');
const {receipt,settings,defaults}=require('../printing');
const script=fs.readFileSync(path.join(__dirname,'../public/print.js'),'utf8');
const mm=value=>Number.parseFloat(value)*96/25.4;
function classList(initial=[]){const values=new Set(initial);return {add:value=>values.add(value),remove:value=>values.delete(value),contains:value=>values.has(value)};}
@@ -31,15 +31,18 @@ function page({long=false,fontsReady=true}={}){
vm.runInNewContext(script,{window,document});
return {body,content,foreignObject,canvas,button,status,window,media,events,mediaEvents,click:()=>clicks.get('click')()};
}
test('打印纸型和方向由浏览器决定,旧宽高只保留为预览及来源排版尺寸',()=>{
test('默认、旧设置和客户端传入宽高均固定为241×140mm横版,不能放大到A4页面',()=>{
const sample={lines:[],total:0,paper_number:'20261022001',status:'delivered'};
for(const raw of [{width:241,height:140},{width:241,height:279},{width:140,height:241}]){
assert.equal(defaults.width,241);assert.equal(defaults.height,140);
for(const raw of [{},{width:241,height:140},{width:241,height:279},{width:140,height:241},{width:300,height:400},{width:'无效旧宽度',height:-1},{width:null,height:''}]){
const before=JSON.stringify(raw);
const saved=settings(raw),html=receipt(sample,saved),print=html.slice(html.indexOf('@page'));
assert.equal(saved.width,raw.width);assert.equal(saved.height,raw.height);
assert.match(print,/@page\{size:auto;margin:0\}/);assert.match(print,/html,body\{width:auto;height:auto/);
assert.match(print,/\.sheet\{width:100%;height:calc\(100vh - 1px\)/);
assert.doesNotMatch(print,/@page\{size:\d|rotate\(|landscape|portrait/);
assert.match(html,new RegExp(`data-layout-width-mm="${raw.width-24}"`));
assert.equal(saved.width,241);assert.equal(saved.height,140);assert.equal(JSON.stringify(raw),before);
assert.match(print,/@page\{size:241mm 140mm;margin:0\}/);
assert.match(print,/\.sheet\{width:241mm;height:calc\(140mm - 1px\);max-width:241mm;max-height:140mm/);
assert.doesNotMatch(print,/size:auto|100vh|100vw|rotate\(/);
assert.match(html,/\.sheet\{width:241mm;height:140mm/);
assert.match(html,/data-layout-width-mm="217" data-layout-height-mm="120"/);
assert.match(html,/preserveAspectRatio="xMinYMin meet"/);
}
});