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

25 lines
2.7 KiB
JavaScript

import {afterEach,expect,it} from 'vitest'
import {mount} from '@vue/test-utils'
import Content from '@/components/NoticeContent/index.vue'
let w
afterEach(()=>w?.unmount())
it('preserves ordered steps, bullet points, indentation and inline emphasis from the editor',()=>{
w=mount(Content,{props:{html:'<p><strong>使用说明:</strong></p><ol><li>第一步</li><li>第二步</li><li class="ql-indent-1">子步骤</li></ol><ul><li>补充说明</li></ul>'}})
expect(w.classes()).toContain('ql-editor');expect(w.findAll('ol>li')).toHaveLength(3);expect(w.findAll('ul>li')).toHaveLength(1);expect(w.find('li.ql-indent-1').text()).toBe('子步骤');expect(w.find('strong').text()).toBe('使用说明:')
})
it('preserves Quill mixed-list markers and checklist metadata',()=>{
w=mount(Content,{props:{html:'<ol><li data-list="ordered"><span class="ql-ui"></span>编号</li><li data-list="bullet">圆点</li></ol><ul data-checked="true"><li>核对项</li></ul>'}})
expect(w.find('li[data-list="ordered"]').exists()).toBe(true);expect(w.find('li[data-list="bullet"]').exists()).toBe(true);expect(w.find('ul[data-checked="true"]').exists()).toBe(true)
})
it('removes executable elements, event handlers and unsafe links while retaining the readable formatting',()=>{
w=mount(Content,{props:{html:'<p onclick="bad()">正文</p><script>hidden</script><iframe src="https://example.com">hidden frame</iframe><a href="javascript:bad()">坏链接</a><img src="x" onerror="bad()"><svg onload="bad()"/><form><input name="password"></form>'}})
expect(w.find('script,iframe,svg,form,input,[onclick],[onerror],[onload]').exists()).toBe(false);expect(w.find('a').attributes('href')).toBeUndefined();expect(w.text()).toContain('正文');expect(w.text()).not.toContain('hidden')
})
it('retains editor colors and alignment but excludes page layout CSS and unrelated classes',()=>{
w=mount(Content,{props:{html:'<p class="ql-align-center malicious-page-class" style="color:red;background-color:rgb(255,255,0);font-size:16px;position:fixed;inset:0;background-image:url(https://example.com)">彩色说明</p><a href="https://example.com">说明链接</a>'}})
const p=w.find('p');expect(p.classes()).toEqual(['ql-align-center']);expect(p.element.style.color).toBe('red');expect(p.element.style.fontSize).toBe('16px');expect(p.element.style.position).toBe('');expect(p.element.style.backgroundImage).toBe('');expect(w.find('a').attributes()).toMatchObject({target:'_blank',rel:'noopener noreferrer'})
})
it('keeps plain text paragraphs usable and handles empty notices',()=>{
w=mount(Content,{props:{html:'第一行\n第二行'}});expect(w.text()).toContain('第一行\n第二行');w.unmount();w=mount(Content,{props:{html:''}});expect(w.text()).toBe('暂无正文')
})