This commit is contained in:
2026-11-02 17:15:55 +08:00
parent 63193d04de
commit 5a1cde6c0f
4 changed files with 106 additions and 16 deletions
@@ -7,7 +7,14 @@ import ts from 'typescript'
const source = readFileSync(new URL('./transportDemandForm.ts', import.meta.url), 'utf8')
const code = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext } }).outputText.replace(/^export /gm, '')
const { createTransportDemandForm, transportDemandError, buildTransportDemand } = runInNewContext(`${code}\n({ createTransportDemandForm, transportDemandError, buildTransportDemand })`)
const valid = () => ({ ...createTransportDemandForm(), vehicleType: 'PALLET_15', estimatedPalletCount: 3, budgetAmount: 100, origin: ' LA ', destination: ' ONT ', originContactName: ' 发货人 ', originContactPhone: ' +1-555-0100 ', destinationContactName: ' 收货人 ', destinationContactPhone: ' +1-555-0101 ', pickupAt: '2026-10-20T09:30:45', deliveryAt: '2026-10-20T15:45:12' })
const valid = () => ({ ...createTransportDemandForm(), deliveryMode: 'WAREHOUSE_PICKUP', operatingWarehouseId: '9', destinationType: 'FBA', packageCount: 8, vehicleType: 'PALLET_15', estimatedPalletCount: 3, budgetAmount: 100, origin: ' LA ', originAddress: '123 Test Road', destination: ' ONT ', originContactName: ' 发货人 ', originContactPhone: ' +1-555-0100 ', destinationContactName: ' 收货人 ', destinationContactPhone: ' +1-555-0101 ', pickupAt: '2026-10-20T09:30:45', deliveryAt: '2026-10-20T15:45:12' })
test('delivery to warehouse permits no tracking number while requiring receiving contacts and arrival time', () => {
const form = { ...valid(), deliveryMode: 'DELIVERY_TO_WAREHOUSE', deliveryContactName: '仓库收货员', deliveryContactPhone: '10003', estimatedArrivalAt: '2026-10-20T09:00:00', trackingNo: '' }
assert.equal(transportDemandError('looseboard', form), undefined)
assert.equal(buildTransportDemand('looseboard', form).trackingNo, undefined)
for (const field of ['deliveryContactName', 'deliveryContactPhone', 'estimatedArrivalAt']) assert.ok(transportDemandError('looseboard', { ...form, [field]: '' }))
})
test('initial form leaves contacts and times blank, zeroes cargo and distinguishes blank budget from zero', () => {
const form = createTransportDemandForm()
@@ -61,3 +68,11 @@ test('truck accepts only the two vehicle types and does not submit looseboard ca
assert.equal(loose.estimatedPalletCount, 3)
assert.equal(loose.packageCount, 8)
})
test('warehouse delivery clears hidden origin data and pickup requires the full origin address', () => {
const form={...valid(),deliveryMode:'DELIVERY_TO_WAREHOUSE',deliveryContactName:'warehouse',deliveryContactPhone:'000',estimatedArrivalAt:'2026-10-20T09:00:00'}
for(const field of ['origin','originAddress','originContactName','originContactPhone']) assert.equal(transportDemandError('looseboard',{...form,[field]:''}),undefined)
const payload=buildTransportDemand('looseboard',form)
assert.equal(payload.origin,'');assert.equal(payload.originAddress,undefined);assert.equal(payload.originContactName,'');assert.equal(payload.originContactPhone,'')
assert.match(transportDemandError('looseboard',{...valid(),originAddress:''}),/详细地址/)
})