67 lines
3.1 KiB
JavaScript
67 lines
3.1 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const vm = require('node:vm');
|
|
|
|
const html = fs.readFileSync('workbench.html', 'utf8');
|
|
const listPage = html.match(/<div class="page-content" id="page-cargo-disposal-list">([\s\S]*?)<!-- ========== PAGE: 新增货物废弃/)?.[1] || '';
|
|
|
|
function textContent(markup) {
|
|
return markup.replace(/<[^>]+>/g, '').trim();
|
|
}
|
|
|
|
const headers = Array.from(listPage.matchAll(/<th(?:\s[^>]*)?>([\s\S]*?)<\/th>/g), match => textContent(match[1]));
|
|
const orderNoIndex = headers.indexOf('货物废弃单号');
|
|
assert.ok(orderNoIndex >= 0, '货物废弃单号列应存在');
|
|
assert.equal(headers[orderNoIndex + 1], '入仓码', '入仓码应紧跟货物废弃单号');
|
|
assert.equal(headers.includes('计费单号'), false, '列表不应显示计费单号');
|
|
assert.equal(headers.includes('关联出库单'), true, '列表应显示关联出库单');
|
|
assert.equal(headers.includes('废弃出库单号'), false, '列表不应再显示废弃出库单号');
|
|
|
|
const detailPage = html.match(/<div class="page-content" id="page-cargo-disposal-detail">([\s\S]*?)<!-- ========== PAGE:/)?.[1] || '';
|
|
assert.match(detailPage, /<dt>关联出库单<\/dt>/, '详情页应显示关联出库单');
|
|
assert.doesNotMatch(detailPage, /<dt>废弃出库单号<\/dt>/, '详情页不应再显示废弃出库单号');
|
|
|
|
function extractFunction(name) {
|
|
const start = html.indexOf(`function ${name}(`);
|
|
assert.notEqual(start, -1, `${name} should exist`);
|
|
const bodyStart = html.indexOf('{', start);
|
|
let depth = 0;
|
|
for (let index = bodyStart; index < html.length; index += 1) {
|
|
if (html[index] === '{') depth += 1;
|
|
if (html[index] === '}') depth -= 1;
|
|
if (depth === 0) return html.slice(start, index + 1);
|
|
}
|
|
throw new Error(`Unable to extract ${name}`);
|
|
}
|
|
|
|
const tbody = { innerHTML: '' };
|
|
const controls = {
|
|
'cargo-disposal-list-body': tbody,
|
|
'cargo-disposal-total': { textContent: '' },
|
|
'cargo-disposal-page-number': { textContent: '' },
|
|
'cargo-disposal-prev': { disabled: false },
|
|
'cargo-disposal-next': { disabled: false }
|
|
};
|
|
const renderCargoDisposalList = vm.runInNewContext(
|
|
`(${extractFunction('renderCargoDisposalList')})`,
|
|
{
|
|
document: { getElementById: id => controls[id] || null },
|
|
cargoDisposalFilteredOrders: null,
|
|
loadCargoDisposalOrders: () => [{
|
|
id: 'order-1', orderNo: 'FH001', inboundNo: 'RK001', disposalBoxes: 2,
|
|
warehouse: '美西洛杉矶仓', feeAmount: 10, outboundOrderNo: 'CK001',
|
|
billingNo: 'JF001', status: '待处理', createdAt: '2026-09-04 09:00'
|
|
}],
|
|
CARGO_DISPOSAL_PAGE_SIZE: 10,
|
|
cargoDisposalCurrentPage: 1,
|
|
escapeCargoDisposalHtml: value => String(value == null ? '' : value)
|
|
}
|
|
);
|
|
renderCargoDisposalList();
|
|
const orderNoCellStart = tbody.innerHTML.indexOf('<td>FH001</td>');
|
|
assert.ok(orderNoCellStart >= 0, '行中应输出货物废弃单号');
|
|
assert.equal(tbody.innerHTML.slice(orderNoCellStart).indexOf('<td>RK001</td>'), '<td>RK001</td>'.length, '行中入仓码应紧跟货物废弃单号');
|
|
assert.doesNotMatch(tbody.innerHTML, /JF001/, '行中不应输出计费单号');
|
|
|
|
console.log('cargo disposal list columns: ok');
|