92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
/**
|
|
* features/chat/training/trainingWorkspace.utils.test.ts
|
|
* 用途:锁定培训工作区 Agent 识别契约,以及培训进度项/文本配置的解析规则。
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import { matchesTrainingAgent, resolveLearnerCopyText, resolveLearnerProgressItems } from './trainingWorkspace.utils';
|
|
|
|
describe('matchesTrainingAgent', () => {
|
|
it('matches handler_config.content_profile=training', () => {
|
|
expect(matchesTrainingAgent({
|
|
name: '任意名称',
|
|
handler_config: { content_profile: 'training' },
|
|
})).toBe(true);
|
|
});
|
|
|
|
it('matches explicit extra_config training flags', () => {
|
|
expect(matchesTrainingAgent({
|
|
name: '普通 Agent',
|
|
extra_config: { training_workspace_enabled: true },
|
|
})).toBe(true);
|
|
});
|
|
|
|
it('does not match generic agent by name alone', () => {
|
|
expect(matchesTrainingAgent({ name: '新人培训助手' })).toBe(false);
|
|
});
|
|
|
|
it('respects training_workspace_enabled=false override', () => {
|
|
expect(matchesTrainingAgent({
|
|
handler_config: { content_profile: 'training' },
|
|
extra_config: { training_workspace_enabled: false },
|
|
})).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('resolveLearnerProgressItems', () => {
|
|
it('returns configured progress items in order', () => {
|
|
expect(resolveLearnerProgressItems({
|
|
id: 1,
|
|
trainingType: 'custom',
|
|
version: 'v1',
|
|
passScore: 90,
|
|
settings: {
|
|
progress_items: [
|
|
{ stage: 'video', label: '观看视频' },
|
|
{ stage: 'exam', label: '参加考试' },
|
|
],
|
|
},
|
|
resources: [],
|
|
})).toEqual([
|
|
{ stage: 'video', label: '观看视频' },
|
|
{ stage: 'exam', label: '参加考试' },
|
|
]);
|
|
});
|
|
|
|
it('filters invalid or duplicate items', () => {
|
|
expect(resolveLearnerProgressItems({
|
|
id: 1,
|
|
trainingType: 'custom',
|
|
version: 'v1',
|
|
passScore: 90,
|
|
settings: {
|
|
progress_items: [
|
|
{ stage: 'video', label: '观看视频' },
|
|
{ stage: 'video', label: '重复步骤' },
|
|
{ stage: '', label: '空阶段' },
|
|
{ stage: 'summary', label: '' },
|
|
],
|
|
},
|
|
resources: [],
|
|
})).toEqual([
|
|
{ stage: 'video', label: '观看视频' },
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('resolveLearnerCopyText', () => {
|
|
it('returns trimmed text when configured', () => {
|
|
expect(resolveLearnerCopyText({
|
|
id: 1,
|
|
trainingType: 'custom',
|
|
version: 'v1',
|
|
passScore: 90,
|
|
settings: { progress_hint_text: ' 按要求完成学习 ' },
|
|
resources: [],
|
|
}, 'progress_hint_text')).toBe('按要求完成学习');
|
|
});
|
|
|
|
it('returns empty string for missing text', () => {
|
|
expect(resolveLearnerCopyText(null, 'step_intro_text')).toBe('');
|
|
});
|
|
});
|