Files
docs/悦/货代SAAS平台后台/tests/verify-last-mile-pending-direct-actions.cjs
T
2026-08-12 19:11:56 +08:00

58 lines
2.8 KiB
JavaScript

#!/usr/bin/env node
const fs=require('node:fs');
const path=require('node:path');
const vm=require('node:vm');
const html=fs.readFileSync(path.resolve(__dirname,'..','货代SaaS平台原型.html'),'utf8');
const failures=[];
function expect(condition,message){if(!condition)failures.push(message);}
function functionSource(name){
const start=html.indexOf(`function ${name}(`);
if(start<0)return '';
const braceStart=html.indexOf('{',start);
let depth=0,quote='',escaped=false;
for(let index=braceStart;index<html.length;index+=1){
const char=html[index];
if(quote){
if(escaped)escaped=false;
else if(char==='\\')escaped=true;
else if(char===quote)quote='';
continue;
}
if(char==="'"||char==='"'||char==='`'){quote=char;continue;}
if(char==='{')depth+=1;
if(char==='}'&&--depth===0)return html.slice(start,index+1);
}
return '';
}
const directActions=functionSource('renderLastMileDirectActions');
const renderList=functionSource('renderLastMileOrders');
const switchTab=functionSource('switchLastMileStatusTab');
expect(Boolean(directActions),'缺少 renderLastMileDirectActions 函数');
expect(/openLastMileOrderDetail/.test(directActions),'待分配应直接显示查看');
expect(/openLastMileTransfer/.test(directActions),'待分配应直接显示转仓');
expect(/openLastMileInboundPlan/.test(directActions),'待分配应直接显示入库计划');
expect(!/more-dropdown/.test(directActions),'待分配直显操作不应包含下拉菜单');
expect(!/openLastMileConsolidate|openLastMileAppointment|openLastMileOutboundPlan/.test(directActions),'待分配直显操作不应包含其他操作');
expect(/currentLastMileTab\s*===\s*'待分配'/.test(renderList)&&/renderLastMileDirectActions/.test(renderList),'列表应仅在待分配页签使用直显操作');
expect(/lmo-hide-operation/.test(switchTab)&&/currentLastMileTab\s*===\s*'全部'/.test(switchTab),'全部页签应继续隐藏操作列');
if(directActions){
try{
const context={};vm.createContext(context);vm.runInContext(directActions,context,{timeout:1000});
const normal=context.renderLastMileDirectActions({no:'LMO-1'},false);
const locked=context.renderLastMileDirectActions({no:'LMO-2'},true);
expect(/openLastMileInboundPlan\('LMO-1'\)/.test(normal),'未锁定订单的入库计划应可点击');
expect(!/openLastMileInboundPlan/.test(locked)&&/清关已完成/.test(locked),'锁定订单的入库计划应禁用并显示原因');
}catch(error){failures.push(`直显操作行为执行失败:${error.message}`);}
}
if(failures.length){
console.error('LAST_MILE_PENDING_DIRECT_ACTIONS_CHECK_FAIL');
failures.forEach(failure=>console.error(`- ${failure}`));
process.exitCode=1;
}else console.log('LAST_MILE_PENDING_DIRECT_ACTIONS_CHECK_PASS');