Files
docs/悦/货代SAAS平台后台/tests/verify-container-empty-return-warning.cjs
T
2026-08-21 09:20:26 +08:00

59 lines
3.5 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const root = path.resolve(__dirname, '..');
const moduleHtml = fs.readFileSync(path.join(root, 'prototype-src/modules/06-containers.html'), 'utf8');
const overlays = fs.readFileSync(path.join(root, 'prototype-src/overlays.html'), 'utf8');
const appJs = fs.readFileSync(path.join(root, 'prototype-src/app.js'), 'utf8');
assert.ok(moduleHtml.includes('table style="min-width:2800px"'), '货柜列表最小宽度应为 2800px');
assert.ok(moduleHtml.includes('<th style="width:300px;white-space:nowrap;text-align:center">操作</th><th>报空预警</th><th>集装箱号</th>'), '报空预警应紧跟操作列');
assert.ok(appJs.includes("['_cb','_act','_emptyWarning','no'"), '报空预警渲染键应紧跟操作列');
['预计提柜时间', '约车时间', '报空时间', '还柜时间', '报空预警'].forEach(label => {
assert.ok(moduleHtml.includes(label), `货柜列表缺少表头:${label}`);
});
assert.ok(!moduleHtml.includes('<th>预计报空时间</th>'), '货柜列表不应显示预计报空时间');
assert.ok(
moduleHtml.includes('<th>预计提柜时间</th><th>约车时间</th><th>报空时间</th>'),
'约车时间应位于预计提柜时间和报空时间之间',
);
['ct-add-pickup-expected', 'ct-add-appointment-at', 'ct-add-emptied-at', 'ct-add-returned-at'].forEach(id => {
assert.ok(overlays.includes(`id="${id}"`), `货柜表单缺少字段:${id}`);
});
assert.ok(!overlays.includes('id="ct-add-empty-expected"'), '货柜表单不应显示预计报空时间字段');
assert.ok(
/预计提柜时间:[\s\S]{0,220}ct-add-pickup-expected[\s\S]{0,220}约车时间:[\s\S]{0,220}ct-add-appointment-at/.test(overlays),
'约车时间应紧跟预计提柜时间',
);
['pickupExpectedAt', 'appointmentAt', 'emptyExpectedAt', 'emptiedAt', 'returnedAt'].forEach(key => {
assert.ok(appJs.includes(key), `货柜数据缺少字段:${key}`);
});
['ct-add-pickup-expected', 'ct-add-appointment-at', 'ct-add-emptied-at', 'ct-add-returned-at'].forEach(id => {
const uses = appJs.match(new RegExp(id, 'g')) || [];
assert.ok(uses.length >= 3, `货柜表单字段未完整接通重置、编辑和保存:${id}`);
});
assert.ok(!appJs.includes("document.getElementById('ct-add-empty-expected')"), '预计报空时间不应继续接入货柜表单');
assert.ok(
appJs.includes("'pickupExpectedAt','appointmentAt','emptiedAt','returnedAt'"),
'货柜列表时间列映射应包含约车时间并移除预计报空时间',
);
const start = appJs.indexOf('function getCtEmptyWarningState');
const end = appJs.indexOf('\nfunction renderCtEmptyWarning', start);
assert.ok(start >= 0 && end > start, '缺少可测试的报空预警函数');
const sandbox = {};
vm.runInNewContext(`${appJs.slice(start, end)}\nresult=getCtEmptyWarningState;`, sandbox);
const getState = sandbox.result;
const now = new Date('2026-08-14T00:00:00');
const normalize = value => JSON.parse(JSON.stringify(value));
assert.deepEqual(normalize(getState({}, now)), {tone:'none', text:'—'});
assert.deepEqual(normalize(getState({emptyExpectedAt:'2026-08-13T12:00', emptiedAt:'2026-08-13T18:00'}, now)), {tone:'done', text:'已报空'});
assert.deepEqual(normalize(getState({emptyExpectedAt:'2026-08-15T00:00', emptiedAt:''}, now)), {tone:'normal', text:'未超时'});
assert.deepEqual(normalize(getState({emptyExpectedAt:'2026-08-13T12:00', emptiedAt:''}, now)), {tone:'overdue', text:'超时 1 天'});
console.log('货柜报空时间与预警回归校验通过');