Files
client-web/src/modules/overseas-warehouse/views/inventoryTransferForm.test.mjs
T

63 lines
4.0 KiB
JavaScript
Raw Normal View History

2026-10-16 11:42:59 +08:00
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { transpileModule, ScriptTarget } from 'typescript'
const view = readFileSync(new URL('./WarehouseServiceView.vue', import.meta.url), 'utf8')
function setup() {
const body = view.slice(view.indexOf('async function selectTransferInventory('), view.indexOf('function selectTransferInboundMethod('))
const code = transpileModule(body, { compilerOptions: { target: ScriptTarget.ES2022 } }).outputText
const ctx = { selectedTransferInventory: {value:''}, selectedTransferSourceOrderIds:{value:[]},
transferSourceCartons:{value:[{cartonMark:'OLD'}]}, transferSourceError:{value:'OLD'}, transferSourceLoading:{value:true},
transferDestinationType:{value:'NONE'}, form:{warehouse:'WH',inboundNo:''},
transferInventoryCandidates:{value:[{inboundCode:'IN',skuCode:'SKU',productNameZh:'货品',availablePackages:2},
{inboundCode:'IN',skuCode:'SKU',availablePackages:3},{inboundCode:'OTHER',skuCode:'OTHER',availablePackages:99}]},
cargoRows:{value:[]}, inventoryQuantity:Number, createCargoRow:()=>({expectedPackageCount:1}),
loadTransferSourceCartons:async()=>{}, listRelabelHistoricalOrders:async()=>[{id:'1234567890123456789'}],
ElMessage:{error(message){throw Error(message)}} }
const select = new Function(...Object.keys(ctx), 'let transferSourceRequest=0;'+code+'; return selectTransferInventory')(...Object.values(ctx))
return {ctx,select}
}
test('inventory source populates full immutable cargo counts without mixing other inbound orders',async()=>{
const {ctx,select}=setup(); await select('IN')
assert.equal(ctx.transferDestinationType.value,'FBA')
assert.equal(ctx.cargoRows.value.length,1)
assert.equal(ctx.cargoRows.value[0].expectedPackageCount,5)
assert.equal(ctx.cargoRows.value[0].quantity,5)
assert.deepEqual(ctx.selectedTransferSourceOrderIds.value,['1234567890123456789'])
await select('')
assert.equal(ctx.form.inboundNo,'')
assert.deepEqual(ctx.selectedTransferSourceOrderIds.value,[])
assert.deepEqual(ctx.transferSourceCartons.value,[])
})
test('inventory view hides inbound fields and editing actions and shows original carton destination',()=>{
assert.match(view,/v-if="props.service === 'transfer' && !inventoryTransfer"[^>]*><span><i>\*<\/i>入仓方式/)
assert.match(view,/<el-radio-button v-if="!inventoryTransfer" value="NONE">/)
const panel=view.slice(view.indexOf('<section v-if="inventoryTransfer"'),view.indexOf('</section>',view.indexOf('<section v-if="inventoryTransfer"')))
assert.match(panel,/box.cartonMark/); assert.match(panel,/box.destinationWarehouseCode/)
assert.doesNotMatch(panel,/v-model|addCargoRow|removeCargoRow|清空/)
assert.match(view,/!inventoryTransfer\.value && \(!form.warehouse/)
assert.match(view,/estimatedArrivalAt: inventoryTransfer.value \? undefined : form.estimatedArrivalAt/)
})
2026-10-16 13:58:08 +08:00
test('仓储转运来源下拉包含退货单并使用独立来源编码', () => {
assert.match(view, /RETURN_ORDER:\$\{returnNo\}/)
assert.match(view, /退货单|\$\{returnNo\}/)
assert.match(view, /item\.sourceType === 'RETURN_CARTON' \|\| item\.sourceType === 'RETURN_PARCEL'/)
assert.match(view, /isReturnSource[\s\S]*item\.sourceType === 'RETURN_CARTON'/)
})
test('退货来源带出实物 SKU 数量并跳过普通历史订单查询', async () => {
const { ctx, select } = setup()
ctx.transferInventoryCandidates.value = [{ sourceType: 'RETURN_CARTON', inboundOrderNo: 'RET-1',
cartonAvailablePackages: 1, skuItems: [{ skuCode: 'SKU', quantity: 1 }],
cartonSkuItems: [{ skuCode: 'SKU', quantity: 6 }] },
{ sourceType: 'RETURN_CARTON', inboundOrderNo: 'OTHER', cartonAvailablePackages: 1,
cartonSkuItems: [{ skuCode: 'FOREIGN', quantity: 99 }] }]
await select('RETURN_ORDER:RET-1')
assert.equal(ctx.cargoRows.value.length, 1)
assert.equal(ctx.cargoRows.value[0].quantity, 6)
assert.equal(ctx.cargoRows.value[0].expectedPackageCount, 1)
assert.deepEqual(ctx.selectedTransferSourceOrderIds.value, [])
})