56 lines
2.3 KiB
JavaScript
56 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const generalHtml = fs.readFileSync(path.join(root, 'prototype-src/modules/10-general.html'), 'utf8');
|
|
const appJs = fs.readFileSync(path.join(root, 'prototype-src/app.js'), 'utf8');
|
|
|
|
function extractPage(source, pageId) {
|
|
const marker = `<div class="page" id="page-${pageId}">`;
|
|
const start = source.indexOf(marker);
|
|
if (start < 0) return '';
|
|
const next = source.indexOf('<div class="page" id="page-', start + marker.length);
|
|
return source.slice(start, next < 0 ? source.length : next);
|
|
}
|
|
|
|
function extractFunction(source, name, nextName) {
|
|
const start = source.indexOf(`function ${name}(`);
|
|
if (start < 0) return '';
|
|
const end = source.indexOf(`function ${nextName}(`, start);
|
|
return source.slice(start, end < 0 ? source.length : end);
|
|
}
|
|
|
|
const voyagePage = extractPage(generalHtml, 'gen-voyage');
|
|
assert.ok(voyagePage, '通用资料模块缺少 page-gen-voyage');
|
|
assert.match(
|
|
voyagePage,
|
|
/<th id="cost-unit-header">成本单价\(元\/kg\)<\/th><th>销售底价<\/th><th>建议报价<\/th><\/tr><\/thead><tbody id="tbody-voyage-cost">/,
|
|
'成本测算表尾列顺序必须为“成本单价、销售底价、建议报价”',
|
|
);
|
|
assert.match(
|
|
voyagePage,
|
|
/销售底价\s*=\s*建议报价\s*-\s*0\.6/,
|
|
'成本测算公式说明缺少“销售底价 = 建议报价 - 0.6”',
|
|
);
|
|
|
|
const calculateCostRowSource = extractFunction(appJs, 'calculateCostRow', 'renderCostCalcRows');
|
|
assert.ok(calculateCostRowSource, 'app.js 缺少 calculateCostRow 函数');
|
|
assert.match(
|
|
calculateCostRowSource,
|
|
/salesFloor\s*:\s*quote\s*-\s*0\.6/,
|
|
'calculateCostRow 必须返回固定派生值 salesFloor: quote - 0.6',
|
|
);
|
|
|
|
const renderCostCalcRowsSource = extractFunction(appJs, 'renderCostCalcRows', 'calculateVoyageCosts');
|
|
assert.ok(renderCostCalcRowsSource, 'app.js 缺少 renderCostCalcRows 函数');
|
|
assert.match(
|
|
renderCostCalcRowsSource,
|
|
/<td class="cost-sales-floor">¥'\+c\.salesFloor\.toFixed\(2\)\+'<\/td><td class="cost-quote">¥'\+c\.quote\.toFixed\(2\)/,
|
|
'renderCostCalcRows 必须在建议报价前渲染 cost-sales-floor 与 salesFloor.toFixed(2)',
|
|
);
|
|
|
|
console.log('VOYAGE_SALES_FLOOR_CHECK_PASS');
|