city_vocational_college/tests/flow-catalog.test.js

95 lines
3.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 直接执行设计器使用的节点目录,防止裁剪业务模块时留下可拖入的专用节点,
* 或误删仍需绑定真实设备的通用动作。SVG 仅转换为资源 URL,不替换节点配置。
*/
import assert from 'node:assert/strict'
import { registerHooks } from 'node:module'
import test from 'node:test'
import { getDeviceKindForAction } from '../src/utils/robotDevice.js'
import { addValueProperty } from '../src/utils/flow.js'
const assetHooks = registerHooks({
/**
* 为 Node 提供浏览器构建中 SVG 默认导出的等价 URL,使测试可执行真实配置模块。
* @param {string} url 已解析的模块地址。
* @param {Object} context Node 模块加载上下文。
* @param {Function} nextLoad 其他模块的默认加载器。
* @returns {Object} SVG 的模块源码,或默认加载器的加载结果。
*/
load(url, context, nextLoad) {
if (url.endsWith('.svg')) {
return { format: 'module', source: `export default ${JSON.stringify(url)}`, shortCircuit: true }
}
return nextLoad(url, context)
},
})
// 项目标识由 Vite define 注入;测试使用独立项目的实际标识执行同一份配置。
globalThis.__PROJECT_NAME__ = 'city_vocational_college'
const { collapseList } = await import('../src/views/flow/config.js')
assetHooks.deregister()
delete globalThis.__PROJECT_NAME__
test('组件库不再提供被移除方案、语料、触控路径和AI评估业务的节点', () => {
const retiredActions = new Set([
'VI_SCHEME', 'VI_CORPUS_WAKE', 'VI_CORPUS_SINGLE', 'VI_CORPUS_CONTINUOUS', 'VI_PLAY_CORPUS',
'TI_PATH_SEARCH', 'TI_TOUCH_COORDINATES', 'AI_EVALUATION_PRE', 'AI_EVALUATION_END',
])
const exposedActions = collapseList.flatMap(group => group.nodeList)
.filter(node => retiredActions.has(node.action))
.map(node => node.action)
assert.deepEqual(exposedActions, [])
})
test('机器人组件库保留触控、说话和表情动作,并匹配正确的实体设备', () => {
const robotNodes = collapseList.find(group => group.collapseTitle === '机器人')?.nodeList || []
const expectedDeviceKinds = [
['TOUCH', 2],
['BIO_HEAD_SPEAK_START', 4],
['BIO_HEAD_SPEAK_STOP', 4],
['BIO_HEAD_SPECIAL_EXPRESSION', 4],
]
for (const [action, deviceKind] of expectedDeviceKinds) {
const node = robotNodes.find(item => item.action === action)
assert.ok(node, `机器人组件库缺少通用动作 ${action}`)
assert.equal(node.nodeType, 'EDGE')
assert.equal(getDeviceKindForAction(action), deviceKind)
}
const audioNodes = collapseList.find(group => group.collapseTitle === '音频')?.nodeList || []
assert.ok(audioNodes.some(node => node.action === 'SPEAKER_PLAYAUDIO'))
assert.equal(getDeviceKindForAction('SPEAKER_PLAYAUDIO'), 13)
})
test('已移除的语料专用动作不再参与设备资源匹配', () => {
assert.equal(getDeviceKindForAction('VI_PLAY_CORPUS'), undefined)
})
test('通用设备指令继续限定机械臂设备,避免设备选择器列出其他终端', () => {
const node = collapseList.flatMap(group => group.nodeList)
.find(item => item.action === 'DEVICE_EXECUTE_JSON_COMMAND')
assert.ok(node)
assert.equal(node.nodeType, 'EDGE')
assert.equal(getDeviceKindForAction(node.action), 2)
})
test('运行参数按类型递归初始化,参数名称不再触发已移除方案的专用默认值', () => {
const parameters = addValueProperty([
{ name: 'schemeId', type: 'number' },
{ name: 'enabled', type: 'boolean' },
{ name: 'settings', type: 'object', children: [
{ name: 'items', type: 'array<string>' },
{ name: 'label', type: 'string' },
] },
])
assert.equal(parameters[0].value, 0)
assert.equal(parameters[1].value, false)
assert.equal(parameters[2].children[0].value, '[0]')
assert.equal(parameters[2].children[1].value, '')
assert.equal(parameters[2].children[1].propPath, '.2.children.1.')
})