54 lines
2.6 KiB
TypeScript
54 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import type { SmartLoadingItem } from './types'
|
|
import { groupSmartLoadingItems } from './smartLoadingItems'
|
|
|
|
function item(overrides: Partial<SmartLoadingItem> = {}): SmartLoadingItem {
|
|
return {
|
|
id: '1', loadingPlanId: '10', accountId: '20', inboundId: '30', inboundDetailId: '40',
|
|
orderId: '50', orderNo: 'FL-1', inboundCode: 'NYEXX2608180003', customerName: '柏悦物流',
|
|
destinationWarehouseId: '60', destinationWarehouseCode: 'LAX', destinationWarehouseName: '洛杉矶仓',
|
|
skuCode: 'SKU-1', productNameZh: '货物一', unitType: 'PACKAGE', palletId: null, palletNo: null, indivisible: false, packageCount: 2, productQuantity: 20,
|
|
grossWeightKg: 662.8, volumeCbm: 0.334, loadSequence: 2, version: 1,
|
|
pickedPackageCount: 0, minPackageCount: 1, canAdjust: true, canRemove: true,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('groupSmartLoadingItems', () => {
|
|
it('keeps every sealed pallet as an independent non-adjustable allocation unit', () => {
|
|
const grouped = groupSmartLoadingItems([
|
|
item({ id: 'p1', unitType: 'SEALED_PALLET', palletId: '101', palletNo: 'PLT-101', indivisible: true, packageCount: 4 }),
|
|
item({ id: 'p2', unitType: 'SEALED_PALLET', palletId: '102', palletNo: 'PLT-102', indivisible: true, packageCount: 6 }),
|
|
])
|
|
|
|
expect(grouped).toHaveLength(2)
|
|
expect(grouped.map((row) => row.palletNo)).toEqual(['PLT-101', 'PLT-102'])
|
|
expect(grouped.every((row) => row.canAdjust === false)).toBe(true)
|
|
})
|
|
|
|
it('shows multiple specification rows as one inbound-code row with summed quantities', () => {
|
|
const grouped = groupSmartLoadingItems([
|
|
item(),
|
|
item({ id: '2', inboundDetailId: '41', skuCode: 'SKU-2', productNameZh: '货物二', packageCount: 2, grossWeightKg: 662.8, volumeCbm: 0.334, loadSequence: 3 }),
|
|
])
|
|
|
|
expect(grouped).toHaveLength(1)
|
|
expect(grouped[0]).toMatchObject({
|
|
inboundCode: 'NYEXX2608180003', packageCount: 4, grossWeightKg: 1325.6,
|
|
volumeCbm: 0.668, detailCount: 2, canAdjust: false, canRemove: true,
|
|
skuCode: 'SKU-1、SKU-2', productNameZh: '货物一、货物二', loadSequence: 2,
|
|
})
|
|
expect(grouped[0].sourceItems.map((source) => source.id)).toEqual(['1', '2'])
|
|
})
|
|
|
|
it('does not merge different inbound codes and keeps single-detail adjustment', () => {
|
|
const grouped = groupSmartLoadingItems([
|
|
item(),
|
|
item({ id: '2', inboundId: '31', inboundCode: 'NYEXX2608180004' }),
|
|
])
|
|
|
|
expect(grouped).toHaveLength(2)
|
|
expect(grouped.every((row) => row.detailCount === 1 && row.canAdjust)).toBe(true)
|
|
})
|
|
})
|