Files
docs/悦/货代SAAS平台后台/tests/verify-customer-service-exception-order-numbers.cjs
T
2026-08-21 09:20:26 +08:00

53 lines
4.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 read = relativePath => fs.readFileSync(path.join(root, relativePath), 'utf8');
const page = read('prototype-src/modules/04a-customer-service.html');
const app = read('prototype-src/app.js');
const overlays = read('prototype-src/overlays.html');
const shell = read('prototype-src/shell.html');
const includes = (source, expected, message) => assert.ok(source.includes(expected), message);
const functionSource = name => {
const start = app.search(new RegExp(`function\\s+${name}\\s*\\(`));
assert.notEqual(start, -1, `app.js 缺少 ${name}()`);
const next = app.indexOf('\nfunction ', start + 1);
return app.slice(start, next === -1 ? app.length : next);
};
const staticDispatchRecords = app.match(/const staticDispatchRecords\s*=\s*\[([\s\S]*?)\n\];/);
assert.ok(staticDispatchRecords, 'app.js 缺少静态派送订单数据');
assert.match(page, /<th\b[^>]*>\s*异常订单号\s*<\/th>/, '异常订单页缺少异常订单号表头');
assert.match(page, /<th\b[^>]*>\s*关联订单号\s*<\/th>/, '异常订单页缺少关联订单号表头');
assert.doesNotMatch(page, /<th\b[^>]*>\s*派送单号\s*<\/th>/, '异常订单页不应保留独立派送单号表头');
includes(page, 'placeholder="异常订单号 / 关联订单号 / 客户 / 原因"', '异常订单页搜索框占位符不符合编号契约');
assert.match(page, /min-width\s*:\s*1520px\b/, '异常订单页表格最小宽度应为 1520px');
assert.match(app, /function ensureDispatchExceptionNo\(/, 'app.js 缺少 ensureDispatchExceptionNo()');
assert.match(app, /function getDispatchExceptionRelatedOrders\(/, 'app.js 缺少 getDispatchExceptionRelatedOrders()');
assert.match(app, /function renderDispatchExceptionRelations\(/, 'app.js 缺少 renderDispatchExceptionRelations()');
assert.match(staticDispatchRecords[1], /dispatchNo\s*:\s*['"]YWBHK200615004['"][^}]*exceptionNo\s*:\s*['"]EXC20260812001['"]/, '异常订单编号 EXC20260812001 未关联派送单 YWBHK200615004');
assert.match(staticDispatchRecords[1], /dispatchNo\s*:\s*['"]YWBHK200615005['"][^}]*exceptionNo\s*:\s*['"]EXC20260812002['"]/, '异常订单编号 EXC20260812002 未关联派送单 YWBHK200615005');
const searchDispatchExceptionsSource = functionSource('searchDispatchExceptions');
const renderDispatchExceptionsSource = functionSource('renderDispatchExceptions');
const renderDispatchExceptionRelationsSource = functionSource('renderDispatchExceptionRelations');
const openDispatchExceptionProcessSource = functionSource('openDispatchExceptionProcess');
assert.match(searchDispatchExceptionsSource, /\[\s*record\.exceptionNo\s*,\s*related\.lastMileNo\s*,\s*related\.dispatchNo\s*,\s*related\.inboundNo\s*,\s*related\.outboundNo/, '异常订单搜索未覆盖编号与关联订单字段');
assert.match(renderDispatchExceptionsSource, /colspan\s*=\s*["']13["']/, '异常订单空状态 colspan 应为 13');
assert.match(renderDispatchExceptionRelationsSource, /\[\s*\[\s*['"]尾程['"]\s*,\s*related\.lastMileNo\s*\]\s*,\s*\[\s*['"]派送['"]\s*,\s*related\.dispatchNo\s*\]\s*,\s*\[\s*['"]入库['"]\s*,\s*related\.inboundNo\s*\]\s*,\s*\[\s*['"]出库['"]\s*,\s*related\.outboundNo\s*\]\s*\]/, '异常订单关联订单映射不完整');
assert.match(openDispatchExceptionProcessSource, /document\.getElementById\(\s*['"]dispatch-exception-process-exception-no['"]\s*\)\.textContent\s*=\s*record\.exceptionNo/, '处理弹窗未写入异常订单号');
assert.match(openDispatchExceptionProcessSource, /document\.getElementById\(\s*['"]dispatch-exception-process-relations['"]\s*\)\.innerHTML\s*=\s*renderDispatchExceptionRelations\(\s*record\s*\)/, '处理弹窗未渲染关联订单号');
assert.match(openDispatchExceptionProcessSource, /querySelector\(\s*['"]#modal-dispatch-exception-process \.modal['"]\s*\)[\s\S]*scrollTop\s*=\s*0/, '处理弹窗重复打开时未重置滚动位置');
includes(overlays, 'id="dispatch-exception-process-exception-no"', '处理弹窗缺少异常订单号容器');
includes(overlays, 'id="dispatch-exception-process-relations"', '处理弹窗缺少关联订单号容器');
assert.match(shell, /\.dispatch-exception-no\s*\{[^}]*font-weight\s*:\s*600\b/, '全局样式缺少带 font-weight:600 的 .dispatch-exception-no');
assert.match(shell, /\.dispatch-exception-relations\s*\{[^}]*display\s*:\s*flex\b/, '全局样式缺少带 display:flex 的 .dispatch-exception-relations');
assert.match(shell, /\.dispatch-exception-relation-label\s*\{[^}]*font-size\s*:\s*11px\b/, '全局样式缺少带 font-size:11px 的 .dispatch-exception-relation-label');
console.log('CUSTOMER_SERVICE_EXCEPTION_ORDER_NUMBERS_CHECK_PASS');