cmvr-wms/ruoyi-ui-vue3/tests/runtime/notice-attachments.spec.js
lixiaolong 89c962223a feat(warehouse): 优化采购报价权限控制和文件管理功能
- 实现基于角色的采购报价权限检查,仅超级管理员和采购经理角色可查看报价
- 替换原有的仓库采购管理权限检查为新的报价权限函数
- 在采购单据组件中更新报价字段显示权限逻辑
- 集成文件管理功能,支持文档附件上传下载
- 添加移动端应用更新提示和发布功能
- 增强采购历史更正服务的安全访问控制
- 重构报价访问工具类以支持细粒度字段过滤
- 添加单元测试验证新的权限控制逻辑
2026-10-29 09:58:51 +08:00

15 lines
1.6 KiB
JavaScript

import {afterEach,expect,it,vi} from 'vitest'
import {mount,flushPromises} from '@vue/test-utils'
import ElementPlus from 'element-plus'
import * as icons from '@element-plus/icons-vue'
import Detail from '@/layout/components/HeaderNotice/DetailView.vue'
const api=vi.hoisted(()=>({get:vi.fn()}))
vi.mock('@/api/system/notice',()=>({getNotice:api.get}))
vi.mock('@/api/system/files',()=>({downloadFile:vi.fn(),fileSize:n=>String(n)}))
let w
afterEach(()=>{w?.unmount();document.body.innerHTML='';vi.resetAllMocks()})
function page(){w=mount(Detail,{attachTo:document.body,global:{plugins:[ElementPlus],components:icons,stubs:{ManagedAttachments:{props:['modelValue'],template:'<div class="attachment-fixture">{{ modelValue.map(f=>f.name).join() }}</div>'}}}})}
it('opening a preset notice still fetches its saved attachments and ignores a slower previous notice response',async()=>{
let old;api.get.mockImplementationOnce(()=>new Promise(resolve=>{old=resolve})).mockResolvedValueOnce({data:{noticeId:2,noticeTitle:'第二份公告',noticeContent:'内容',status:'0',attachments:[{id:'two',name:'操作手册.pdf'}]}});page();w.vm.open({noticeId:1,noticeTitle:'旧公告',noticeContent:'已有列表内容'});await w.vm.open({noticeId:2,noticeContent:'列表内容'});await flushPromises();expect(api.get).toHaveBeenCalledTimes(2);expect(document.body.textContent).toContain('操作手册.pdf');old({data:{noticeId:1,noticeTitle:'迟到的内容',attachments:[]}});await flushPromises();expect(document.body.textContent).toContain('操作手册.pdf');expect(document.body.textContent).not.toContain('迟到的内容')
})