优化
This commit is contained in:
@@ -119,7 +119,7 @@ test('uses the shared dense order-list and detail visual language', () => {
|
||||
assert.match(view, /\.detail-grid div \{[^}]*min-height: 34px;[^}]*grid-template-columns: 76px minmax\(0, 1fr\)/)
|
||||
})
|
||||
|
||||
function transportHarness(kind = 'trucking', failFirst = false) {
|
||||
function transportHarness(kind = 'trucking', failFirst = false, budgetCheck = async () => {}) {
|
||||
const calls = []
|
||||
const script = view.match(/<script setup lang="ts">([\s\S]*?)<\/script>/)[1]
|
||||
const compiled = ts.transpileModule(script, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext } }).outputText
|
||||
@@ -130,7 +130,7 @@ function transportHarness(kind = 'trucking', failFirst = false) {
|
||||
computed: getter => ({ get value() { return typeof getter === 'function' ? getter() : getter.get() } }),
|
||||
reactive: value => value, ref: value => ({ value }), onMounted: () => {}, watch: () => {},
|
||||
useAuthStore: () => ({ hasPermission: () => true }), useRouter: () => ({ push: async () => {} }), useRoute: () => ({ params: {} }),
|
||||
...demandHelpers, poolOrderStatusLabels: {},
|
||||
...demandHelpers, poolOrderStatusLabels: {}, requireOrderBudget: budgetCheck,
|
||||
ElMessage: { success: () => {}, error: () => {} },
|
||||
createTransport: async (business, payload) => { calls.push({ business, payload: { ...payload } }); if (failFirst && calls.length === 1) throw new Error('retry'); },
|
||||
})
|
||||
@@ -155,7 +155,7 @@ test('truck requires both contacts vehicle and minute times without inheriting l
|
||||
|
||||
test('truck retry submits the complete new contract with identical local times and idempotency key', async () => {
|
||||
const current = transportHarness('trucking', true)
|
||||
Object.assign(current.form, { vehicleType: 'PALLET_30', origin: 'Los Angeles', destination: 'Ontario', originContactName: 'A', originContactPhone: '+1-555-0100', destinationContactName: 'B', destinationContactPhone: '+1-555-0101', pickupAt: '2026-10-20T09:30:00', deliveryAt: '2026-10-20T15:45:00' })
|
||||
Object.assign(current.form, { vehicleType: 'PALLET_30', estimatedPalletCount: 3, budgetAmount: 100, origin: 'Los Angeles', destination: 'Ontario', originContactName: 'A', originContactPhone: '+1-555-0100', destinationContactName: 'B', destinationContactPhone: '+1-555-0101', pickupAt: '2026-10-20T09:30:00', deliveryAt: '2026-10-20T15:45:00' })
|
||||
await current.submit()
|
||||
assert.equal(current.form.destinationContactName, 'B')
|
||||
await current.submit()
|
||||
@@ -164,11 +164,12 @@ test('truck retry submits the complete new contract with identical local times a
|
||||
const second = current.calls[1].payload
|
||||
assert.equal(first.idempotencyKey, second.idempotencyKey)
|
||||
assert.equal(second.vehicleType, 'PALLET_30')
|
||||
assert.equal(second.palletCount, 3)
|
||||
assert.equal(second.originContactPhone, '+1-555-0100')
|
||||
assert.equal(second.destinationContactName, 'B')
|
||||
assert.equal(second.pickupAt, '2026-10-20T09:30:00')
|
||||
assert.equal(second.deliveryAt, '2026-10-20T15:45:00')
|
||||
for (const field of ['transportType', 'containerType', 'palletCount', 'contactName', 'contactInfo', 'requestedDate']) assert.equal(Object.hasOwn(second, field), false)
|
||||
for (const field of ['transportType', 'containerType', 'packageCount', 'contactName', 'contactInfo', 'requestedDate']) assert.equal(Object.hasOwn(second, field), false)
|
||||
})
|
||||
|
||||
test('truck details render saved minute times and unknown pool demand without timezone conversion', () => {
|
||||
@@ -208,3 +209,17 @@ test('looseboard requires both times and rejects backwards schedule', () => {
|
||||
current.rules.value.deliveryAt[1].validator({}, '2026-10-20T10:29:00', error => { failure = error })
|
||||
assert.ok(failure)
|
||||
})
|
||||
|
||||
|
||||
test('truck creation waits for budget freeze and never submits after insufficient funds', async () => {
|
||||
let release
|
||||
const gate = new Promise(resolve => { release = resolve })
|
||||
const current = transportHarness('trucking', false, () => gate)
|
||||
Object.assign(current.form, { vehicleType: 'PALLET_30', estimatedPalletCount: 3, budgetAmount: 100, origin: 'LA', destination: 'ONT', originContactName: 'A', originContactPhone: '1', destinationContactName: 'B', destinationContactPhone: '2', pickupAt: '2026-10-20T09:00:00', deliveryAt: '2026-10-20T15:00:00' })
|
||||
const pending = current.submit(); await Promise.resolve(); await Promise.resolve()
|
||||
assert.equal(current.calls.length, 0)
|
||||
release(); await pending; assert.equal(current.calls.length, 1)
|
||||
const failed = transportHarness('trucking', false, async () => { throw new Error('余额及授信不足') })
|
||||
Object.assign(failed.form, { ...current.form, vehicleType: 'PALLET_30', estimatedPalletCount: 3, budgetAmount: 100, origin: 'LA', destination: 'ONT', originContactName: 'A', originContactPhone: '1', destinationContactName: 'B', destinationContactPhone: '2', pickupAt: '2026-10-20T09:00:00', deliveryAt: '2026-10-20T15:00:00' })
|
||||
await failed.submit(); assert.equal(failed.calls.length, 0); assert.equal(failed.form.budgetAmount, 100)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user