Files
docs/悦/货代SAAS平台后台/tests/verify-fba-outbound-detail-pallet-info.cjs
T
2026-08-21 09:20:26 +08:00

42 lines
2.7 KiB
JavaScript

const assert = require('node:assert/strict');
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 pageStart = moduleHtml.indexOf('<div class="page" id="page-fba-outbound-order-detail">');
const pageEnd = moduleHtml.indexOf('<!-- ==================== OVERSEAS WAREHOUSE - 换标单详情', pageStart);
assert.ok(pageStart >= 0 && pageEnd > pageStart, '无法提取海外仓出库单详情页面');
const detailPage = moduleHtml.slice(pageStart, pageEnd);
const sectionStart = detailPage.indexOf('aria-labelledby="fbd-outbound-sku-title"');
const sectionEnd = detailPage.indexOf('</section>', sectionStart);
assert.ok(sectionStart >= 0 && sectionEnd > sectionStart, '无法提取出库单详情信息区块');
const detailSection = detailPage.slice(sectionStart, sectionEnd);
assert.ok(detailSection.includes('id="fbd-outbound-sku-title">托盘信息</div>'), '详情区块标题应为“托盘信息”');
const headers = [...detailSection.matchAll(/<th(?:\s[^>]*)?>([^<]+)<\/th>/g)].map(match => match[1].trim());
assert.deepEqual(headers, ['托盘号', '入仓码', '箱数', '重量', '体积'], '托盘信息应只保留五个逐托盘字段');
assert.ok(!detailSection.includes('<th>SKU</th>'), '托盘信息不应展示 SKU 列');
assert.ok(!detailSection.includes('<th>中文品名</th>'), '托盘信息不应展示中文品名列');
assert.ok(!detailSection.includes('<th>总托数</th>'), '托盘信息不应展示总托数列');
assert.ok(!detailSection.includes('<th>总托数</th>'), '托盘信息不应展示总托数列');
assert.ok(detailSection.includes('colspan="5"'), '托盘信息空态应跨五列');
assert.ok(detailSection.includes('暂无托盘信息'), '托盘信息应提供对应空态文案');
const renderFunction = appJs.match(/function\s+renderFbaOutboundSkuInfo\s*\(\s*items\s*\)\s*\{([\s\S]*?)\n\}/);
assert.ok(renderFunction, 'app.js 缺少 renderFbaOutboundSkuInfo(items)');
const renderBody = renderFunction[1];
['item.palletNo', 'item.inboundCode', 'item.boxes', 'item.weight', 'item.volume'].forEach(field => {
assert.ok(renderBody.includes(field), `托盘信息渲染缺少 ${field}`);
});
['item.sku', 'item.cnName'].forEach(field => {
assert.ok(!renderBody.includes(field), `托盘信息渲染不应包含 ${field}`);
});
assert.ok(renderBody.includes('colspan="5"'), '托盘信息渲染空态应跨五列');
assert.ok(renderBody.includes('暂无托盘信息'), '托盘信息渲染应使用对应空态文案');
console.log('FBA outbound detail pallet info verification passed.');