Files
docs/悦/货代SAAS平台后台/tests/verify-last-mile-inbound-pallet-outsourcing.cjs
T
2026-08-22 09:50:50 +08:00

56 lines
2.9 KiB
JavaScript

#!/usr/bin/env node
const fs = require('node:fs');
const path = require('node:path');
const root = path.resolve(__dirname, '..');
const html = fs.readFileSync(path.join(root, 'prototype-src/modules/03-overseas-warehouse.html'), 'utf8');
const app = fs.readFileSync(path.join(root, 'prototype-src/app.js'), 'utf8');
const failures = [];
const expect = (condition, message) => { if (!condition) failures.push(message); };
const functionSource = name => {
const start = app.indexOf(`function ${name}(`);
if (start < 0) return '';
const next = app.slice(start + 1).match(/\nfunction\s+[A-Za-z_$][\w$]*\s*\(/);
return app.slice(start, next ? start + 1 + next.index : app.length);
};
const inboundPlanModal = html.slice(
html.indexOf('id="modal-lmo-inbound-plan"'),
html.indexOf('<!-- 尾程订单 - 合托 -->')
);
expect(/id="lmo-inbound-pallet-type"/.test(inboundPlanModal), '入库计划缺少托盘类型');
expect(/<option[^>]*value="标准托盘"[^>]*selected[^>]*>标准托盘<\/option>/.test(inboundPlanModal), '托盘类型默认值不是标准托盘');
for (const type of ['标准托盘', '木托盘', '纸托盘']) {
expect(inboundPlanModal.includes(`>${type}</option>`), `缺少${type}选项`);
}
expect(/id="lmo-inbound-outsourced"[^>]*type="checkbox"/.test(inboundPlanModal), '入库计划缺少是否外配复选框');
expect(!/id="lmo-inbound-(?:pallet-type|outsourced)"[^>]*required/.test(inboundPlanModal), '新增字段不应必填');
const inboundTable = html.slice(html.indexOf('id="page-fba-inbound-order"'), html.indexOf('id="modal-fbio-appointment"'));
expect(/>托盘类型<\/th>/.test(inboundTable), '入库单列表缺少托盘类型列');
expect(/>是否外配<\/th>/.test(inboundTable), '入库单列表缺少是否外配列');
expect(/id="fbio-edit-pallet-type"/.test(html), '入库单编辑缺少托盘类型');
expect(/id="fbio-edit-outsourced"/.test(html), '入库单编辑缺少是否外配');
for (const name of ['openLastMileInboundPlan', 'saveLastMileInboundPlan', 'renderFbaInboundOrder', 'openFbioEditModal', 'saveFbioEdit', 'openFbaInboundOrderDetail']) {
const source = functionSource(name);
expect(/palletType|getInboundPalletType/.test(source), `${name} 未读写托盘类型`);
expect(/isOutsourced|isInboundOutsourced|formatInboundOutsourced/.test(source), `${name} 未读写是否外配`);
}
const savePlan = functionSource('saveLastMileInboundPlan');
expect(/palletType,isOutsourced/.test(savePlan), '入库计划未显式保存并同步两个字段');
const detail = functionSource('renderLastMileOrderDetail');
expect(/lmoInfo\('托盘类型'/.test(detail), '尾程详情未展示托盘类型');
expect(/lmoInfo\('是否外配'/.test(detail), '尾程详情未展示是否外配');
if (failures.length) {
console.error('LAST_MILE_INBOUND_PALLET_OUTSOURCING_CHECK_FAIL');
failures.forEach(message => console.error(`- ${message}`));
process.exitCode = 1;
} else {
console.log('LAST_MILE_INBOUND_PALLET_OUTSOURCING_CHECK_PASS');
}