Files
docs/悦/货代SAAS平台后台/tests/verify-last-mile-detail-actions-hidden.cjs
T
2026-08-13 09:50:04 +08:00

96 lines
3.2 KiB
JavaScript

#!/usr/bin/env node
const fs = require('node:fs');
const path = require('node:path');
const html = fs.readFileSync(path.resolve(__dirname, '..', '货代SaaS平台原型.html'), 'utf8');
const failures = [];
function expect(condition, message) {
if (!condition) failures.push(message);
}
function section(startMarker, endMarker) {
const start = html.indexOf(startMarker);
const end = html.indexOf(endMarker, start + startMarker.length);
return start >= 0 && end > start ? html.slice(start, end) : '';
}
function functionSource(name) {
const start = html.indexOf(`function ${name}(`);
if (start < 0) return '';
const braceStart = html.indexOf('{', start);
let depth = 0;
let quote = '';
let 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 listPage = section(
'<div class="page" id="page-last-mile-orders">',
'<!-- ==================== OVERSEAS WAREHOUSE - 尾程订单详情'
);
const detailPage = section(
'<div class="page" id="page-last-mile-order-detail">',
'<!-- 尾程订单 - 入库计划 -->'
);
const renderDetail = functionSource('renderLastMileOrderDetail');
expect(Boolean(detailPage), '缺少尾程订单详情页面');
expect(Boolean(renderDetail), '缺少尾程订单详情渲染函数');
expect(!/lmo-detail-actions/.test(detailPage), '详情页不应保留操作按钮容器');
expect(!/lmo-detail-inbound-btn/.test(renderDetail), '详情渲染不应访问已删除的入库计划按钮');
expect(!/lmo-detail-outbound-btn/.test(renderDetail), '详情渲染不应访问已删除的出库计划按钮');
[
['openLastMileTransfer', '转仓'],
['openLastMileInboundPlan', '入库计划'],
['openLastMileConsolidate', '合托'],
['openLastMileAppointment', 'FBA预约'],
['openLastMileOutboundPlan', '出库计划']
].forEach(([handler, label]) => {
expect(!new RegExp(`onclick="${handler}\\(\\)"`).test(detailPage), `详情页不应显示${label}按钮`);
});
expect(/openLastMileBatchTransfer\(\)/.test(listPage), '列表页应保留批量转仓入口');
expect(/openLastMileBatchConsolidate\(\)/.test(listPage), '列表页应保留批量合托入口');
[
'modal-lmo-transfer',
'modal-lmo-inbound-plan',
'modal-lmo-consolidate',
'modal-lmo-fba-appointment',
'modal-lmo-outbound-plan'
].forEach(id => expect(html.includes(`id="${id}"`), `应保留操作弹框 ${id}`));
[
'openLastMileTransfer',
'openLastMileInboundPlan',
'openLastMileConsolidate',
'openLastMileAppointment',
'openLastMileOutboundPlan'
].forEach(name => expect(html.includes(`function ${name}(`), `应保留操作函数 ${name}`));
if (failures.length) {
console.error('LAST_MILE_DETAIL_ACTIONS_HIDDEN_CHECK_FAIL');
failures.forEach(failure => console.error(`- ${failure}`));
process.exitCode = 1;
} else {
console.log('LAST_MILE_DETAIL_ACTIONS_HIDDEN_CHECK_PASS');
}