Files
docs/悦/货代SAAS平台后台/tests/verify-overseas-truck-detail.cjs
T
2026-08-22 09:50:50 +08:00

46 lines
3.3 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const root = path.resolve(__dirname, '..');
const sourceRoot = path.join(root, 'prototype-src');
const moduleSource = fs.readFileSync(path.join(sourceRoot, 'modules/07-overseas-business.html'), 'utf8');
const appSource = fs.readFileSync(path.join(sourceRoot, 'app.js'), 'utf8');
const manifest = JSON.parse(fs.readFileSync(path.join(sourceRoot, 'manifest.json'), 'utf8'));
const moduleEntry = manifest.modules.find(item => item.file === 'modules/07-overseas-business.html');
assert.ok(moduleEntry, 'manifest 缺少海外业务模块');
assert.ok(moduleEntry.pages.includes('overseas-truck-detail'), '海外业务模块未登记本土卡派详情页');
assert.ok(manifest.pageOrder.includes('overseas-truck-detail'), 'pageOrder 未登记本土卡派详情页');
const moduleAddIndex = moduleEntry.pages.indexOf('overseas-truck-add');
const moduleDetailIndex = moduleEntry.pages.indexOf('overseas-truck-detail');
const moduleEditIndex = moduleEntry.pages.indexOf('overseas-truck-edit');
assert.ok(moduleAddIndex < moduleDetailIndex && moduleDetailIndex < moduleEditIndex, '海外业务模块中的详情页顺序应为新增页之后、编辑页之前');
const orderAddIndex = manifest.pageOrder.indexOf('overseas-truck-add');
const orderDetailIndex = manifest.pageOrder.indexOf('overseas-truck-detail');
const orderEditIndex = manifest.pageOrder.indexOf('overseas-truck-edit');
assert.ok(orderAddIndex < orderDetailIndex && orderDetailIndex < orderEditIndex, 'pageOrder 中的详情页顺序应为新增页之后、编辑页之前');
const detailStart = moduleSource.indexOf('id="page-overseas-truck-detail"');
const editStart = moduleSource.indexOf('id="page-overseas-truck-edit"');
assert.ok(detailStart >= 0, '缺少本土卡派详情页');
assert.ok(editStart > detailStart, '本土卡派详情页应位于新增页和编辑页之间');
const detailPage = moduleSource.slice(detailStart, editStart);
assert.match(detailPage, /id="truck-detail-no"/, '详情页缺少订单编号');
assert.match(detailPage, /id="truck-detail-status"/, '详情页缺少状态');
assert.match(detailPage, /id="truck-detail-fields"/, '详情页缺少订单字段容器');
assert.match(detailPage, /id="truck-detail-attachments"/, '详情页缺少上传资料容器');
assert.match(detailPage, /onclick="editTruckOrderFromDetail\(\)"/, '详情页缺少编辑入口');
assert.match(detailPage, /switchPage\('overseas-truck'\)/, '详情页缺少返回列表入口');
assert.match(appSource, /onclick="showTruckOrderDetail\('\+idx\+'\)"/, '列表详情未接通详情页');
assert.match(appSource, /function showTruckOrderDetail\(index\)/, '缺少详情渲染函数');
assert.match(appSource, /function editTruckOrderFromDetail\(\)/, '缺少详情页编辑跳转函数');
assert.match(appSource, /showToast\('订单不存在','error'\)/, '缺少无效订单处理');
assert.match(appSource, /暂无上传资料/, '缺少上传资料空态');
assert.match(appSource, /switchPage\('overseas-truck-detail'\)/, '详情渲染未跳转到详情页');
assert.match(appSource, /page==='overseas-truck-detail'[\s\S]*?switchPage\(\\'overseas-truck\\',this\)/, '本土卡派详情页未映射到列表侧栏导航');
console.log('海外本土卡派详情页校验通过');