cmvr-wms/ruoyi-ui-vue3/tests/runtime/assistant-notice.spec.js
lixiaolong f8f286d2a1 feat(assistant): 新增用户核对功能并优化对话流程
- 新增 user.check 功能用于核对人员是否已有系统账号
- 在 assistant-table-layout.js 中为用户表格添加 checkedIdentity 和 matchResult 字段
- 优化 AssistantConversationService 中的任务记忆和澄清流程
- 支持对草稿特定行进行修改,无需重新填写整张表
- 限制 user.check 操作最大查询数量为 100 条记录
- 实现中断任务恢复机制,保持原始请求上下文
- 添加针对多行数据选择性修改的目标行标识支持
2026-10-27 09:04:41 +08:00

39 lines
2.9 KiB
JavaScript

import { expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import Content from '@/components/BusinessAssistant/AssistantNoticeContent.vue'
import { safeNoticeHtml } from '@/utils/assistant-notice'
vi.mock('@/components/Editor/index.vue', () => ({ default: { name: 'NoticeEditorFixture', props: ['modelValue', 'readOnly'], emits: ['update:modelValue'], template: '<textarea :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />' } }))
it('previews text and real tutorial images without exposing model HTML as plain source', () => {
const row = { noticeTitle: '反馈使用说明', noticeType: '1', noticeContent: '<h3>提交反馈</h3><p>填写标题和说明</p><img src="/static/assistant-guides/feedback-1.svg" alt="操作示意图">' }
const wrapper = mount(Content, { props: { row, editable: true }, global: { plugins: [ElementPlus] } })
expect(wrapper.find('article h3').text()).toBe('提交反馈')
expect(wrapper.find('article img').attributes('src')).toBe('/static/assistant-guides/feedback-1.svg')
expect(wrapper.text()).toContain('确认后发布')
expect(wrapper.find('textarea').exists()).toBe(false)
expect(wrapper.emitted('change')).toBeUndefined()
wrapper.unmount()
})
it('editing emits a draft-only body change while read-only cards have no editor controls', async () => {
const wrapper = mount(Content, { props: { row: { _rowId: 'one', noticeContent: '<p>原文</p>' }, editable: true }, global: { plugins: [ElementPlus] } })
await wrapper.findAll('input[type="radio"]')[1].setValue(true)
await wrapper.find('textarea').setValue('<p>新内容</p>')
expect(wrapper.emitted('change')[0][0]).toEqual({ key: 'noticeContent', value: '<p>新内容</p>' })
await wrapper.setProps({ busy: true })
await wrapper.find('textarea').setValue('<p>忙时不改</p>')
expect(wrapper.emitted('change')).toHaveLength(1)
await wrapper.setProps({ editable: false })
expect(wrapper.find('textarea').exists()).toBe(false)
expect(wrapper.find('.el-radio-group').exists()).toBe(false)
wrapper.unmount()
})
it('never renders scripts, inline handlers, CSS overlays, embedded frames or unsafe image/link schemes', () => {
const html = safeNoticeHtml('<script>alert(1)</script><svg onload="evil()"></svg><p style="position:fixed" onclick="evil()">说明</p><img src="javascript:evil()" onerror="evil()"><a href="jav&#x61;script:evil()">链接</a><iframe src="https://example.invalid"></iframe><img src="//external.invalid/a.png"><img src="/static/assistant-guides/feedback-2.svg">')
const container = document.createElement('div'); container.innerHTML = html
expect(container.querySelectorAll('script,svg,iframe,[onclick],[onerror],[style]')).toHaveLength(0)
expect(container.querySelectorAll('img')).toHaveLength(1)
expect(container.querySelector('a').getAttribute('href')).toBeNull()
expect(container.textContent).toContain('说明')
})