Files
Genarrative/apps/ai-game-creator-shell/tests/resourceDocumentPreviewModel.test.ts
lhk229 994fcd6b20
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
同步 PR375 的前端界面测试契约
更新消息标题、JSON 文档预览和工具条断言

对齐重构后的对话输入盒结构
2026-09-16 06:03:16 +08:00

83 lines
2.3 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'],
])('%s 包为 %s 代码块', (path, language) => {
expect(
resourceDocumentPreviewMarkdown(resource(path), ' source\n\n\n'),
).toBe(`\`\`\`${language}\n source\n\n\n\`\`\``);
});
it('JSON 规格按文档原文预览,不包成代码块', () => {
expect(
resourceDocumentPreviewMarkdown(
resource('assets/data.json'),
' source\n\n\n',
),
).toBe(' source\n\n\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);
});
});