Files
docs/悦/货代SAAS平台后台/tests/verify-fba-outbound-list-sku-info.cjs
T
2026-08-19 14:28:55 +08:00

80 lines
4.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 moduleHtml = fs.readFileSync(path.join(root, 'prototype-src', 'modules', '03-overseas-warehouse.html'), 'utf8');
const appJs = fs.readFileSync(path.join(root, 'prototype-src', 'app.js'), 'utf8');
const failures = [];
function getPage(pageId) {
const start = moduleHtml.indexOf(`<div class="page" id="page-${pageId}">`);
const end = start >= 0 ? moduleHtml.indexOf('<div class="page"', start + 20) : -1;
return start >= 0 ? moduleHtml.slice(start, end >= 0 ? end : moduleHtml.length) : '';
}
function getFunction(name) {
const match = new RegExp(`function\\s+${name}\\s*\\(`).exec(appJs);
if (!match) return '';
const next = /\nfunction\s+[A-Za-z_$][\w$]*\s*\(/.exec(appJs.slice(match.index + 1));
return appJs.slice(match.index, next ? match.index + 1 + next.index : appJs.length);
}
function requireMatch(source, pattern, label) {
if (!pattern.test(source)) failures.push(`missing ${label}`);
}
const listPage = getPage('fba-outbound-order');
const detailPage = getPage('fba-outbound-order-detail');
const listRenderer = getFunction('renderFbaOutboundOrder');
const detailOpener = getFunction('openFbaOutboundOrderDetail');
['SKU种数', '总托数', '总箱数', '总重量(kg)', '总体积(m3)'].forEach((field) => {
requireMatch(listPage, new RegExp(`>${field.replace(/[()]/g, '\\$&')}<\\/th>`), `列表列 ${field}`);
});
['货主', '目的仓', '转仓', '商品SKU', '中文品名'].forEach((field) => {
if (new RegExp(`>${field}<\\/th>`).test(listPage)) failures.push(`list retains removed field ${field}`);
});
['d.skuCount', 'd.palletTotal', 'd.boxes', 'd.netWt', 'd.volume'].forEach((field) => {
requireMatch(listRenderer, new RegExp(field.replace('.', '\\.'), 'g'), `列表渲染 ${field}`);
});
requireMatch(detailPage, /id="fbd-outbound-sku-title">托盘信息<\/div>/, '托盘信息模块标题');
requireMatch(detailPage, /id="fbd-outbound-sku-items"/, 'SKU 信息表体');
['SKU', '中文品名', '托盘号', '入仓码', '箱数', '重量', '体积'].forEach((field) => {
requireMatch(detailPage, new RegExp(`>${field.replace(/[()]/g, '\\$&')}<\\/th>`), `SKU 信息列 ${field}`);
});
requireMatch(detailOpener, /renderFbaOutboundSkuInfo\(d\.items\)/, '详情渲染 SKU 信息');
requireMatch(appJs, /function renderFbaOutboundSkuInfo\(/, 'SKU 信息渲染函数');
requireMatch(appJs, /function getFbaOutboundPalletRows\(/, '按托盘展开 SKU 函数');
requireMatch(appJs, /getFbaOutboundPalletRows\(item\)/, 'SKU 信息按托盘渲染');
requireMatch(appJs, /owner:/, '出库单货主字段');
requireMatch(appJs, /palletTotal:/, '出库单总托数字段');
requireMatch(appJs, /volume:/, '出库单总体积字段');
requireMatch(appJs, /pallets:/, 'SKU 明细托数字段');
requireMatch(appJs, /volume:/, 'SKU 明细体积字段');
requireMatch(getFunction('renderFbaOutboundSkuInfo'), /fbaDetailDisplay\(item\.sku\)/, '托盘渲染 SKU');
requireMatch(getFunction('renderFbaOutboundSkuInfo'), /fbaDetailDisplay\(item\.cnName\)/, '托盘渲染中文品名');
try {
const getPalletRows = new Function(`${getFunction('getFbaOutboundPalletRows')}\nreturn getFbaOutboundPalletRows;`)();
const rows = getPalletRows({sku:'SKU-A1001',cnName:'蓝牙耳机套件',palletNo:'PAL-A1001-01',inboundCode:'IC20260722001',pallets:2,boxes:5,weight:12,volume:1.5});
assert.equal(rows.length, 2);
assert.deepEqual(rows.map((row) => row.palletNo), ['PAL-A1001-01', 'PAL-A1001-02']);
assert.equal(rows.reduce((sum, row) => sum + row.boxes, 0), 5);
assert.equal(rows.reduce((sum, row) => sum + row.weight, 0), 12);
assert.equal(rows.reduce((sum, row) => sum + row.volume, 0), 1.5);
} catch (error) {
failures.push(`missing 按托盘拆分汇总行为: ${error.message}`);
}
if (failures.length) {
console.error('FBA_OUTBOUND_LIST_SKU_INFO_CHECK_FAIL');
failures.forEach((failure) => console.error(`- ${failure}`));
process.exitCode = 1;
} else {
console.log('FBA_OUTBOUND_LIST_SKU_INFO_CHECK_PASS');
}