import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { runInNewContext } from 'node:vm' import test from 'node:test' import ts from 'typescript' const source = readFileSync(new URL('./transportFacts.ts', import.meta.url), 'utf8') const javascript = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 } }).outputText const exports = {} runInNewContext(javascript, { exports }) const rows = exports.customerTransportRows test('split inbound fragments retain separate cabinet facts and actual/estimated times', () => { const result = rows([ { inboundCode: 'NY-1', cabinetNo: 'D1', containerNo: 'TSTU0000001', nodes: [ { standardNode: 'AT_ORIGIN_PORT', actualAt: '2026-10-05T09:00:00', estimatedAt: null, providerCode: 'MANUAL' }, { standardNode: 'DEPARTED_ORIGIN_PORT', actualAt: null, estimatedAt: '2026-10-07T08:00:00', providerCode: 'MATSON' }, ] }, { inboundCode: 'NY-2', cabinetNo: 'D2', containerNo: 'TSTU0000002', nodes: [ { standardNode: 'AT_ORIGIN_PORT', actualAt: '2026-10-06T10:00:00', estimatedAt: null, providerCode: 'MATSON' }, ] }, ]) assert.equal(result.length, 3) assert.equal(result[0].nodeLabel, '已进港') assert.equal(result[0].source, '人工记录') assert.equal(result[1].nodeLabel, '预计开航') assert.equal(result[1].actualAt, null) assert.equal(result[1].estimatedAt, '2026-10-07T08:00:00') assert.equal(result[2].cabinetNo, 'D2') assert.equal(result[2].inboundCode, 'NY-2') assert.equal(result[2].actualAt, '2026-10-06T10:00:00') }) test('empty actual scope creates no invented nodes or database identifier fallback', () => { assert.equal(rows([]).length, 0) assert.equal(rows([{ inboundCode: 'NY-1', nodes: [] }]).length, 0) const [row] = rows([{ id: 'INTERNAL', nodes: [{ standardNode: 'AT_ORIGIN_PORT', actualAt: null, estimatedAt: '2026-10-05T09:00:00' }] }]) assert.equal(row.cabinetNo, '—') assert.equal(row.containerNo, '—') assert.equal(row.inboundCode, '—') assert.equal(row.actualAt, null) }) test('detail consumes the existing merchant detail API and displays times separately', () => { const store = readFileSync(new URL('../store/firstLegOrders.ts', import.meta.url), 'utf8') const table = readFileSync(new URL('../components/TransportFactsTable.vue', import.meta.url), 'utf8') assert.match(store, /transportFragments: detail\.transportFragments/) assert.match(table, /label="实际时间".*time\(row\.actualAt\)/) assert.match(table, /label="预计时间".*time\(row\.estimatedAt\)/) assert.doesNotMatch(table, /platform\/|fetch\(|actualAt\s*\|\|\s*.*estimatedAt/) })