import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' import { runInNewContext } from 'node:vm' import ts from 'typescript' const api = readFileSync(new URL('./api/businessOrders.ts', import.meta.url), 'utf8') const routes = readFileSync(new URL('./routes.ts', import.meta.url), 'utf8') const view = readFileSync(new URL('./components/BusinessOrdersView.vue', import.meta.url), 'utf8') const demandComponent = readFileSync(new URL('./components/TransportDemandForm.vue', import.meta.url), 'utf8') const demandLogic = ts.transpileModule(readFileSync(new URL('./transportDemandForm.ts', import.meta.url), 'utf8'), { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext } }).outputText.replace(/^export /gm, '') const demandHelpers = runInNewContext(`${demandLogic}\n({ createTransportDemandForm, transportDemandRules, transportDemandError, buildTransportDemand })`) const procurementApi = readFileSync(new URL('./api/procurement.ts', import.meta.url), 'utf8') const procurementView = readFileSync(new URL('./views/ProcurementView.vue', import.meta.url), 'utf8') test('renders unknown pallet service and container type as dashes while preserving explicit values', () => { const helpers = view.slice(view.indexOf('function read('), view.indexOf('function idempotencyKey(')) const compiled = ts.transpileModule(helpers, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText const { displayCell, yesNo, text } = runInNewContext(`${compiled}\n({ displayCell, yesNo, text })`) assert.equal(displayCell({ palletRequired: null }, 'palletRequired'), '—') assert.equal(displayCell({ palletRequired: 'NO' }, 'palletRequired'), '否') assert.equal(displayCell({ palletRequired: 'YES' }, 'palletRequired'), '是') assert.equal(displayCell({ containerType: null }, 'containerType'), '—') assert.equal(displayCell({ containerType: '40HQ' }, 'containerType'), '40HQ') assert.equal(yesNo(null), '—') assert.equal(text(null), '—') assert.match(api, /palletRequired\?: string \| null/) const create = api.slice(api.indexOf('export interface TransportCreate'), api.indexOf('export interface TransportUpdate')) assert.doesNotMatch(create, /palletRequired\?: string \| null/) }) test('shows merchant-owned arrangement facts without a pool request or editable status control', () => { assert.match(api, /fleetArrangement: import\('\.\.\/fleetArrangement'\)\.FleetArrangement \| null/) assert.match(view, /aria-label="承运安排"/) for (const field of ['signedPackages', 'unsignedPackages', 'returnedPackages']) assert.ok(view.includes(`fleetArrangement.${field}`)) assert.doesNotMatch(api, /capacity-offers|fleet\/trips/) assert.match(view, /if \(query\.page !== 1\) query\.page = 1\s+else void load\(\)/) assert.match(view, /if \(reloadDirectly\) void load\(\)/) }) test('activates all three customer cross-border pages with frozen permissions', () => { for (const [path, permission] of [ ['cross-border/procurement', 'merchant:cross-border:procurement:list'], ['cross-border/domestic-trucking', 'merchant:cross-border:domestic-trucking:list'], ['cross-border/pallet-shipping', 'merchant:cross-border:pallet-shipping:list'], ]) { assert.match(routes, new RegExp(`path: '${path}'[\\s\\S]*?release: 'active'[\\s\\S]*?permission: '${permission}'`)) } assert.doesNotMatch(view, /PrototypeFeatureView|mock|customerId|tenantId/i) assert.match(procurementView, /merchant:cross-border:procurement:create/) assert.match(view, /merchant:cross-border:domestic-trucking:create/) assert.match(view, /merchant:cross-border:pallet-shipping:create/) assert.match(view, /v-if="canCreate"[^>]*type="primary"/) }) test('uses only merchant overseas endpoints and keeps retry idempotency stable', () => { assert.match(procurementApi, /overseas-procurements/) assert.doesNotMatch(api, /overseas-procurements|ProcurementSummary|ProcurementDetail/) assert.match(api, /us-truck-orders/) assert.match(api, /local-looseboard-orders/) assert.doesNotMatch(api, /\/platform\/|\/internal\/|customerId|tenantId/) assert.match(view, /const stableSubmitKey = submitKey\.value \|\| idempotencyKey\(\)/) assert.match(view, /submitKey\.value = stableSubmitKey/) assert.match(view, /idempotencyKey: stableSubmitKey/g) }) test('covers list detail create loading error empty pagination and actions-first contracts', () => { assert.match(view, /mode\.value = 'detail'/) assert.match(view, /mode\.value = 'list'/) assert.match(view, /mode = 'create'/) assert.match(view, /v-loading="loading"/) assert.match(view, /class="business-load-error"/) assert.match(view, /empty-text="暂无订单"/) assert.match(view, /]*layout="grid"/) assert.match(view, /]*:row-actions="getRowActions"/) assert.match(view, /key: 'actions', label: '操作', width: 90, fixed: 'left'/) assert.match(view, /class="business-table-card"/) assert.doesNotMatch(procurementView, /inventoryQuantity|outboundQuantity|reviewRemark/) assert.match(procurementView, /procurementStatuses/) assert.match(procurementView, /ProcurementDetailPanel/) }) test('opens every dashboard cross-border action on a dedicated protected create page', () => { for (const [path, permission] of [ ['cross-border/procurement/create', 'merchant:cross-border:procurement:create'], ['cross-border/domestic-trucking/create', 'merchant:cross-border:domestic-trucking:create'], ['cross-border/pallet-shipping/create', 'merchant:cross-border:pallet-shipping:create'], ]) { assert.match(routes, new RegExp(`path: '${path}'[\\s\\S]*?props: \\{ createPage: true \\}[\\s\\S]*?permission: '${permission}'`)) } assert.match(view, /props\.createPage \? 'create' : 'list'/) assert.match(view, /if \(props\.createPage\) await router\.push/) }) test('opens all cross-border details on dedicated protected routes', () => { for (const [path, routeName] of [ ['cross-border/procurement/:orderNo/detail', 'cross-border-procurement-detail'], ['cross-border/domestic-trucking/:orderNo/detail', 'cross-border-domestic-trucking-detail'], ['cross-border/pallet-shipping/:orderNo/detail', 'cross-border-pallet-shipping-detail'], ]) { assert.match(routes, new RegExp(`path: '${path.replaceAll('/', '\\/')}'[\\s\\S]*?name: '${routeName}'`)) } assert.match(view, /name: detailRouteName\.value, params: \{ orderNo: row\.orderNo \}/) assert.match(view, /class="business-detail-error"/) }) test('preserves the existing transport responsive rules without adding a narrow-screen procurement acceptance gate', () => { assert.match(view, /@media \(max-width: 767px\)/) assert.match(view, /queryFields/) assert.match(view, /\.detail-grid \{ grid-template-columns: 1fr; \}/) assert.match(view, /\.form-card :deep\(\.el-form-item\) \{ display: block; \}/) assert.match(demandComponent, /\.transport-demand-budget \{ display: grid; width: 100%/) }) test('uses the shared dense order-list and detail visual language', () => { assert.match(view, /class="business-orders client-ui"/) assert.match(view, /\.business-detail-page \{[^}]*border: 1px solid var\(--client-border\);[^}]*border-radius: var\(--client-radius\);/) assert.match(view, /\.detail-grid \{[^}]*grid-template-columns: repeat\(4, minmax\(0, 1fr\)\)/) assert.match(view, /\.detail-grid div \{[^}]*min-height: 34px;[^}]*grid-template-columns: 76px minmax\(0, 1fr\)/) }) function transportHarness(kind = 'trucking', failFirst = false) { const calls = [] const script = view.match(/