cmvr-wms/ruoyi-ui-vue3/tests/runtime/assistant-notification.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

74 lines
5.3 KiB
JavaScript

import { expect, it, vi } from 'vitest'
import { defineComponent } from 'vue'
import { mount, shallowMount, flushPromises } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import Preview from '@/components/BusinessAssistant/AssistantNotificationPreview.vue'
import { assistantApplyDraftChanges, assistantFieldLocked } from '@/utils/assistant-draft-edit'
import { notificationFieldVisible } from '@/utils/assistant-notification'
import Draft from '@/components/BusinessAssistant/AssistantDraft.vue'
vi.mock('@/components/BusinessAssistant/AssistantField.vue', () => ({ default: { template: '<span/>' } }))
const plan = () => ({ recipientVersion: 'synthetic', scope: '全部有效用户', recipientCount: 55, channel: 'INBOX', title: '模拟说明', content: '请使用问题反馈功能。\n这是第二行。', notice: '确认后才发送站内消息', recipients: Array.from({ length: 55 }, (_, i) => ({ id: i + 1, name: `模拟用户${i + 1}`, account: `account${i + 1}` })) })
it('renders full scope, channel, body and actual count and pages all recipients without truncation', async () => {
const wrapper = mount(Preview, { props: { plan: plan() }, global: { plugins: [ElementPlus] } })
await flushPromises()
expect(wrapper.text()).toContain('全部有效用户 · 55 人')
expect(wrapper.text()).toContain('站内消息')
expect(wrapper.find('.notification-body').text()).toContain('这是第二行。')
expect(wrapper.findAll('tbody tr')).toHaveLength(50)
await wrapper.find('.btn-next').trigger('click')
await flushPromises()
expect(wrapper.findAll('tbody tr')).toHaveLength(5)
expect(wrapper.find('tbody').text()).toContain('模拟用户55')
expect(wrapper.findAll('thead th').map(node => node.text())).toEqual(['姓名', '登录账号'])
wrapper.unmount()
})
it('search narrows only review display, resets pagination, and never changes send audience', async () => {
const data = plan()
data.emailRequired = true; data.channel = 'BOTH'; data.recipients[54].email = 'last@example.invalid'
const wrapper = mount(Preview, { props: { plan: data }, global: { plugins: [ElementPlus] } })
await wrapper.find('.btn-next').trigger('click')
await wrapper.find('input').setValue('last@example.invalid')
await flushPromises()
expect(wrapper.findAll('tbody tr')).toHaveLength(1)
expect(wrapper.find('tbody').text()).toContain('模拟用户55')
expect(wrapper.text()).toContain('搜索不改变发送范围')
expect(data.recipients).toHaveLength(55)
expect(wrapper.emitted('execute')).toBeUndefined()
await wrapper.find('input').setValue('nonexistent')
expect(wrapper.text()).toContain('没有匹配的接收人')
await wrapper.setProps({ plan: { ...plan(), recipientVersion: 'new-version' } })
expect(wrapper.find('input').element.value).toBe('')
expect(wrapper.findAll('tbody tr')).toHaveLength(50)
wrapper.unmount()
})
it('recipient mode hides unrelated pickers and keeps inactive cells locked in a mixed draft', () => {
expect(notificationFieldVisible({ key: 'userIds' }, [{ recipientMode: 'ALL' }])).toBe(false)
expect(notificationFieldVisible({ key: 'roleIds' }, [{ recipientMode: 'ROLES' }])).toBe(true)
expect(notificationFieldVisible({ key: 'userIds' }, [{}, { recipientMode: 'ALL' }])).toBe(true)
expect(assistantFieldLocked('notification.send', { recipientMode: 'ALL' }, { key: 'userIds' })).toBe(true)
expect(assistantFieldLocked('notification.send', { recipientMode: 'ROLES' }, { key: 'roleIds' })).toBe(false)
})
it('editing scope, channel or body clears stale full recipient preview and derived version', () => {
const fields = ['recipientMode', 'userIds', 'roleIds', 'channel', 'title', 'content'].map(key => ({ key }))
const source = { _rowId: 'one', recipientMode: 'USERS', userIds: [7], _notificationPreview: plan(), recipientVersion: 'old', recipientSummary: 'old', deliveryNotice: 'old' }
for (const [key, value] of [['recipientMode', 'ROLES'], ['content', 'changed'], ['channel', 'BOTH']]) {
const [changed] = assistantApplyDraftChanges([source], { rowId: 'one', key, value }, { action: 'notification.send', fields })
expect(changed._notificationPreview).toBeUndefined()
expect(changed.recipientVersion).toBeUndefined()
if (key === 'recipientMode') expect(changed.userIds).toBeUndefined()
}
expect(source._notificationPreview).toBeDefined()
})
it('the main confirmation card embeds the full authoritative plan and omits unused recipient pickers', () => {
const column = defineComponent({ props: ['label'], template: '<span>{{ label }}</span>' })
const data = plan(), rows = [{ _rowId: 'one', recipientMode: 'ALL', _notificationPreview: data }]
const wrapper = shallowMount(Draft, { props: { draft: { id: 'synthetic', action: 'notification.send', status: 'WAIT_CONFIRM', fields: [{ key: 'recipientMode', label: '接收范围' }, { key: 'userIds', label: '指定接收人' }, { key: 'roleIds', label: '接收角色' }] }, rows, action: { allowed: true } }, global: { stubs: { ElTable: { template: '<div><slot/></div>' }, ElTableColumn: column } } })
expect(wrapper.findComponent(Preview).props('plan').recipients).toHaveLength(55)
const headers = wrapper.findAllComponents(column).map(node => node.props('label'))
expect(headers).toContain('接收范围')
expect(headers).not.toContain('指定接收人')
expect(headers).not.toContain('接收角色')
wrapper.unmount()
})