48caa23997
canvas生成与运行时统一使用共享GameCreationAppAssetKind 删除平台kind兼容映射与退役kind拒绝测试 更新资源kind审计里程碑与绑定文档
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
type ProjectResourceCardPreviewState,
|
|
projectResourceJsonPresentation,
|
|
} from '../src/view/project-development/resourceCardPreviewModel';
|
|
import type { ProjectResource } from '../src/view/project-development/resourceProjectionModel';
|
|
|
|
const resource: ProjectResource = {
|
|
id: 'asset:json',
|
|
manifestAssetId: 'json',
|
|
path: 'ui/design.json',
|
|
label: '设计',
|
|
mediaType: 'application/json',
|
|
subtype: 'ui-design',
|
|
category: 'document',
|
|
sourceLabel: '',
|
|
taskTitle: null,
|
|
producerTaskId: null,
|
|
externalResourceId: null,
|
|
referenceResourceIds: [],
|
|
dependencies: [],
|
|
dependencyDepth: 0,
|
|
};
|
|
const verified: ProjectResourceCardPreviewState = {
|
|
status: 'loaded',
|
|
preview: {
|
|
path: resource.path,
|
|
mediaType: 'application/json',
|
|
byteLen: 2,
|
|
content: '{}',
|
|
uiDesignAssetId: 'json',
|
|
},
|
|
};
|
|
|
|
describe('JSON 卡片呈现', () => {
|
|
it.each(['ui-design', 'unknown', 'document'] as const)(
|
|
'合法识别不依赖 %s 标签',
|
|
(subtype) => {
|
|
expect(
|
|
projectResourceJsonPresentation({ ...resource, subtype }, verified),
|
|
).toBe('ui-design');
|
|
expect(
|
|
projectResourceJsonPresentation(
|
|
{ ...resource, subtype },
|
|
{
|
|
...verified,
|
|
preview: { ...verified.preview, uiDesignAssetId: undefined },
|
|
},
|
|
),
|
|
).toBe('json');
|
|
},
|
|
);
|
|
it('原生读取未完成、失败或身份不匹配时保持普通 JSON,不推断编辑能力', () => {
|
|
for (const preview of [
|
|
null,
|
|
{ status: 'loading' },
|
|
{ status: 'failed', error: '读取失败', retryable: true },
|
|
] as const) {
|
|
expect(projectResourceJsonPresentation(resource, preview)).toBe('json');
|
|
}
|
|
expect(
|
|
projectResourceJsonPresentation(
|
|
{ ...resource, manifestAssetId: 'other' },
|
|
verified,
|
|
),
|
|
).toBe('json');
|
|
expect(
|
|
projectResourceJsonPresentation(
|
|
{ ...resource, path: 'other.json' },
|
|
verified,
|
|
),
|
|
).toBe('json');
|
|
expect(
|
|
projectResourceJsonPresentation(
|
|
{ ...resource, manifestAssetId: null },
|
|
verified,
|
|
),
|
|
).toBe('json');
|
|
expect(
|
|
projectResourceJsonPresentation(
|
|
{ ...resource, path: 'image.png', mediaType: 'image/png' },
|
|
verified,
|
|
),
|
|
).toBeNull();
|
|
});
|
|
});
|