40 lines
2.0 KiB
JavaScript
40 lines
2.0 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const targets = [
|
|
['维护源码', path.join(root, 'prototype-src/modules/04-overseas-delivery.html')],
|
|
['完整入口', path.join(root, 'index.html')],
|
|
];
|
|
|
|
function verifyDispatchTable(label, filePath) {
|
|
const html = fs.readFileSync(filePath, 'utf8');
|
|
const tableMatch = html.match(/<div class="inbound-table-container" id="dispatch-table-scroll"[\s\S]*?<table[\s\S]*?<\/table>/);
|
|
assert.ok(tableMatch, `${label}缺少派送单主表`);
|
|
|
|
const table = tableMatch[0];
|
|
const headMatch = table.match(/<thead>[\s\S]*?<tr>([\s\S]*?)<\/tr>[\s\S]*?<\/thead>/);
|
|
assert.ok(headMatch, `${label}缺少派送单表头`);
|
|
const headers = [...headMatch[1].matchAll(/<th(?:\s[^>]*)?>([\s\S]*?)<\/th>/g)]
|
|
.map((match) => match[1].replace(/<[^>]+>/g, '').trim());
|
|
|
|
assert.ok(!headers.includes('编辑'), `${label}的派送单表头仍包含独立“编辑”字段`);
|
|
|
|
const bodyMatch = table.match(/<tbody id="tbody-outbound-dispatch">([\s\S]*?)<\/tbody>/);
|
|
assert.ok(bodyMatch, `${label}缺少派送单表体`);
|
|
const rows = [...bodyMatch[1].matchAll(/<tr data-dispatch-no="[^"]+">([\s\S]*?)<\/tr>/g)];
|
|
assert.equal(rows.length, 5, `${label}的派送单示例行数量异常`);
|
|
|
|
for (const row of rows) {
|
|
const cells = [...row[1].matchAll(/<td(?:\s[^>]*)?>[\s\S]*?<\/td>/g)];
|
|
assert.equal(cells.length, headers.length, `${label}的派送单表头与数据列数量不一致`);
|
|
assert.match(row[1], />编辑车队<\/a>/, `${label}的派送单行缺少“编辑车队”操作`);
|
|
assert.doesNotMatch(row[1], /<td><a[^>]*>编辑<\/a><\/td>/, `${label}的派送单行仍包含独立“编辑”字段`);
|
|
}
|
|
}
|
|
|
|
for (const [label, filePath] of targets) verifyDispatchTable(label, filePath);
|
|
|
|
console.log('验证通过:派送单列表已移除独立“编辑”字段,并保留 5 个“编辑车队”操作。');
|