57 lines
2.8 KiB
JavaScript
57 lines
2.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const html = fs.readFileSync(path.resolve(__dirname, '..', '货代SaaS平台原型.html'), 'utf8');
|
|
const failures = [];
|
|
function expect(condition, message) { if (!condition) failures.push(message); }
|
|
function section(startMarker, endMarker) {
|
|
const start = html.indexOf(startMarker);
|
|
const end = html.indexOf(endMarker, start + startMarker.length);
|
|
return start >= 0 && end > start ? html.slice(start, end) : '';
|
|
}
|
|
function functionSource(name) {
|
|
const start = html.indexOf(`function ${name}(`);
|
|
if (start < 0) return '';
|
|
const braceStart = html.indexOf('{', start);
|
|
let depth = 0; let quote = ''; let escaped = false;
|
|
for (let index = braceStart; index < html.length; index += 1) {
|
|
const char = html[index];
|
|
if (quote) {
|
|
if (escaped) escaped = false;
|
|
else if (char === '\\') escaped = true;
|
|
else if (char === quote) quote = '';
|
|
continue;
|
|
}
|
|
if (char === "'" || char === '"' || char === '`') { quote = char; continue; }
|
|
if (char === '{') depth += 1;
|
|
if (char === '}' && --depth === 0) return html.slice(start, index + 1);
|
|
}
|
|
return '';
|
|
}
|
|
|
|
const supplierPage = section('<div class="page" id="page-supplier-list">', '<!-- ==================== OCEAN CHANNEL');
|
|
const supplierEditPage = section('<div class="page" id="page-supplier-edit">', '<!-- ==================== BOOKING DETAIL');
|
|
const renderSupplier = functionSource('renderSupplier');
|
|
const openSupplierAdd = functionSource('openSupplierAdd');
|
|
const editSupplier = functionSource('editSupplier');
|
|
const saveSupplier = functionSource('saveSupplier');
|
|
|
|
expect(/data-cat="trucking"/.test(supplierPage), '供应商列表应提供拖车分类');
|
|
expect(/id="supplier-scope"/.test(supplierPage), '拖车供应商列表应提供国内/国外筛选');
|
|
expect(/>国内<\/option>/.test(supplierPage) && />国外<\/option>/.test(supplierPage), '筛选应提供国内和国外选项');
|
|
expect(/国内\/国外<\/th>/.test(supplierPage), '供应商列表应新增国内/国外列');
|
|
expect(/id="supplier-scope-group-edit"/.test(html) && /id="sup-add-scope"/.test(html), '供应商表单应提供国内/国外字段');
|
|
expect(/scope/.test(renderSupplier) && /currentSupplierCat===['"]trucking['"]/.test(renderSupplier), '列表渲染应按拖车分类处理国内/国外字段');
|
|
expect(/sup-add-scope/.test(openSupplierAdd) && /sup-add-scope/.test(editSupplier) && /sup-add-scope/.test(saveSupplier), '新增、编辑、保存应读写国内/国外字段');
|
|
expect(/scope\s*:\s*['"]国内['"]/.test(html), '历史拖车供应商应默认国内');
|
|
|
|
if (failures.length) {
|
|
console.error('TRUCKING_SUPPLIER_SCOPE_CHECK_FAIL');
|
|
failures.forEach(failure => console.error(`- ${failure}`));
|
|
process.exitCode = 1;
|
|
} else {
|
|
console.log('TRUCKING_SUPPLIER_SCOPE_CHECK_PASS');
|
|
}
|