cmvr-wms/ruoyi-ui-vue3/tests/runtime/bom-ownership.spec.js
lixiaolong 771574fef7 feat: 完善采购协同、到货照片及验收发票流程
优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
2026-11-23 14:41:42 +08:00

34 lines
3.9 KiB
JavaScript

import {afterEach,expect,it,vi} from 'vitest'
import {mount,flushPromises} from '@vue/test-utils'
import {defineComponent} from 'vue'
import ElementPlus,{ElTable} from 'element-plus'
import Products from '../../src/views/production/product/index.vue'
import Boms from '../../src/views/production/bom/index.vue'
import Editor from '../../src/components/BomEditor/index.vue'
import Attachments from '../../src/components/ProductAttachments/index.vue'
const api=vi.hoisted(()=>({products:vi.fn(),boms:vi.fn(),get:vi.fn(),files:vi.fn()}))
vi.mock('@/utils/permission',()=>({checkPermi:()=>true}))
vi.mock('@/api/production/bom',()=>({listProducts:api.products,listBom:api.boms,getBom:api.get,saveProduct:vi.fn(),delProduct:vi.fn(),bomOptions:vi.fn(),setDefaultBom:vi.fn(),delBom:vi.fn(),copyBom:vi.fn(),bomLogs:vi.fn(),saveBom:vi.fn(),itemOptionPage:vi.fn()}))
vi.mock('@/api/production/product-editions',()=>({productAttachments:api.files,uploadProductAttachment:vi.fn(),cancelProductAttachmentTransfer:vi.fn(),removeProductAttachment:vi.fn(),readProductAttachment:vi.fn()}))
const Layout=defineComponent({template:'<main><slot name="header"/><slot :tableHeight="400"/><slot name="footer"/><slot name="dialogs"/></main>'})
const Workspace=defineComponent({template:'<section><slot name="header"/><slot :tableHeight="400"/></section>'})
const global={plugins:[ElementPlus],components:{BusinessListPage:Layout,BusinessTable:ElTable,DialogWorkspace:Workspace},stubs:{BusinessPageHeader:true,Pagination:true,ProductEditions:true,ProductAttachments:true,ItemPicker:true,ProductPicker:true,TableText:true,BusinessIcon:true},mocks:{$can:()=>true,$canRole:()=>false,$route:{path:'/businessBasics/products',query:{}},$modal:{msgWarning:vi.fn(),msgSuccess:vi.fn()},$confirm:vi.fn(),$dateTime:value=>value}}
let wrapper
afterEach(()=>{wrapper?.unmount();document.body.innerHTML='';vi.clearAllMocks()})
it('product maintenance controls follow server ownership instead of menu access',async()=>{
api.products.mockResolvedValue({rows:[{id:1,itemName:'我的产品',createBy:'alice',editable:true},{id:2,itemName:'他人的产品',createBy:'bob',editable:false}],total:2})
wrapper=mount(Products,{global,attachTo:document.body});await flushPromises();const rows=wrapper.findAll('tbody tr');expect(rows[0].text()).toContain('修改');expect(rows[0].text()).toContain('删除');expect(rows[1].text()).not.toContain('修改');expect(rows[1].text()).not.toContain('删除');expect(rows[1].text()).toContain('bob')
})
it('BOM maintenance is hidden for someone else while viewing remains available',async()=>{
api.boms.mockResolvedValue({rows:[{id:1,itemName:'我的BOM',createBy:'alice',editable:true},{id:2,itemName:'他人的BOM',createBy:'bob',editable:false}],total:2})
wrapper=mount(Boms,{global,attachTo:document.body});await flushPromises();const rows=wrapper.findAll('tbody tr');expect(rows[0].text()).toContain('修改');expect(rows[1].text()).not.toContain('修改');expect(rows[1].text()).toContain('查看')
})
it('opening another users BOM directly still forces read-only mode',async()=>{
api.get.mockResolvedValue({data:{id:2,itemId:20,itemName:'他人的BOM',versionTag:'V1',scopeType:'PUBLIC',editable:false,lines:[]}})
wrapper=mount(Editor,{global,attachTo:document.body});await wrapper.vm.open({id:2});await flushPromises();expect(wrapper.vm.readonly).toBe(true);expect(document.body.textContent).not.toContain('添加用料');expect(document.body.textContent).not.toContain('保存')
})
it('another users product attachments can be read but cannot be uploaded or removed',async()=>{
api.files.mockResolvedValue({data:[{id:'f1',name:'产品资料.pdf',size:200,contentType:'application/pdf'}]})
wrapper=mount(Attachments,{global,attachTo:document.body});await wrapper.vm.open({id:2,itemName:'他人的产品',editable:false});await flushPromises();expect(document.body.textContent).toContain('下载');expect(document.body.textContent).not.toContain('上传附件');expect(document.body.textContent).not.toContain('移除')
})