Files
docs/悦/货代SAAS平台后台/tests/verify-fba-receivable-fee-detail.cjs
T
2026-08-19 14:28:55 +08:00

82 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
const fs = require('node:fs');
const path = require('node:path');
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 = [];
const expect = (condition, message) => { if (!condition) failures.push(message); };
function getPage(pageId, nextMarker) {
const start = moduleHtml.indexOf(`<div class="page" id="page-${pageId}">`);
const end = moduleHtml.indexOf(nextMarker, start);
return start >= 0 && end > start ? moduleHtml.slice(start, end) : '';
}
const inboundDetail = getPage(
'fba-inbound-order-detail',
'<!-- ==================== OVERSEAS WAREHOUSE - 出库单详情',
);
const outboundDetail = getPage(
'fba-outbound-order-detail',
'<!-- ==================== OVERSEAS WAREHOUSE - 换标单详情',
);
expect(/id="fbd-inbound-fee-title">应收费用明细<\/div>/.test(inboundDetail), '入库单费用区块未改为应收费用明细');
expect(/暂无应收费用明细/.test(inboundDetail), '入库单缺少应收费用空态');
expect(/应收费用合计(USD)/.test(inboundDetail), '入库单缺少应收费用合计');
expect(/id="fbd-outbound-fee-title">应收费用明细<\/div>/.test(outboundDetail), '出库单缺少应收费用明细区块');
expect(/id="fbd-outbound-fees"/.test(outboundDetail), '出库单缺少应收费用表体');
expect(/id="fbd-outbound-fee-total"/.test(outboundDetail), '出库单缺少应收费用合计节点');
expect(/暂无应收费用明细/.test(outboundDetail), '出库单缺少应收费用空态');
expect(/应收费用合计(USD)/.test(outboundDetail), '出库单缺少应收费用合计');
const expectedFees = [
['仓储费', 85],
['出库费', 45],
['托盘自提打托费', 30],
['托盘自提出库费', 25],
['快递交车费', 18],
['快递出库费', 22],
['扣货费', 50],
['弃货费', 65],
];
const feeTemplateStart = appJs.indexOf('const fbaOutboundReceivableFeeTemplate');
const feeTemplateEnd = appJs.indexOf('];', feeTemplateStart);
const feeTemplate = feeTemplateStart >= 0 && feeTemplateEnd > feeTemplateStart
? appJs.slice(feeTemplateStart, feeTemplateEnd + 2)
: '';
for (const [feeName, amount] of expectedFees) {
expect(
feeTemplate.includes(`{name:'${feeName}',currency:'USD',amount:${amount},remark:'-'}`),
`出库应收费用缺少 ${feeName} USD ${amount}`,
);
}
expect(expectedFees.reduce((sum, [, amount]) => sum + amount, 0) === 340, '出库应收费用示例金额合计不是 340');
expect(/function\s+createFbaOutboundReceivableFees\s*\(\)/.test(appJs), '缺少出库应收费用数组创建函数');
expect(/fbaOutboundOrderData\.forEach\(order=>\{order\.fees=createFbaOutboundReceivableFees\(\);\}\);/.test(appJs), '现有出库单未接入统一应收费用模板');
expect((appJs.match(/fees:createFbaOutboundReceivableFees\(\)/g) || []).length >= 2, '动态新增出库单未接入统一应收费用模板');
expect(/function\s+formatFbaReceivableFee\s*\(/.test(appJs), '缺少统一应收费用金额格式化函数');
expect(/amount===null\|\|amount===undefined\|\|String\(amount\)\.trim\(\)===''/.test(appJs), '空金额未显示为 -');
expect(/function\s+renderFbaReceivableFees\s*\(/.test(appJs), '缺少统一应收费用渲染函数');
expect(/item\.name\|\|'-'/.test(appJs), '空费用项目未显示为 -');
expect(/item\.currency\|\|'-'/.test(appJs), '空币种未显示为 -');
expect(/item\.remark\|\|'-'/.test(appJs), '空备注未显示为 -');
expect(/暂无应收费用明细/.test(appJs), '统一渲染函数缺少应收费用空态');
expect(/function\s+renderFbaInboundFees\s*\(fees\)[\s\S]*?renderFbaReceivableFees\('fbd-inbound-fees','fbd-inbound-fee-total',fees\)/.test(appJs), '入库单未复用统一应收费用渲染');
expect(/function\s+renderFbaOutboundFees\s*\(fees\)[\s\S]*?renderFbaReceivableFees\('fbd-outbound-fees','fbd-outbound-fee-total',fees\)/.test(appJs), '出库单未复用统一应收费用渲染');
expect(/renderFbaInboundFees\(d\.fees\)/.test(appJs), '入库单详情未渲染应收费用');
expect(/renderFbaOutboundFees\(d\.fees\)/.test(appJs), '出库单详情未渲染应收费用');
if (failures.length) {
console.error('FBA_RECEIVABLE_FEE_DETAIL_CHECK_FAIL');
failures.forEach(message => console.error(`- ${message}`));
process.exitCode = 1;
} else {
console.log('FBA_RECEIVABLE_FEE_DETAIL_CHECK_PASS');
}