import {expect,it,vi} from 'vitest' import {mount} from '@vue/test-utils' import ElementPlus from 'element-plus' import Editions from '../../src/components/ProductEditions/index.vue' const api=vi.hoisted(()=>({list:vi.fn(),create:vi.fn(),boms:vi.fn()})) vi.mock('@/api/production/product-editions',()=>({productVersions:api.list,createProductVersion:api.create})) vi.mock('@/api/production/bom',()=>({bomOptions:api.boms,itemOptionPage:vi.fn()})) it('a freely named version generates a separate item spec and never resubmits changed input after timeout',async()=>{ const source={id:7,itemId:70,itemName:'机器人',spec:'R1',version:2};api.list.mockResolvedValue({data:[source]});api.boms.mockResolvedValue({data:[]});api.create.mockRejectedValueOnce({code:'ECONNABORTED',message:'timeout'}).mockResolvedValueOnce({data:{id:8,itemId:80,itemName:'机器人',editionTag:'量产版'}}) const wrapper=mount(Editions,{global:{plugins:[ElementPlus],stubs:{ItemPicker:true},mocks:{$can:()=>true,$modal:{msgWarning:vi.fn(),msgSuccess:vi.fn()}}}}) await wrapper.vm.open(source);await wrapper.vm.start(source);wrapper.vm.form.editionTag='量产版';wrapper.vm.tagChanged();expect(wrapper.vm.form.itemSpec).toBe('R1 / 量产版');wrapper.vm.form.itemSpec='用户自定义规格';wrapper.vm.automaticSpec=false;wrapper.vm.form.editionTag='2026改进款';wrapper.vm.tagChanged();expect(wrapper.vm.form.itemSpec).toBe('用户自定义规格') await wrapper.vm.save();expect(wrapper.vm.attempted).toBe(true);const frozen=api.create.mock.calls[0][0];wrapper.vm.form.editionTag='不能混入重试';await wrapper.vm.save();expect(api.create.mock.calls[1][0]).toEqual(frozen);expect(frozen.editionTag).toBe('2026改进款');expect(wrapper.vm.editing).toBe(false);wrapper.unmount() })