Files
Genarrative/apps/ai-game-creator-shell/tests/resourceDocumentPreviewModel.test.ts
T
suzmii 910862fd06 修复AGC画布交互并识别UI设计JSON
稳定工作台与窗口标题栏状态同步,消除重复更新循环
支持画布右键平移并保留左键框选及资源拖动,完善中断清理
解耦运行不可用提示与资源选中状态
复用原生UI状态校验区分UI设计JSON和普通JSON,接入现有编辑器与代码预览
补充前端和原生回归测试、规范及待验收记录,明确对话历史分页尚未修复
2026-09-16 17:39:23 +08:00

85 lines
2.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
isResourceDocumentPreviewable,
resourceDocumentPreviewMarkdown,
} from '../src/features/resource-canvas/resourceDocumentPreviewModel';
import type { ProjectResource } from '../src/view/project-development/resourceProjectionModel';
function resource(path: string): ProjectResource {
return {
id: path,
path,
label: path,
mediaType: 'text/plain',
category: 'document',
subtype: 'document',
manifestAssetId: 'doc',
sourceLabel: '',
taskTitle: null,
producerTaskId: null,
externalResourceId: null,
referenceResourceIds: [],
dependencies: [],
dependencyDepth: 0,
};
}
describe('resourceDocumentPreviewMarkdown', () => {
it('文档与空行原样进入 Markdown 渲染', () => {
const text = '# 标题\n\n\n|列|\n|-|\n|值|';
expect(
resourceDocumentPreviewMarkdown(resource('docs/design.md'), text),
).toBe(text);
expect(isResourceDocumentPreviewable(resource('docs/design.md'))).toBe(
true,
);
});
it.each([
['game/main.ts', 'typescript'],
['game/main.js', 'javascript'],
['game/main.py', 'python'],
['assets/data.json', 'json'],
['assets/DESIGN.JSON', 'json'],
])('%s 包为 %s 代码块', (path, language) => {
expect(
resourceDocumentPreviewMarkdown(resource(path), ' source\n\n\n'),
).toBe(`\`\`\`${language}\n source\n\n\n\`\`\``);
});
it('JSON 规格按原文代码块预览,不把字段值当 Markdown', () => {
expect(
resourceDocumentPreviewMarkdown(
resource('assets/data.json'),
'{ "text": "# 不应成为标题" }\n',
),
).toBe('```json\n{ "text": "# 不应成为标题" }\n```');
});
it('正文包含 Markdown 围栏时不会逃出代码块', () => {
const text = 'const sample = "````";\n\n\n<script>alert(1)</script>';
expect(
resourceDocumentPreviewMarkdown(resource('game/main.js'), text),
).toBe(`\`\`\`\`\`javascript\n${text}\n\`\`\`\`\``);
});
it('图片没有文档预览入口,内联文档不要求文件路径', () => {
expect(
isResourceDocumentPreviewable({
...resource('assets/image.png'),
mediaType: 'image/png',
subtype: 'image',
}),
).toBe(false);
expect(
isResourceDocumentPreviewable({
...resource(''),
content: '# 回执',
subtype: 'agent-result',
}),
).toBe(true);
expect(isResourceDocumentPreviewable(resource(''))).toBe(false);
});
});