it('mounts procurement list with customer candidates and real data',async()=>{constwrapper=mountPage(PurchaseOrdersView);awaitflushPromises();expect(listOverseasPurchaseCustomerOptions).toHaveBeenCalled();expect(listOverseasPurchases).toHaveBeenCalledWith({page: 1,size: 20,customerId:'',orderNo:'',purchaseCategory:'',productName:''});expect(wrapper.text()).toContain('OP-100');expect(wrapper.text()).toContain('待出库');expect(wrapper.text()).toContain('2026-08-01 10:00')})
it('refreshes the cached procurement list after returning from detail or edit',()=>{expect(purchaseListSource).toContain('onActivated');expect(purchaseListSource).toMatch(/onActivated\(\(\) => \{ if \(activatedOnce\) void load\(\)/)})
it('refreshes the cached procurement detail after an edit completes',()=>{expect(purchaseDetailSource).toContain('onActivated');expect(purchaseDetailSource).toMatch(/onActivated\(\(\) => \{ if \(activatedOnce\) void load\(\)/)})
it('mounts procurement detail operation history without exposing internal operator ids',async()=>{routing.route.params={purchaseId:'OP-100'};routing.route.query={customerId:'10001'};constwrapper=mountPage(PurchaseOrderDetailView);awaitflushPromises();expect(getOverseasPurchase).toHaveBeenCalledWith('OP-100','10001');expect(wrapper.text()).toContain('操作流水');expect(wrapper.text()).toContain('编辑');expect(wrapper.text()).not.toContain('INTERNAL-OPERATOR-7')})
it('reviews a pending procurement from its detail page',async()=>{constpending={...purchase,status:'PENDING_REVIEW'asconst,inboundQuantity: 0,inventoryQuantity: 0,version: 2};routing.route.params={purchaseId:'OP-100'};routing.route.query={customerId:'10001'};vi.mocked(getOverseasPurchase).mockResolvedValue(pending);vi.mocked(reviewOverseasPurchase).mockResolvedValue({...pending,status:'APPROVED',version: 3});constwrapper=mountPage(PurchaseOrderDetailView);awaitflushPromises();awaitwrapper.findAll('button').find((button)=>button.text().includes('通过'))?.trigger('click');awaitwrapper.vm.$nextTick();constreviewDialog=wrapper.findAllComponents(AppDialog)[0];expect(reviewDialog.props('modelValue')).toBe(true);reviewDialog.vm.$emit('confirm');awaitflushPromises();expect(reviewOverseasPurchase).toHaveBeenCalledWith('OP-100','10001',expect.objectContaining({version: 2,decision:'APPROVE',idempotencyKey: expect.any(String)}));expect(wrapper.text()).toContain('已通过');expect(wrapper.find('.header-actions').exists()).toBe(false);expect(wrapper.get('.density-back').text()).toBe('返回列表')})
it('submits procurement explicit null clears and keeps a 409 visible without local overwrite',async()=>{routing.route.params={purchaseId:'OP-100'};routing.route.query={customerId:'10001'};vi.mocked(updateOverseasPurchase).mockRejectedValue(newApiResponseError('订单版本冲突,请刷新后重试','B0409',409));constwrapper=mountPage(PurchaseOrderEditView);awaitflushPromises();constproductUrl=wrapper.findAll('.el-form-item').find((item)=>item.text().startsWith('商品链接'))!.find('input');constdomesticCarrier=wrapper.findAll('.el-form-item').find((item)=>item.text().startsWith('国内承运商'))!.find('input');awaitproductUrl.setValue('');awaitdomesticCarrier.setValue('');wrapper.findComponent({name:'ElSelect'}).vm.$emit('update:modelValue',null);wrapper.findComponent({name:'ElDatePicker'}).vm.$emit('update:modelValue',null);awaitwrapper.vm.$nextTick();awaitwrapper.findAll('button').find((button)=>button.text().trim()==='保存')?.trigger('click');awaitflushPromises();expect(updateOverseasPurchase).toHaveBeenCalledWith('OP-100','10001',expect.objectContaining({version: 3,productUrl: null,domesticCarrier: null,estimatedArrivalAt: null,purchaseWarehouseId: null}));expect(document.body.textContent).toContain('订单版本冲突,请刷新后重试');expect((productUrl.elementasHTMLInputElement).value).toBe('');expect((domesticCarrier.elementasHTMLInputElement).value).toBe('');expect(routing.push).not.toHaveBeenCalled()})
it('keeps procurement list usable when customer candidates fail',async()=>{vi.mocked(listOverseasPurchaseCustomerOptions).mockRejectedValue(newError('candidate unavailable'));constwrapper=mountPage(PurchaseOrdersView);awaitflushPromises();expect(listOverseasPurchases).toHaveBeenCalled();expect(wrapper.text()).toContain('OP-100');expect(wrapper.text()).not.toContain('candidate unavailable')})
it('loads procurement edit data but blocks unsafe warehouse selection when candidates fail',async()=>{routing.route.params={purchaseId:'OP-100'};routing.route.query={customerId:'10001'};vi.mocked(listOverseasPurchaseWarehouseOptions).mockRejectedValue(newError('candidate unavailable'));constwrapper=mountPage(PurchaseOrderEditView);awaitflushPromises();expect(getOverseasPurchase).toHaveBeenCalledWith('OP-100','10001');expect(wrapper.text()).toContain('采购仓候选加载失败');expect(wrapper.text()).toContain('OP-100')})
it('mounts truck list with enabled create and supported types',async()=>{constwrapper=mountPage(TransportOrdersView,{domain:'truck'});awaitflushPromises();expect(listUsTruckOrders).toHaveBeenCalled();expect(wrapper.text()).toContain('TK-200');expect(wrapper.text()).toContain('港口提柜');expect(wrapper.text()).toContain('2026-08-01 10:00');expect(wrapper.findAll('button').find((button)=>button.text().includes('新增订单'))?.attributes('disabled')).toBeUndefined()})
it('keeps truck edit form and version unchanged after a 409',async()=>{routing.route.params={orderId:'TK-200'};routing.route.query={customerId:'10002'};vi.mocked(updateUsTruckOrder).mockRejectedValue(newApiResponseError('订单版本冲突','B0409',409));constwrapper=mountPage(TransportOrderFormView,{domain:'truck'});awaitflushPromises();constdestination=wrapper.find('input[placeholder="城市 / 州"]');awaitdestination.setValue('Ontario-MARKER-EDIT');awaitwrapper.findAll('button').find((button)=>button.text().includes('保存修改'))?.trigger('click');awaitflushPromises();expect(updateUsTruckOrder).toHaveBeenCalledWith('TK-200','10002',expect.objectContaining({version: 1,destination:'Ontario-MARKER-EDIT'}));expect((destination.elementasHTMLInputElement).value).toBe('Ontario-MARKER-EDIT');expect(document.body.textContent).toContain('订单版本冲突');expect(routing.push).not.toHaveBeenCalled()})
it('loads the real looseboard list',async()=>{constwrapper=mountPage(TransportOrdersView,{domain:'looseboard'});awaitflushPromises();expect(listLocalLooseboardOrders).toHaveBeenCalledWith({page: 1,size: 20,orderNo:'',routeKeyword:'',status:''});expect(wrapper.text()).toContain('LB-300');expect(wrapper.text()).toContain('待接单');expect(wrapper.text()).toContain('2026-08-01 10:00');expect(listUsTruckOrders).not.toHaveBeenCalled()})
it('loads and submits pending-acceptance looseboard edit with PUT adapter',async()=>{routing.route.params={orderId:'LB-300'};routing.route.query={customerId:'10003'};constwrapper=mountPage(TransportOrderFormView,{domain:'looseboard'});awaitflushPromises();awaitwrapper.findAll('button').find((button)=>button.text().includes('保存修改'))?.trigger('click');awaitflushPromises();expect(getLocalLooseboardOrder).toHaveBeenCalledWith('LB-300','10003');expect(updateLocalLooseboardOrder).toHaveBeenCalledWith('LB-300','10003',expect.objectContaining({version: 0,transportMode:'SHARED_TRUCK',palletRequired:'YES'}))})
it('keeps looseboard edit form and version unchanged after a 409',async()=>{routing.route.params={orderId:'LB-300'};routing.route.query={customerId:'10003'};vi.mocked(updateLocalLooseboardOrder).mockRejectedValue(newApiResponseError('订单版本冲突','B0409',409));constwrapper=mountPage(TransportOrderFormView,{domain:'looseboard'});awaitflushPromises();constdestination=wrapper.find('input[placeholder="城市 / 州"]');awaitdestination.setValue('ONT-MARKER-EDIT');awaitwrapper.findAll('button').find((button)=>button.text().includes('保存修改'))?.trigger('click');awaitflushPromises();expect(updateLocalLooseboardOrder).toHaveBeenCalledWith('LB-300','10003',expect.objectContaining({version: 0,destination:'ONT-MARKER-EDIT'}));expect((destination.elementasHTMLInputElement).value).toBe('ONT-MARKER-EDIT');expect(document.body.textContent).toContain('订单版本冲突');expect(routing.push).not.toHaveBeenCalled()})
it('mounts looseboard create without a detail route or pending notice',async()=>{constwrapper=mountPage(TransportOrderFormView,{domain:'looseboard'});awaitflushPromises();expect(wrapper.text()).toContain('客户信息');expect(wrapper.text()).toContain('请选择客户');expect(wrapper.text()).not.toContain('接口能力待后端补齐');expect(wrapper.findAll('button').find((button)=>button.text().includes('提交订单'))?.attributes('disabled')).toBeUndefined()})