106 lines
5.1 KiB
JavaScript
106 lines
5.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const html = [
|
|
fs.readFileSync(path.join(root, 'prototype-src', 'modules', '03-overseas-warehouse.html'), 'utf8'),
|
|
fs.readFileSync(path.join(root, 'prototype-src', 'app.js'), 'utf8'),
|
|
].join('\n');
|
|
const failures = [];
|
|
|
|
function requireMatch(pattern, label, source = html) {
|
|
if (!pattern.test(source)) failures.push(`missing ${label}`);
|
|
}
|
|
|
|
function getFunctionSource(name, source = html) {
|
|
const match = new RegExp(`function\\s+${name}\\s*\\([^)]*\\)\\s*\\{`).exec(source);
|
|
if (!match) throw new Error(`function ${name} not found`);
|
|
|
|
const start = source.indexOf('{', match.index);
|
|
let depth = 0;
|
|
for (let index = start; index < source.length; index += 1) {
|
|
if (source[index] === '{') depth += 1;
|
|
if (source[index] === '}') depth -= 1;
|
|
if (depth === 0) return source.slice(match.index, index + 1);
|
|
}
|
|
throw new Error(`function ${name} has unbalanced braces`);
|
|
}
|
|
|
|
const pageStart = html.indexOf('<div class="page" id="page-fba-outbound-order">');
|
|
const pageEnd = html.indexOf('<!-- ==================== FBA RETURN - 托盘管理', pageStart);
|
|
const page = pageStart >= 0 && pageEnd > pageStart ? html.slice(pageStart, pageEnd) : '';
|
|
|
|
requireMatch(/onclick="openFbaOutboundCreate\(\)"[^>]*>\+ 一件代发出库<\/button>/, '一件代发出库入口按钮', page);
|
|
requireMatch(/>出库类型<\/th>/, '出库类型列表列', page);
|
|
requireMatch(/>SKU种数<\/th>[\s\S]{0,200}>总托数<\/th>/, 'SKU 汇总列表列', page);
|
|
requireMatch(/>总箱数<\/th>[\s\S]{0,200}>总重量\(kg\)<\/th>[\s\S]{0,200}>总体积\(m3\)<\/th>/, '箱重体积汇总列表列', page);
|
|
requireMatch(/id="modal-fboo-create"/, '新增出库单弹窗');
|
|
requireMatch(/id="modal-fboo-create"[\s\S]*?<div class="modal-header"><span>一件代发出库<\/span>/, '一件代发出库弹窗标题', page);
|
|
const createTypeMatch = page.match(/<select\b(?=[^>]*\bid="fboo-create-type")[^>]*>([\s\S]*?)<\/select>/);
|
|
if (!createTypeMatch) {
|
|
failures.push('missing 一件代发出库类型字段');
|
|
} else {
|
|
requireMatch(/^\s*<option value="一件代发" selected>一件代发<\/option>\s*$/, '仅一件代发的出库类型选项', createTypeMatch[1]);
|
|
}
|
|
requireMatch(/id="fboo-create-destination"/, '目的信息字段');
|
|
requireMatch(/id="tbody-fboo-create-inventory"/, '可选库存表体');
|
|
requireMatch(/id="fboo-selected-count"/, '已选商品统计');
|
|
requireMatch(/id="fboo-selected-qty"/, '出库总数量统计');
|
|
requireMatch(/id="fboo-create-remark"/, '出库备注字段');
|
|
|
|
requireMatch(/outboundType\s*:/, '出库类型数据字段');
|
|
requireMatch(/totalQty\s*:/, '出库数量数据字段');
|
|
requireMatch(/function openFbaOutboundCreate\(/, '打开新增出库单函数');
|
|
requireMatch(/function renderFbaOutboundInventory\(/, '渲染可选库存函数');
|
|
requireMatch(/function toggleFbaOutboundItem\(/, '切换出库商品函数');
|
|
requireMatch(/function updateFbaOutboundSummary\(/, '更新出库汇总函数');
|
|
requireMatch(/function saveFbaOutboundOrder\(/, '保存新增出库单函数');
|
|
requireMatch(/quantity\s*>\s*available/, '超可用库存拦截');
|
|
requireMatch(/warehouseStockData[\s\S]{0,500}availQty\s*-=\s*item\.quantity/, '保存后扣减可用库存');
|
|
requireMatch(/fbaOutboundOrderData\.unshift\(/, '新增记录写入出库单数据');
|
|
requireMatch(/d\.outboundType/, '列表渲染出库类型');
|
|
requireMatch(/d\.skuCount/, '列表渲染 SKU 种数');
|
|
requireMatch(/d\.palletTotal/, '列表渲染总托数');
|
|
|
|
try {
|
|
const elements = {
|
|
'fboo-create-type': { value: '头程' },
|
|
'fboo-create-destination': { value: '旧目的信息', disabled: true, placeholder: '' },
|
|
'fboo-create-remark': { value: '旧备注' },
|
|
'fboo-destination-label': { textContent: '' },
|
|
};
|
|
const modalCalls = [];
|
|
const functions = new Function(
|
|
'document',
|
|
'renderFbaOutboundInventory',
|
|
'showModal',
|
|
`${getFunctionSource('fbooDestinationConfig')}\n${getFunctionSource('updateFbaOutboundDestinationHint')}\n${getFunctionSource('openFbaOutboundCreate')}\nreturn { openFbaOutboundCreate, updateFbaOutboundDestinationHint };`,
|
|
)(
|
|
{ getElementById: (id) => elements[id] },
|
|
() => {},
|
|
(id) => modalCalls.push(id),
|
|
);
|
|
|
|
functions.openFbaOutboundCreate();
|
|
assert.equal(elements['fboo-create-type'].value, '一件代发');
|
|
assert.equal(elements['fboo-destination-label'].textContent, '收件信息 *');
|
|
assert.equal(elements['fboo-create-destination'].disabled, false);
|
|
assert.equal(elements['fboo-create-destination'].placeholder, '请输入收件人、电话和地址');
|
|
assert.equal(elements['fboo-create-destination'].value, '');
|
|
assert.equal(elements['fboo-create-remark'].value, '');
|
|
assert.deepEqual(modalCalls, ['modal-fboo-create']);
|
|
} catch (error) {
|
|
failures.push(`missing 一件代发出库创建行为: ${error.message}`);
|
|
}
|
|
|
|
if (failures.length) {
|
|
console.error('FBA_OUTBOUND_CREATE_CHECK_FAIL');
|
|
failures.forEach((failure) => console.error(`- ${failure}`));
|
|
process.exitCode = 1;
|
|
} else {
|
|
console.log('FBA_OUTBOUND_CREATE_CHECK_PASS');
|
|
}
|