import ElementPlus from 'element-plus' import { flushPromises, mount } from '@vue/test-utils' import { describe, expect, it, vi } from 'vitest' import { listRelabelInventoryCandidates } from '../api/relabelOrders' import RelabelInventoryItemsEditor from './RelabelInventoryItemsEditor.vue' vi.mock('../api/relabelOrders', () => ({ listRelabelInventoryCandidates: vi.fn() })) describe('formal relabel source tasks', () => { it('submits one carton with long source IDs and independently editable SKU pieces; warehouse change clears it', async () => { vi.mocked(listRelabelInventoryCandidates).mockResolvedValue([{ inventoryBalanceId: '9007199254740993', inboundOrderId: '9007199254740994', inboundOrderNo: 'IN-1', skuCode: 'A', productNameZh: '商品', availablePackages: 1, sourceType: 'INBOUND', positions: [{ positionId: '9007199254740995', palletNo: 'P1', availablePackages: 1 }] }]) const wrapper = mount(RelabelInventoryItemsEditor, { props: { customerId:'C', warehouseId:'W',operationType:'CARTON_AND_SKU',shipmentNo:'S',destination:'SCK8',requirement:'要求' }, global:{plugins:[ElementPlus]} }) await flushPromises() wrapper.findComponent({name:'ElSelect'}).vm.$emit('update:modelValue','inventory:9007199254740995') await flushPromises() await wrapper.findAll('button').find(button => button.text() === '添加箱任务')!.trigger('click'); await flushPromises() await wrapper.findAll('input').find(input => input.attributes('maxlength') === '255')!.setValue('BOX-1') await wrapper.get('input[aria-label="新 SKU"]').setValue('B') wrapper.findComponent({name:'ElInputNumber'}).vm.$emit('update:modelValue',8) await flushPromises() const items = wrapper.emitted('update:items')!.at(-1)![0] as Array> expect(items).toMatchObject([{sourceInventoryBalanceId:'9007199254740993',sourceInventoryPositionId:'9007199254740995',sourceInboundOrderId:'9007199254740994',cartonMark:'BOX-1',totalPackageCount:1,notifiedPackageCount:1,destinationFbaWarehouseCode:'SCK8',skuItems:[{skuCode:'A',newSkuCode:'B',quantity:8}]}]) expect(items[0]).not.toHaveProperty('sourceLabel') await wrapper.setProps({warehouseId:'OTHER'}); await flushPromises() expect(wrapper.emitted('update:items')!.at(-1)![0]).toEqual([]) expect(listRelabelInventoryCandidates).toHaveBeenLastCalledWith('C','OTHER') wrapper.unmount() }) })