优化
This commit is contained in:
@@ -12,13 +12,14 @@ test('box merge component compiles both its script and template', () => {
|
||||
assert.deepEqual(compileTemplate({ source: descriptor.template.content, filename, id: 'box-merge' }).errors, [])
|
||||
})
|
||||
function instance() {
|
||||
const component = vm.runInNewContext(descriptor.script.content.replace(/^import .*$/gm, '').replace('export default', 'component ='), { ScanTargetInput: {}, ReturnLabelConfirmation: {}, component: null })
|
||||
const boxes = [{cartonMark:'A',customerId:'C1',items:[{skuCode:'SKU1',quantity:2},{skuCode:'SKU2',quantity:3}]},{cartonMark:'B',customerId:'C1',items:[{skuCode:'SKU1',quantity:2}]}]
|
||||
const component = vm.runInNewContext(descriptor.script.content.replace(/^import .*$/gm, '').replace('export default', 'component ='), { ScanTargetInput: {}, ReturnLabelConfirmation: {}, component: null, scanReturnCarton: async mark => boxes.find(box => box.cartonMark === mark) })
|
||||
const work = { ...component.data(), plan: {customerId:'C1',sources:[{cartonMark:'A',items:[{skuCode:'SKU1',quantity:2},{skuCode:'SKU2',quantity:3}]},{cartonMark:'B',items:[{skuCode:'SKU1',quantity:2}]}]}, $emit(){} }
|
||||
for (const [name, method] of Object.entries(component.methods)) work[name] = method.bind(work)
|
||||
work.save = () => {}
|
||||
return {work,component}
|
||||
}
|
||||
test('new plan requires scanning each source and keeps independent SKU deductions', async () => {
|
||||
test('new plan requires scanning each source and preserves locked SKU quantities', async () => {
|
||||
const {work,component}=instance(); work.choose('NEW')
|
||||
assert.equal(work.sources.length,0)
|
||||
assert.equal(work.active,'source')
|
||||
@@ -26,14 +27,20 @@ test('new plan requires scanning each source and keeps independent SKU deduction
|
||||
work.setDeduction('A','SKU1',1); work.setDeduction('A','SKU2',2); work.setDeduction('B','SKU1',2)
|
||||
work.dimensions={length:10,width:20,height:30,weight:1}
|
||||
assert.equal(work.sources.length,2)
|
||||
assert.equal(work.plannedItems().reduce((sum,item)=>sum+item.quantity,0),5)
|
||||
assert.equal(work.plannedItems().reduce((sum,item)=>sum+item.quantity,0),7)
|
||||
assert.equal(component.computed.canComplete.call(work),true)
|
||||
})
|
||||
|
||||
test('planned source carton marks are visible before scanning', () => {
|
||||
const {work, component} = instance()
|
||||
work.plan = { sourceCartonMarks: ['A', 'B'], sources: [] }
|
||||
assert.deepEqual(component.computed.plannedSourceRows.call(work).map(box => box.cartonMark), ['A', 'B'])
|
||||
})
|
||||
test('existing box uses another box as target and never removes target inventory', async () => {
|
||||
const {work,component}=instance(); work.choose('EXISTING'); await work.scanSource('A'); await work.scanTarget('B')
|
||||
assert.equal(work.target.cartonMark,'B'); assert.equal(work.sources.length,1)
|
||||
work.setDeduction('A','SKU1',1)
|
||||
assert.equal(work.plannedItems().length,1)
|
||||
assert.equal(work.plannedItems().length,2)
|
||||
assert.equal(work.target.items[0].quantity,2)
|
||||
assert.equal(component.computed.canComplete.call(work),true)
|
||||
work.choose('NEW'); assert.equal(work.target,null); assert.equal(work.sources.length,0)
|
||||
@@ -42,6 +49,7 @@ test('existing box uses another box as target and never removes target inventory
|
||||
|
||||
test('existing source can be replaced before merging, echoing the mark and clearing old deductions and target', async () => {
|
||||
const {work,component}=instance()
|
||||
work.plan=null
|
||||
work.choose('EXISTING'); await work.scanSource('A'); await work.scanTarget('B')
|
||||
work.setDeduction('A','SKU1',1)
|
||||
assert.equal(work.sourceCode,'A')
|
||||
@@ -58,6 +66,18 @@ test('existing source can be replaced before merging, echoing the mark and clear
|
||||
assert.equal(component.computed.canComplete.call(work),true)
|
||||
})
|
||||
|
||||
test('BOX plan requires every source and accumulates multiple scanned sources', async () => {
|
||||
const {work,component}=instance()
|
||||
work.plan.mode='BOX'
|
||||
work.plan.sources.push({cartonMark:'C',items:[{skuCode:'SKU1',quantity:4}]})
|
||||
work.choose('EXISTING'); await work.scanSource('A'); await work.scanTarget('B')
|
||||
assert.equal(component.computed.canComplete.call(work),false)
|
||||
await work.scanSource('C')
|
||||
assert.equal(work.sources.length,2)
|
||||
assert.equal(component.computed.canComplete.call(work),true)
|
||||
assert.equal(work.plannedItems().reduce((sum,item)=>sum+item.quantity,0),9)
|
||||
})
|
||||
|
||||
test('a directly scanned box survives switching between existing and new targets', async () => {
|
||||
const {work}=instance()
|
||||
const box=work.plan.sources[0];work.plan=null;work.initialSource=box
|
||||
|
||||
Reference in New Issue
Block a user