58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
const assert = require('node:assert/strict')
|
|
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
|
|
const pagePath = path.resolve(__dirname, '../pages/ai-house/index.vue')
|
|
const source = fs.readFileSync(pagePath, 'utf8')
|
|
const scriptMatch = source.match(/<script>([\s\S]*?)<\/script>/)
|
|
|
|
assert.ok(scriptMatch, '未找到 AI 找房页面脚本')
|
|
|
|
const componentScript = scriptMatch[1]
|
|
.replace(/^\s*import .*$/gm, '')
|
|
.replace('export default {', 'return {')
|
|
const component = new Function(
|
|
'HouseAiConfigApi',
|
|
'HouseAiChatApi',
|
|
'storage',
|
|
'USER_ID',
|
|
'apiUrl',
|
|
componentScript
|
|
)({}, {}, {}, 'userId', 'http://localhost')
|
|
|
|
function createPageVm() {
|
|
const vm = component.data()
|
|
Object.entries(component.methods).forEach(([name, method]) => {
|
|
vm[name] = method.bind(vm)
|
|
})
|
|
vm.scrollToBottom = () => {}
|
|
return vm
|
|
}
|
|
|
|
const vm = createPageVm()
|
|
vm.handleSocketMessage(JSON.stringify({
|
|
type: 'house_ai_result',
|
|
answer: '航洋城附近通勤方便,停车以现场政策为准。',
|
|
locationCards: [{
|
|
locationId: 101,
|
|
locationName: '航洋城',
|
|
knowledgeItems: [{ title: '停车' }]
|
|
}],
|
|
houses: [{
|
|
houseId: 201,
|
|
houseTitle: '航洋城附近两居室',
|
|
files: []
|
|
}]
|
|
}))
|
|
|
|
assert.equal(vm.messages.filter((message) => message.type === 'location').length, 0,
|
|
'地点资料不应在小程序中创建卡片消息')
|
|
assert.equal(vm.messages.filter((message) => message.type === 'text').length, 1,
|
|
'地点资料应由 AI 直接组织为文本回答')
|
|
assert.equal(vm.messages.find((message) => message.type === 'text').content,
|
|
'航洋城附近通勤方便,停车以现场政策为准。')
|
|
assert.equal(vm.messages.filter((message) => message.type === 'list').length, 1,
|
|
'房源结果仍应创建房源卡片消息')
|
|
|
|
console.log('地点资料仅由 AI 组织为文本,页面不渲染地点卡片')
|