187 lines
24 KiB
JavaScript
187 lines
24 KiB
JavaScript
'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 {randomUUID}=require('node:crypto'),Calc=require('../public/calculations');
|
|
const D='2026-10-23';
|
|
function order(id){return {id,revision:1,reviewed_revision:1,number:'XS-'+id,paper_number:id,date:D,status:'delivered',customer:'合成客户-'+id,salesperson:'助理',payment_account:'助理微信',
|
|
total:10000,rounding_mode:'cent',discount:0,goodsCost:0,knownGoodsCost:0,directCost:0,profit:10000,ownerCost:0,netReceived:10000,balance:0,costTransferred:0,profitTransferred:0,ownerDirect:0,settlementDue:10000,costDue:0,profitDue:10000,
|
|
lines:[],pendingFees:[],fee_items:[],payments:[],expenses:[],settlements:[],corrections:[],audit:[]};}
|
|
function book(ids=['C','A','B']){
|
|
const amounts=['sale','material','laborAndFees','unallocated','totalCost','profit','ownerCost','assistantCost'],counts=['orderCount','completedCount','draftCount','incompleteCount','afterSaleCount','recordCount','mg','pieces','unknownCosts','unknownCostCount','unknownProfitCount'];
|
|
const summary={...Object.fromEntries([...amounts,...counts].map(key=>[key,0])),orderCount:ids.length,completedCount:ids.length,knownCounts:Object.fromEntries(amounts.map(key=>[key,0])),unknownCounts:Object.fromEntries(amounts.map(key=>[key,0]))};
|
|
const rows=ids.map(id=>({...order(id),kind:'order',types:[],mg:0,pieces:1,sale:10000,material:0,laborAndFees:0,totalCost:0}));
|
|
if(rows.length>1)rows.splice(1,0,{kind:'afterSale',id:'not-an-order',status:'after_sale',date:D,project:'合成售后',customer:'合成客户',types:[],mg:0,pieces:0,sale:0,material:0,laborAndFees:0,totalCost:0,profit:0});
|
|
return {from:D,date:D,today:D,rows,summaryWithoutCancelled:summary,receiptsWithoutCancelled:{basis:'orderDate',filterScope:'matchingOrdersWithoutCancelled',from:D,date:D,receipt:0,refund:0,net:0,channels:['wechat','alipay','cash'].map(channel=>({channel,name:channel,receipt:0,refund:0,net:0}))}};
|
|
}
|
|
function deferred(){let resolve,reject;const promise=new Promise((yes,no)=>{resolve=yes;reject=no;});return {promise,resolve,reject};}
|
|
function node(extra={}){return {innerHTML:'',textContent:'',hidden:false,dataset:{},disabled:false,classList:{toggle(){}},setAttribute(){},scrollIntoView(){},querySelector(){return null;},...extra};}
|
|
function harness(ids=['C','A','B']){
|
|
const nodes=new Map(),handlers={},dialogHandlers={},calls=[],saved=new Map(),toasts=[],orders=new Map(ids.concat(['outside']).map(id=>[id,order(id)]));
|
|
for(const selector of ['#main','#order-content','#order-detail-navigation','#detail-error','#pending','#order-list','#order-book-summary','#order-book-count','#order-book-scope','#order-lock-activity','#order-book-people','#identity','#mode','#notice'])nodes.set(selector,node());
|
|
nodes.set('#detail-form',node({querySelector(selector){return selector==='form'&&this.innerHTML.includes('<form')?{id:'unsaved-form'}:null;}}));
|
|
const dialog=node({open:false,scrollTop:0,shows:0,addEventListener(type,handler){(dialogHandlers[type]??=[]).push(handler);},showModal(){this.open=true;this.shows++;},close(){const wasOpen=this.open;this.open=false;if(wasOpen)for(const handler of dialogHandlers.close||[])handler();}});nodes.set('#order-dialog',dialog);
|
|
const context=vm.createContext({LedgerCalc:Calc,crypto:{randomUUID},URLSearchParams,console,FormData:class{constructor(form){return Object.entries(form.data||{});}},setInterval(){},setTimeout(){},clearTimeout(){},
|
|
document:{querySelector:selector=>nodes.get(selector)||null,querySelectorAll:()=>[],addEventListener(type,handler){(handlers[type]??=[]).push(handler);}},window:{scrollTo(){}},
|
|
localStorage:{getItem:key=>saved.get(key)??null,setItem:(key,value)=>saved.set(key,String(value)),removeItem:key=>saved.delete(key)},sessionStorage:{getItem(){return null;},setItem(){}},
|
|
__calls:calls,__book:book(ids),__toasts:toasts,__api:async url=>{
|
|
if(url==='/api/state')return context.__state;
|
|
if(url.startsWith('/api/order-book?'))return context.__book;
|
|
const match=url.match(/^\/api\/orders\/([^/]+)(?:\/(cancellation|change))?$/);if(!match)throw new Error('意外接口:'+url);
|
|
if(match[2])return {eligible:true,canApprove:true,revision:orders.get(match[1])?.revision||1,pending:null,requests:[]};
|
|
if(!orders.has(match[1]))throw new Error('合成订单不存在');return orders.get(match[1]);
|
|
}});
|
|
const run=code=>vm.runInContext(code,context),json=code=>JSON.parse(JSON.stringify(run(code)));
|
|
for(const file of ['price-locks-ui.js','material-pools-ui.js','order-cancellations-ui.js','order-changes-ui.js','app.js'])run(fs.readFileSync(path.join(__dirname,'../public',file),'utf8').replace(/\ninit\(\);\s*$/,''));
|
|
run(`session={user:{id:'navigation-user',name:'麦麦',role:'owner'}};state={user:session.user,today:'${D}',pockets:['现货','金料'],orders:[{id:'outside'}]};tab='orders';getOrderBookFilters();api=async function(url,data,key){__calls.push({url,data,key});return await __api(url,data,key);};toast=function(message,error){__toasts.push({message,error});};`);
|
|
context.__state={...run('state'),mode:'trial',sync:{enabled:false,pending:0}};
|
|
async function submit(kind,data={}){const form={id:'action-form',dataset:{kind},data};nodes.get('#detail-form').innerHTML='<form>合成已保存动作</form>';for(const handler of handlers.submit||[])await handler({target:form,preventDefault(){}});}
|
|
function source(id,fromList=true){return {dataset:{action:'open-order',id,...(fromList?{orderBookVersion:String(run('orderBookDetailList.version'))}:{})},closest:selector=>fromList&&selector==='#order-list'?nodes.get('#order-list'):null};}
|
|
async function click(button){for(const handler of handlers.click||[])await handler({target:{closest:()=>button}});}
|
|
async function open(id){context.__source=source(id);return await run(`openOrder('${id}',{source:__source})`);}
|
|
function html(){return run('orderDetailNavigationHTML()');}
|
|
function disabled(action){const tag=html().match(new RegExp('<button[^>]*data-action="'+action+'"[^>]*>'));assert.ok(tag,'按钮应存在:'+action);return /\sdisabled(?:\s|>)/.test(tag[0]);}
|
|
async function load(nextBook){if(nextBook)context.__book=nextBook;await run('loadOrderBook()');}
|
|
return {run,json,context,nodes,dialog,dialogHandlers,calls,saved,toasts,orders,source,click,open,html,disabled,load,submit};
|
|
}
|
|
|
|
test('沿当前筛选结果的销售单显示顺序切换,跳过售后,首末禁用;只读且不修改订单',async()=>{
|
|
const h=harness(),before=JSON.stringify([...h.orders]);await h.load();await h.open('C');
|
|
assert.deepEqual(h.json('orderDetailNavigation.list.ids'),['C','A','B']);assert.match(h.html(),/>1 \/ 3</);assert.equal(h.disabled('order-detail-prev'),true);assert.equal(h.disabled('order-detail-next'),false);
|
|
assert.match(h.nodes.get('#order-content').innerHTML,/id="order-detail-navigation"/);
|
|
await h.run('navigateOrderDetail(1)');assert.equal(h.run('currentOrder.id'),'A');assert.match(h.html(),/>2 \/ 3</);
|
|
await h.run('navigateOrderDetail(1)');assert.equal(h.run('currentOrder.id'),'B');assert.equal(h.disabled('order-detail-next'),true);
|
|
const count=h.calls.length;await h.run('navigateOrderDetail(1)');assert.equal(h.calls.length,count);
|
|
await h.run('navigateOrderDetail(-1)');assert.equal(h.run('currentOrder.id'),'A');
|
|
assert.equal(h.calls.some(call=>call.data),false);assert.equal(h.calls.some(call=>/not-an-order|outside/.test(call.url)),false);assert.equal(h.saved.size,0);assert.equal(JSON.stringify([...h.orders]),before);
|
|
});
|
|
test('单条结果两侧都禁用,空结果不能沿用旧列表,日期搜索状态重新加载均替换上下文',async()=>{
|
|
const h=harness();await h.load();await h.open('C');await h.load(book(['B']));
|
|
assert.equal(h.run('orderDetailNavigation'),null);assert.match(h.html(),/列表已变化/);
|
|
await h.open('B');assert.match(h.html(),/>1 \/ 1</);assert.equal(h.disabled('order-detail-prev'),true);assert.equal(h.disabled('order-detail-next'),true);
|
|
await h.load(book([]));assert.deepEqual(h.json('orderBookDetailList.ids'),[]);assert.equal(h.run('orderDetailNavigation'),null);
|
|
});
|
|
test('按钮路由绑定本次列表;报表、锁价和全局审批入口即使同单仍不带入旧顺序',async()=>{
|
|
const h=harness();await h.load();await h.click(h.source('C'));assert.match(h.html(),/>1 \/ 3</);
|
|
await h.click({dataset:{action:'order-detail-next'},closest:()=>h.dialog});assert.equal(h.run('currentOrder.id'),'A');
|
|
for(const action of ['open-order','open-lock-order','open-cancellation-order','open-change-order']){
|
|
await h.open('C');await h.click({dataset:{action,id:'C'},closest:()=>null});assert.equal(h.run('currentOrder.id'),'C');assert.equal(h.run('orderDetailNavigation'),null);assert.equal(h.html(),'');
|
|
}
|
|
});
|
|
test('连续点击只发起一次切换,读取完成前保留当前单与位置',async()=>{
|
|
const h=harness();await h.load();await h.open('C');const wait=deferred(),read=h.context.__api;h.context.__api=url=>url==='/api/orders/A'?wait.promise:read(url);
|
|
const first=h.run('navigateOrderDetail(1)');await h.run('navigateOrderDetail(1)');await h.run('navigateOrderDetail(-1)');
|
|
assert.equal(h.run('currentOrder.id'),'C');assert.match(h.html(),/>1 \/ 3</);assert.equal(h.disabled('order-detail-next'),true);assert.equal(h.calls.filter(call=>call.url==='/api/orders/A').length,1);
|
|
wait.resolve(h.orders.get('A'));await first;assert.equal(h.run('currentOrder.id'),'A');assert.equal(h.disabled('order-detail-prev'),false);assert.equal(h.disabled('order-detail-next'),false);
|
|
});
|
|
test('读取失败保留原单、当前位置及审批资料,可重试;错误信息转义',async()=>{
|
|
const h=harness();await h.load();await h.open('C');const before=h.nodes.get('#order-content').innerHTML,cancellation=h.run('orderCancellationDetail'),read=h.context.__api;
|
|
h.context.__api=url=>{if(url==='/api/orders/A')throw new Error('<断线>');return read(url);};await h.run('navigateOrderDetail(1)');
|
|
assert.equal(h.run('currentOrder.id'),'C');assert.equal(h.run('orderCancellationDetail'),cancellation);assert.equal(h.nodes.get('#order-content').innerHTML,before);assert.match(h.html(),/<断线>/);assert.equal(h.disabled('order-detail-retry'),false);
|
|
h.context.__api=read;await h.run('retryOrderDetail()');assert.equal(h.run('currentOrder.id'),'A');assert.doesNotMatch(h.html(),/重试读取/);
|
|
});
|
|
test('非列表订单读取失败仍可重试,不会因没有列表永远禁用重试按钮',async()=>{
|
|
const h=harness();await h.run("openOrder('outside')");const read=h.context.__api;h.context.__api=url=>{if(url==='/api/orders/C')throw new Error('合成失败');return read(url);};
|
|
await h.run("openOrder('C')");assert.equal(h.run('currentOrder.id'),'outside');assert.equal(h.disabled('order-detail-retry'),false);
|
|
h.context.__api=read;await h.run('retryOrderDetail()');assert.equal(h.run('currentOrder.id'),'C');assert.equal(h.run('orderDetailNavigation'),null);
|
|
});
|
|
test('未收起表单、保存中和待恢复操作禁止切换,不丢填写内容也不发读取',async()=>{
|
|
const h=harness();await h.load();await h.open('C');const form=h.nodes.get('#detail-form');
|
|
for(const id of ['action-form','order-cancellation-form','order-change-form']){
|
|
form.innerHTML='<form id="'+id+'"><textarea>未保存</textarea></form>';const before=h.calls.length;await assert.rejects(h.run('navigateOrderDetail(1)'),/先保存或收起/);assert.equal(h.calls.length,before);assert.match(form.innerHTML,/未保存/);assert.match(h.nodes.get('#order-detail-navigation').innerHTML,/role="alert">[^<]*先保存或收起/);
|
|
}
|
|
form.innerHTML='';h.run('busy=true');await assert.rejects(h.run('navigateOrderDetail(1)'),/正在保存/);h.run('busy=false');
|
|
h.saved.set('mm-pending-navigation-user','{"url":"/api/orders/issue","key":"synthetic"}');await assert.rejects(h.run('navigateOrderDetail(1)'),/恢复原操作/);assert.equal(h.run('currentOrder.id'),'C');assert.equal(h.disabled('order-detail-next'),true);
|
|
});
|
|
test('切换途中弹出表单仍在响应提交前复查,不会被新详情覆盖',async()=>{
|
|
const h=harness();await h.load();await h.open('C');const wait=deferred(),read=h.context.__api;h.context.__api=url=>url==='/api/orders/A'?wait.promise:read(url);
|
|
const loading=h.run('navigateOrderDetail(1)');h.nodes.get('#detail-form').innerHTML='<form>保留我的内容</form>';wait.resolve(h.orders.get('A'));await loading;
|
|
assert.equal(h.run('currentOrder.id'),'C');assert.match(h.nodes.get('#detail-form').innerHTML,/保留我的内容/);assert.match(h.html(),/先保存或收起/);
|
|
});
|
|
test('×关闭、原生Escape及close使晚到的响应失效,不会重新打开弹窗',async()=>{
|
|
for(const kind of ['button','cancel','close']){
|
|
const h=harness();await h.load();await h.open('C');const wait=deferred(),read=h.context.__api;h.context.__api=url=>url==='/api/orders/A'?wait.promise:read(url);
|
|
const loading=h.run('navigateOrderDetail(1)');if(kind==='button')await h.click({dataset:{action:'close-dialog'},closest:()=>h.dialog});else if(kind==='cancel'){for(const handler of h.dialogHandlers.cancel)handler();h.dialog.close();}else h.dialog.close();
|
|
wait.resolve(h.orders.get('A'));await loading;assert.equal(h.dialog.open,false);assert.equal(h.dialog.shows,1);assert.equal(h.run('currentOrder'),null);assert.equal(h.run('orderDetailNavigation'),null);
|
|
}
|
|
});
|
|
test('列表更换、页签或账号变化时拒收旧响应,不影响已经显示的原单',async()=>{
|
|
for(const kind of ['list','tab','session','state']){
|
|
const h=harness();await h.load();await h.open('C');const wait=deferred(),read=h.context.__api;h.context.__api=url=>url==='/api/orders/A'?wait.promise:read(url);
|
|
const loading=h.run('navigateOrderDetail(1)');if(kind==='list')await h.load(book(['B']));else if(kind==='tab')h.run("tab='report'");else if(kind==='session')h.run("session={user:{id:'other-user'}}");else h.run("state={...state,user:{id:'other-user'}}");
|
|
wait.resolve(h.orders.get('A'));await loading;assert.equal(h.run('currentOrder.id'),'C');assert.equal(h.run('orderDetailLoad'),null);
|
|
}
|
|
});
|
|
test('后打开的订单优先,晚到的前一张单及其审批响应不能覆盖当前资料',async()=>{
|
|
const h=harness(),wait=deferred(),read=h.context.__api;h.context.__api=url=>url==='/api/orders/C'?wait.promise:read(url);
|
|
const old=h.run("openOrder('C')");await h.run("openOrder('A')");wait.resolve(h.orders.get('C'));await old;
|
|
assert.equal(h.run('currentOrder.id'),'A');assert.equal(h.run('orderCancellationDetail.id'),'A');assert.equal(h.run('orderChangeDetail.id'),'A');
|
|
});
|
|
test('mutate完成后重新应用首末禁用,原有全量按钮恢复不会解禁边界',async()=>{
|
|
const h=harness();await h.load();await h.open('C');const read=h.context.__api;h.context.__api=(url,data)=>data?{synthetic:true}:read(url);
|
|
await h.run("mutate('/synthetic-only',{test:true})");assert.equal(h.disabled('order-detail-prev'),true);assert.equal(h.disabled('order-detail-next'),false);
|
|
assert.match(h.nodes.get('#order-detail-navigation').innerHTML,/data-action="order-detail-prev"[^>]*disabled/);assert.equal(h.saved.size,0);
|
|
});
|
|
|
|
test('列表已复核标记只认可销售单当前正整数版本,售后与改后旧复核不误标且保留状态',async()=>{
|
|
const h=harness();
|
|
for(const row of [h.context.__book.rows[0],h.context.__book.rows[1]])Object.assign(row,{revision:3,reviewed_revision:3});
|
|
Object.assign(h.context.__book.rows[2],{revision:4,reviewed_revision:3,status:'cancelled'});h.context.__book.rows[3].status='returned';
|
|
await h.load();const html=h.nodes.get('#order-list').innerHTML;assert.equal((html.match(/class="order-review-status"/g)||[]).length,2);for(const status of ['已完成','已取消','已退货'])assert.ok(html.includes(status));
|
|
for(const row of [{revision:0,reviewed_revision:0},{revision:'3',reviewed_revision:'3'},{revision:3,reviewed_revision:'3'},{revision:4,reviewed_revision:3},{kind:'afterSale',revision:1,reviewed_revision:1},{revision:3}]){h.context.__row=row;assert.equal(h.run('orderReviewBadge(__row)'),'');}
|
|
});
|
|
|
|
test('真实复核保存刷新列表徽标,并保留原筛选与顺序的中间位置和上一下一条',async()=>{
|
|
const h=harness();h.orders.get('A').reviewed_revision=0;h.context.__book.rows.find(row=>row.id==='A').reviewed_revision=0;await h.load();await h.open('A');const oldList=h.run('orderDetailNavigation.list'),read=h.context.__api;
|
|
h.context.__api=(url,data)=>{if(url==='/api/orders/A/review'){assert.equal(data.revision,1);Object.assign(h.orders.get('A'),{revision:2,reviewed_revision:2});Object.assign(h.context.__book.rows.find(row=>row.id==='A'),{revision:2,reviewed_revision:2});return {id:'A'};}return read(url,data);};
|
|
await h.submit('review');assert.equal(h.run('pending()'),null);assert.notEqual(h.run('orderDetailNavigation.list'),oldList);assert.deepEqual(h.json('orderDetailNavigation.list.ids'),['C','A','B']);assert.match(h.html(),/>2 \/ 3</);assert.equal(h.run('currentOrder.reviewed_revision'),2);assert.equal(h.nodes.get('#detail-form').innerHTML,'');assert.equal(h.disabled('order-detail-prev'),false);assert.equal(h.disabled('order-detail-next'),false);assert.match(h.nodes.get('#order-list').innerHTML,/order-review-status/);
|
|
await h.run('navigateOrderDetail(1)');assert.equal(h.run('currentOrder.id'),'B');assert.equal(h.disabled('order-detail-next'),true);assert.equal(h.calls.filter(call=>call.data).length,1);
|
|
});
|
|
|
|
test('复核POST丢响应在原弹窗用同操作号恢复,成功后导航和已复核版本均保留',async()=>{
|
|
const h=harness();await h.load();await h.open('A');const read=h.context.__api;let committed=false;
|
|
h.context.__api=(url,data)=>{if(url==='/api/orders/A/review'){if(!committed){committed=true;Object.assign(h.orders.get('A'),{revision:2,reviewed_revision:2});throw new Error('合成响应中断');}return {id:'A'};}return read(url,data);};
|
|
await h.submit('review');assert.ok(h.run('pending()'));assert.match(h.nodes.get('#detail-error').innerHTML,/data-action="retry"/);assert.match(h.html(),/>2 \/ 3</);
|
|
await h.click({dataset:{action:'retry'},closest:()=>h.dialog});const writes=h.calls.filter(call=>call.url==='/api/orders/A/review');assert.equal(writes.length,2);assert.equal(writes[0].key,writes[1].key);assert.equal(h.run('pending()'),null);assert.match(h.html(),/>2 \/ 3</);assert.equal(h.run('currentOrder.reviewed_revision'),2);assert.equal(h.disabled('order-detail-next'),false);
|
|
});
|
|
|
|
test('复核已保存但state、列表或单据GET失败,只读重试恢复导航且不重发POST',async()=>{
|
|
for(const stage of ['state','book','detail']){
|
|
const h=harness();await h.load();await h.open('C');const read=h.context.__api;let committed=false,failed=false;
|
|
h.context.__api=(url,data)=>{if(url==='/api/orders/C/review'){committed=true;Object.assign(h.orders.get('C'),{revision:2,reviewed_revision:2});return {id:'C'};}if(committed&&!failed&&(stage==='state'&&url==='/api/state'||stage==='book'&&url.startsWith('/api/order-book?')||stage==='detail'&&url==='/api/orders/C')){failed=true;throw new Error('合成读取失败');}return read(url,data);};
|
|
await h.submit('review');assert.equal(failed,true,stage);assert.equal(h.run('pending()'),null);assert.ok(h.run('orderDetailRetry.savedContext'),stage);assert.equal(h.nodes.get('#detail-form').innerHTML,'');assert.equal(h.disabled('order-detail-retry'),false);
|
|
await h.run('retryOrderDetail()');assert.equal(h.run('currentOrder.reviewed_revision'),2);assert.match(h.html(),/>1 \/ 3</);assert.equal(h.disabled('order-detail-prev'),true);assert.equal(h.disabled('order-detail-next'),false);assert.equal(h.calls.filter(call=>call.data).length,1);
|
|
}
|
|
});
|
|
|
|
test('变更与取消审批成功回读保留列表导航,单据读取失败的原重读按钮也保留上下文',async()=>{
|
|
for(const kind of ['change','cancellation']){
|
|
const h=harness();await h.load();await h.open('A');const read=h.context.__api;let failed=false;h.context.__api=(url,data)=>{if(!failed&&url==='/api/orders/A'){failed=true;throw new Error('合成审批后读取失败');}return read(url,data);};
|
|
const save=kind==='change'?"finishOrderChangeSave('/api/order-changes/decision/approve',{}, {id:'A'})":"finishOrderCancellationSave('/api/order-cancellations/decision/reject',{}, {id:'A'})";
|
|
await h.run(save);assert.equal(h.run('currentOrder'),null);assert.ok(h.run('orderDetailRetry.savedContext'));await h.click({dataset:{action:'reload-order-'+kind,id:'A'},closest:()=>h.dialog});assert.equal(h.run('currentOrder.id'),'A');assert.match(h.html(),/>2 \/ 3</);assert.deepEqual(h.json('orderDetailNavigation.list.ids'),['C','A','B']);assert.equal(h.calls.filter(call=>call.data).length,0);
|
|
}
|
|
});
|
|
|
|
test('保存后订单离开原状态筛选则禁切并说明,不用旧列表;全局入口仍刷新原页且无导航',async()=>{
|
|
const h=harness();h.run("orderBookFilters.status='delivered'");await h.load();await h.open('C');h.context.__saved=h.run("captureOrderDetailReload('C')");h.context.__book=book(['A','B']);h.orders.get('C').status='returned';await h.run("refreshOrderDetailAfterSave('C',__saved)");assert.equal(h.run('currentOrder.id'),'C');assert.equal(h.run('orderDetailNavigation'),null);assert.match(h.html(),/不在原筛选结果/);assert.equal(h.disabled('order-detail-prev'),true);assert.equal(h.disabled('order-detail-next'),true);
|
|
const external=harness();await external.run("openOrder('outside')");external.run('refresh=async function(renderPage=true){__calls.push({renderPage});};');await external.run("refreshOrderDetailAfterSave('outside')");assert.equal(external.calls.find(call=>Object.hasOwn(call,'renderPage')).renderPage,true);assert.equal(external.run('orderDetailNavigation'),null);
|
|
});
|
|
|
|
test('保存后等待重读期间关闭、切页、换账号或改日期搜索状态都不恢复旧导航和弹窗',async()=>{
|
|
for(const kind of ['close','tab','session','state','date','search','status']){
|
|
const h=harness();await h.load();await h.open('C');const wait=deferred(),read=h.context.__api;h.context.__api=(url,data)=>url==='/api/state'?wait.promise:read(url,data);
|
|
const loading=h.run("refreshOrderDetailAfterSave('C')");if(kind==='close')h.dialog.close();else if(kind==='tab')h.run("tab='report'");else if(kind==='session')h.run("session={user:{id:'other'}}");else if(kind==='state')h.run("state={...state,user:{id:'other'}}");else if(kind==='date')h.run("orderBookFilters.mode='date';orderBookFilters.date='2026-10-22'");else if(kind==='search')h.run("orderBookFilters.q='另一个筛选'");else h.run("orderBookFilters.status='returned'");
|
|
wait.resolve(h.context.__state);await loading;assert.equal(h.calls.filter(call=>call.url==='/api/orders/C').length,1,kind);if(kind==='close'){assert.equal(h.dialog.open,false);assert.equal(h.run('currentOrder'),null);}if(kind==='state')assert.equal(h.run('state.user.id'),'other');
|
|
}
|
|
});
|
|
|
|
test('回收在客户旁醒目标记且只读展示,置换销售单标记一次,普通订单导航不混入回收',async()=>{
|
|
const h=harness(),b=h.context.__book,recovery={id:'recovery-only',kind:'recovery',recovery_id:'recovery-only',recovery_mode:'direct',status:'recovery',number:'HS202610230001',date:D,customer:'合成回收客户',types:['黄金回收'],mg:9900,pieces:0,cashPayment:899991,note:'合成回收备注'};
|
|
b.rows.find(row=>row.id==='A').recovery_mode='exchange';b.rows.find(row=>row.id==='A').recovery_id='swap-A';
|
|
b.displayRows=[b.rows[0],recovery,...b.rows.slice(1)];b.recoveryCount=1;
|
|
await h.load();const html=h.nodes.get('#order-list').innerHTML,match=html.match(/<tr class="order-recovery">([\s\S]*?)<\/tr>/);assert.ok(match);
|
|
assert.match(match[1],/order-book-customer-name">合成回收客户<\/strong><span class="order-book-recovery-badge">回收/);
|
|
assert.match(match[1],/data-action="recovery-open" data-id="recovery-only"/);assert.match(match[1],/data-action="recovery-print"/);assert.doesNotMatch(match[1],/data-action="open-order"|data-action="copy-order"|order-review-status/);
|
|
assert.match(match[1],/回收付款 ¥8,999.91/);assert.match(match[1],/9.900g.*折后克重/);assert.equal((match[1].match(/<span class="muted">—<\/span>/g)||[]).length,5);
|
|
assert.equal((html.match(/order-book-recovery-badge is-exchange">置换/g)||[]).length,1);assert.match(h.nodes.get('#order-book-count').textContent,/汇总 3 单 · 回收 1 笔/);assert.match(h.nodes.get('#order-book-summary').innerHTML,/另有回收 1 笔/);
|
|
assert.deepEqual(h.json('orderBookDetailList.ids'),['C','A','B']);await h.open('A');assert.match(h.html(),/>2 \/ 3</);
|
|
});
|