This commit is contained in:
2026-10-16 11:42:59 +08:00
parent 4d7b6eb6dc
commit 9b58c12012
8 changed files with 180 additions and 46 deletions
@@ -14,6 +14,9 @@ function harness(kind = 'disposal', overrides = {}) {
const api = {
getDiscard: async () => ({ summary: { status: 'PDA_COMPLETED' }, photos: [{ fileId: '101' }] }),
getRelabel: async () => ({ application: { status: 'CUSTOMER_CONFIRM_PENDING' }, completionEvidence: { photoFileIds: ['101'] } }),
getTransfer: async () => ({ status: 'WAIT_CUSTOMER_CONFIRMATION', measurementPhotos: [{ fileId: '101' }], cartons: [{ cartonMark: 'BOX-1', status: 'COUNTED', weight: 5 }], pallets: [{ palletNo: 'PLT-1', grossWeightKg: 5 }] }),
downloadTransferMeasurementPhoto: async () => ({}),
confirmTransferMeasurement: async no => calls.push(['transfer', no]),
downloadDiscardPhoto: async () => ({}), downloadRelabelCompletionPhoto: async () => ({}),
confirmDiscardCompletion: async no => calls.push(['discard', no]),
confirmRelabelCompletion: async no => calls.push(['relabel', no]), ...overrides,
@@ -24,11 +27,11 @@ function harness(kind = 'disposal', overrides = {}) {
useAuthStore: () => ({ hasPermission: () => true }), ElMessage: { success() {}, error() {} },
URL: { createObjectURL: () => 'blob:photo', revokeObjectURL: url => revoked.push(url) }, ...api,
}
const state = new Function(...Object.keys(env), js + '\nreturn { loadEvidence, loadPhoto, submit, clear, checked, canConfirm, urls, failed, error, busy };')(...Object.values(env))
const state = new Function(...Object.keys(env), js + '\nreturn { loadEvidence, loadPhoto, submit, clear, checked, canConfirm, urls, failed, error, busy, measurement };')(...Object.values(env))
return { ...state, props, calls, events, revoked }
}
for (const kind of ['disposal', 'labeling']) {
for (const kind of ['disposal', 'labeling', 'transfer']) {
test(`${kind}: opening loads photos without confirming; only reviewed evidence can be submitted`, async () => {
const state = harness(kind)
await state.loadEvidence()
@@ -37,12 +40,33 @@ for (const kind of ['disposal', 'labeling']) {
state.checked.value = true
assert.equal(state.canConfirm.value, true)
await state.submit()
assert.deepEqual(state.calls, [[kind === 'disposal' ? 'discard' : 'relabel', 'CD/1']])
assert.deepEqual(state.calls, [[kind === 'transfer' ? 'transfer' : kind === 'disposal' ? 'discard' : 'relabel', 'CD/1']])
assert.deepEqual(state.events, [['confirmed', 'CD/1'], ['update:modelValue', false]])
state.clear(); assert.deepEqual(state.revoked, ['blob:photo'])
})
}
test('transfer confirmation reads current measurements and blocks missing, failed or outdated evidence', async () => {
const state = harness('transfer', { downloadTransferMeasurementPhoto: async () => { throw Error('offline') } })
await state.loadEvidence()
assert.equal(state.measurement.value.pallets[0].grossWeightKg, 5)
assert.equal(state.measurement.value.cartons[0].cartonMark, 'BOX-1')
state.checked.value = true
await state.submit()
assert.equal(state.canConfirm.value, false)
assert.deepEqual(state.calls, [])
for (const detail of [
{ status: 'WAIT_CUSTOMER_CONFIRMATION', measurementPhotos: [] },
{ status: 'COMPLETED', measurementPhotos: [{ fileId: '101' }] },
{ status: 'WAIT_CUSTOMER_CONFIRMATION', customerConfirmedAt: '2026-10-16', measurementPhotos: [{ fileId: '101' }] },
]) {
const invalid = harness('transfer', { getTransfer: async () => detail })
await invalid.loadEvidence(); invalid.checked.value = true; await invalid.submit()
assert.equal(invalid.canConfirm.value, false)
assert.deepEqual(invalid.calls, [])
}
})
test('photo failure blocks confirmation and supports retry', async () => {
let reject = true
const state = harness('disposal', { downloadDiscardPhoto: async () => { if (reject) throw Error('offline'); return {} } })