5cd02aa8b0
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 2m44s
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m45s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 2m46s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 2m49s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m53s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 3m18s
Project CI / Frontend tests (pull_request) Failing after 4m6s
Project CI / Native shell tests (pull_request) Successful in 6m12s
Project CI / Repository checks (pull_request) Failing after 3m48s
Project CI / Backend tests (pull_request) Successful in 7m8s
Project CI / AI game creator shell web tests (pull_request) Failing after 3m59s
当前Agent与策划Agent共用正文和过程表现组件,统一思考及工具调用的小字号浅色样式 素材工具栏按实际动作分组,导出紧邻删除并修复空分组重复分隔线 文档与代码使用共享Markdown预览和代码高亮,复用按需读取与缓存 移除未调用的活跃回合查询命令,保留正式快照恢复链路 补充回归用例并同步技术方案和团队约定
127 lines
3.7 KiB
TypeScript
127 lines
3.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
import type { ReactNode } from 'react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { ResourceDocumentPreviewDialog } from '../src/view/project-development/ResourceDocumentPreviewDialog';
|
|
import type { ProjectResource } from '../src/view/project-development/resourceProjectionModel';
|
|
|
|
vi.mock('../src/components/modal/ThemedModal', () => ({
|
|
ThemedModal: ({
|
|
children,
|
|
ariaLabel,
|
|
}: {
|
|
children: ReactNode;
|
|
ariaLabel: string;
|
|
}) => (
|
|
<section role="dialog" aria-label={ariaLabel}>
|
|
{children}
|
|
</section>
|
|
),
|
|
}));
|
|
afterEach(cleanup);
|
|
|
|
const resource: ProjectResource = {
|
|
id: 'doc',
|
|
path: 'docs/design.md',
|
|
label: '设计文档',
|
|
mediaType: 'text/markdown',
|
|
category: 'document',
|
|
subtype: 'document',
|
|
manifestAssetId: 'doc',
|
|
sourceLabel: '',
|
|
taskTitle: null,
|
|
producerTaskId: null,
|
|
externalResourceId: null,
|
|
referenceResourceIds: [],
|
|
dependencies: [],
|
|
dependencyDepth: 0,
|
|
};
|
|
|
|
describe('ResourceDocumentPreviewDialog', () => {
|
|
it('加载时通过现有详情回调请求正文,加载完成复用 Markdown 渲染', () => {
|
|
const onRequestPreview = vi.fn();
|
|
const onClose = vi.fn();
|
|
const props = { resource, identity: 'doc:v1', onRequestPreview, onClose };
|
|
const { rerender } = render(
|
|
<ResourceDocumentPreviewDialog
|
|
{...props}
|
|
preview={{ status: 'loading' }}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole('status').textContent).toContain('加载');
|
|
expect(onRequestPreview).toHaveBeenCalledWith(resource, 'doc:v1', 'detail');
|
|
rerender(
|
|
<ResourceDocumentPreviewDialog
|
|
{...props}
|
|
preview={{
|
|
status: 'loaded',
|
|
preview: {
|
|
path: resource.path,
|
|
mediaType: resource.mediaType,
|
|
byteLen: 10,
|
|
content: '# 标题\n\n**正文**',
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole('heading', { name: '标题' })).toBeTruthy();
|
|
fireEvent.click(screen.getByRole('button', { name: '关闭文档预览' }));
|
|
expect(onClose).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('失败显示错误与重试,换资源进入加载态时不残留旧正文', () => {
|
|
const onRequestPreview = vi.fn();
|
|
const props = {
|
|
resource,
|
|
identity: 'doc:v1',
|
|
onRequestPreview,
|
|
onClose: vi.fn(),
|
|
};
|
|
const { rerender } = render(
|
|
<ResourceDocumentPreviewDialog
|
|
{...props}
|
|
preview={{
|
|
status: 'failed',
|
|
error: '文档读取失败',
|
|
retryable: true,
|
|
}}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole('alert').textContent).toBe('文档读取失败');
|
|
onRequestPreview.mockClear();
|
|
fireEvent.click(screen.getByRole('button', { name: '重试' }));
|
|
expect(onRequestPreview).toHaveBeenCalledWith(resource, 'doc:v1', 'detail');
|
|
rerender(
|
|
<ResourceDocumentPreviewDialog
|
|
{...props}
|
|
identity="doc:v2"
|
|
preview={{ status: 'loading' }}
|
|
/>,
|
|
);
|
|
expect(screen.queryByRole('alert')).toBeNull();
|
|
expect(screen.getByRole('status').textContent).toContain('加载');
|
|
});
|
|
|
|
it('空文档显示空态而不是永久加载', () => {
|
|
render(
|
|
<ResourceDocumentPreviewDialog
|
|
resource={resource}
|
|
identity="doc:v1"
|
|
onRequestPreview={vi.fn()}
|
|
onClose={vi.fn()}
|
|
preview={{
|
|
status: 'loaded',
|
|
preview: {
|
|
path: resource.path,
|
|
mediaType: resource.mediaType,
|
|
byteLen: 0,
|
|
content: '',
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole('status').textContent).toBe('文档为空');
|
|
});
|
|
});
|