import { describe, expect, it } from 'vitest' import type { SmartLoadingItem } from './types' import { groupSmartLoadingItems } from './smartLoadingItems' function item(overrides: Partial = {}): 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: '货物一', 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('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) }) })