feat: add avatar chat and knowledge workflow
This commit is contained in:
99
digital-avatar-app/scripts/avatar-page-data.test.mjs
Normal file
99
digital-avatar-app/scripts/avatar-page-data.test.mjs
Normal file
@@ -0,0 +1,99 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
import {
|
||||
buildAvatarUpdatePayload,
|
||||
normalizeAvatarEditForm,
|
||||
pickAvatarId,
|
||||
unwrapListData,
|
||||
} from '../src/utils/avatar-page-data.js'
|
||||
|
||||
assert.deepEqual(unwrapListData([{ id: 'a1' }]), [{ id: 'a1' }], 'unwrapListData should return raw arrays')
|
||||
assert.deepEqual(
|
||||
unwrapListData({ data: [{ id: 'a2' }], total: 1 }),
|
||||
[{ id: 'a2' }],
|
||||
'unwrapListData should unwrap wrapped collection payloads'
|
||||
)
|
||||
assert.deepEqual(unwrapListData(null), [], 'unwrapListData should fall back to an empty list')
|
||||
|
||||
assert.equal(
|
||||
pickAvatarId('current-id', [{ id: 'first-id' }]),
|
||||
'current-id',
|
||||
'pickAvatarId should prefer current avatar id'
|
||||
)
|
||||
assert.equal(
|
||||
pickAvatarId('', [{ id: 'first-id' }]),
|
||||
'first-id',
|
||||
'pickAvatarId should fall back to the first avatar id'
|
||||
)
|
||||
assert.equal(pickAvatarId('', []), null, 'pickAvatarId should return null when no avatar exists')
|
||||
|
||||
assert.deepEqual(
|
||||
normalizeAvatarEditForm({
|
||||
name: '我的分身',
|
||||
displayName: '会会助手',
|
||||
description: '描述',
|
||||
status: 'inactive',
|
||||
photoUrl: 'https://img.example/avatar.png',
|
||||
config: { replyStyle: 'friendly', creativity: 72, rigor: 88, humor: 16, responseLength: 'short', systemPrompt: '不要编造', autoReply: false },
|
||||
}),
|
||||
{
|
||||
name: '我的分身',
|
||||
displayName: '会会助手',
|
||||
description: '描述',
|
||||
status: 'inactive',
|
||||
photoUrl: 'https://img.example/avatar.png',
|
||||
replyStyle: 'friendly',
|
||||
creativity: 72,
|
||||
rigor: 88,
|
||||
humor: 16,
|
||||
responseLength: 'short',
|
||||
systemPrompt: '不要编造',
|
||||
autoReply: false,
|
||||
},
|
||||
'normalizeAvatarEditForm should map API avatars into edit form state'
|
||||
)
|
||||
|
||||
assert.deepEqual(
|
||||
buildAvatarUpdatePayload({
|
||||
name: '更新后的分身',
|
||||
displayName: '更新后的助手',
|
||||
description: '新描述',
|
||||
status: 'active',
|
||||
photoUrl: 'https://img.example/new-avatar.png',
|
||||
replyStyle: 'casual',
|
||||
creativity: 65,
|
||||
rigor: 70,
|
||||
humor: 25,
|
||||
responseLength: 'medium',
|
||||
systemPrompt: '回答简洁',
|
||||
autoReply: true,
|
||||
}),
|
||||
{
|
||||
name: '更新后的分身',
|
||||
displayName: '更新后的助手',
|
||||
description: '新描述',
|
||||
status: 'active',
|
||||
photoUrl: 'https://img.example/new-avatar.png',
|
||||
config: {
|
||||
replyStyle: 'casual',
|
||||
creativity: 65,
|
||||
rigor: 70,
|
||||
humor: 25,
|
||||
responseLength: 'medium',
|
||||
systemPrompt: '回答简洁',
|
||||
autoReply: true,
|
||||
},
|
||||
},
|
||||
'buildAvatarUpdatePayload should emit API-ready update payloads'
|
||||
)
|
||||
|
||||
const knowledgeView = fs.readFileSync(path.resolve('src/views/KnowledgeManage.vue'), 'utf8')
|
||||
assert.match(knowledgeView, /文档知识库/, 'knowledge page should expose the document tab')
|
||||
assert.match(knowledgeView, /标准问答对/, 'knowledge page should expose the QA tab')
|
||||
assert.match(knowledgeView, /activeTab/, 'knowledge page should switch active tabs')
|
||||
assert.match(knowledgeView, /accept="\.md,\.txt,\.pdf,\.doc,\.docx,\.xlsx"/, 'knowledge page should accept md and txt')
|
||||
assert.match(knowledgeView, /table-scroll/, 'knowledge page should use a scrollable table wrapper')
|
||||
|
||||
console.log('avatar-page-data tests passed')
|
||||
Reference in New Issue
Block a user