92 lines
4.8 KiB
JavaScript
92 lines
4.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const prototypePath = path.resolve(__dirname, '..', 'index.html');
|
|
const html = fs.readFileSync(prototypePath, 'utf8');
|
|
const failures = [];
|
|
|
|
function escapeRegExp(value) {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
}
|
|
|
|
function requireMatch(pattern, label, source = html) {
|
|
if (!pattern.test(source)) failures.push(`missing ${label}`);
|
|
}
|
|
|
|
function requireNotMatch(pattern, label, source = html) {
|
|
if (pattern.test(source)) failures.push(`unexpected ${label}`);
|
|
}
|
|
|
|
function getFunctionSource(functionName) {
|
|
const declaration = new RegExp(`function\\s+${escapeRegExp(functionName)}\\s*\\(`).exec(html);
|
|
if (!declaration) return '';
|
|
|
|
const remaining = html.slice(declaration.index + declaration[0].length);
|
|
const nextFunction = /\n\s*function\s+[A-Za-z_$][\w$]*\s*\(/.exec(remaining);
|
|
const end = nextFunction
|
|
? declaration.index + declaration[0].length + nextFunction.index
|
|
: html.length;
|
|
return html.slice(declaration.index, end);
|
|
}
|
|
|
|
const detailPageStart = html.indexOf('<div class="page" id="page-outbound-vehicle-detail">');
|
|
const detailPageEnd = detailPageStart >= 0
|
|
? html.indexOf('<div class="page"', detailPageStart + 20)
|
|
: -1;
|
|
const detailPage = detailPageStart >= 0
|
|
? html.slice(detailPageStart, detailPageEnd > detailPageStart ? detailPageEnd : html.length)
|
|
: '';
|
|
const listRenderer = getFunctionSource('renderOutboundVehicle');
|
|
const openDetail = getFunctionSource('openOutboundVehicleDetail');
|
|
const backToList = getFunctionSource('backToOutboundVehicles');
|
|
|
|
requireMatch(/id=["']page-outbound-vehicle-detail["']/, '排车详情独立页面');
|
|
requireMatch(/排车详情/, '排车详情标题', detailPage);
|
|
requireMatch(/id=["']ovd-vehicle-no["']/, '排车单号头部节点', detailPage);
|
|
requireMatch(/id=["']ovd-status["']/, '车辆状态头部节点', detailPage);
|
|
requireMatch(/车辆信息/, '车辆信息模块', `${detailPage}\n${openDetail}`);
|
|
requireMatch(/排车信息/, '排车信息模块', `${detailPage}\n${openDetail}`);
|
|
requireMatch(/单据信息/, '单据信息模块', `${detailPage}\n${openDetail}`);
|
|
requireMatch(/关联订单明细/, '关联订单明细模块', detailPage);
|
|
['订单号', '重量(kg)', '托数', '目的FBA仓', '体积(m³)', '集装箱号'].forEach((field) => {
|
|
requireMatch(new RegExp(escapeRegExp(field)), `关联订单字段“${field}”`, detailPage);
|
|
});
|
|
|
|
requireMatch(
|
|
/openOutboundVehicleDetail\s*\(\s*v\.vehicleNo\s*\)/,
|
|
'列表详情入口传入 v.vehicleNo',
|
|
listRenderer,
|
|
);
|
|
requireMatch(/document\.createElement\s*\(\s*['"]tr['"]\s*\)/, '列表使用 DOM API 创建行', listRenderer);
|
|
requireMatch(/\.textContent\s*=/, '列表动态值通过 textContent 写入', listRenderer);
|
|
requireMatch(/addEventListener\s*\(\s*['"]click['"]/, '列表操作使用事件监听器', listRenderer);
|
|
requireNotMatch(/\.innerHTML\s*=/, '列表通过 innerHTML 拼接动态字段', listRenderer);
|
|
requireNotMatch(/onclick\s*=/, '列表通过内联 onclick 拼接排车单号', listRenderer);
|
|
requireMatch(/outboundVehicleData\.find\(/, '按排车单号查找记录', openDetail);
|
|
requireMatch(/showToast\s*\(\s*['"]未找到该排车记录['"]\s*,\s*['"]error['"]\s*\)/, '记录不存在错误提示', openDetail);
|
|
requireMatch(/lmoEsc\s*\(/, '详情动态文本转义', openDetail);
|
|
requireMatch(/['"]待发车['"]\s*:\s*['"]tag-orange['"]/, '待发车状态颜色', openDetail);
|
|
requireMatch(/['"]配送中['"]\s*:\s*['"]tag-blue['"]/, '配送中状态颜色', openDetail);
|
|
requireMatch(/['"]已送达['"]\s*:\s*['"]tag-green['"]/, '已送达状态颜色', openDetail);
|
|
requireMatch(/['"]已返回['"]\s*:\s*['"]tag-gray['"]/, '已返回状态颜色', openDetail);
|
|
requireMatch(/outboundVehicleListScrollTop\s*=\s*[^;]*\.scrollTop/, '进入详情前保存列表滚动位置', openDetail);
|
|
requireMatch(/\.scrollTop\s*=\s*0/, '进入详情时滚动详情容器到顶部', openDetail);
|
|
requireMatch(/showExistingFbaList\s*\(\s*['"]outbound-vehicle['"]\s*\)/, '返回时保留排车列表状态', backToList);
|
|
requireMatch(/\.scrollTop\s*=\s*outboundVehicleListScrollTop/, '返回时恢复列表滚动位置', backToList);
|
|
requireMatch(/\.fbd-head>div:first-child\{min-width:0\}/, '详情头部允许长文本收缩');
|
|
requireMatch(/\.fbd-subtitle strong\{[^}]*overflow-wrap:anywhere/, '详情编号支持长文本换行');
|
|
requireMatch(/id=["']fbio-schedule-vehicle-no["'][^>]*maxlength=["']64["']/, '排车单号输入长度限制');
|
|
requireMatch(/createdAt\s*:/, '排车示例创建时间');
|
|
requireMatch(/updatedAt\s*:/, '排车示例更新时间');
|
|
requireMatch(/remark\s*:/, '排车示例备注');
|
|
|
|
if (failures.length) {
|
|
console.error('OUTBOUND_VEHICLE_DETAIL_CHECK_FAIL');
|
|
failures.forEach((failure) => console.error(`- ${failure}`));
|
|
process.exitCode = 1;
|
|
} else {
|
|
console.log('OUTBOUND_VEHICLE_DETAIL_CHECK_PASS');
|
|
}
|