c1ffb2386b
- 删除 resourceReferences.ts 中 mediaType 优先的 7 桶筛选口径与 resourceReferenceFilterKind,改由 resourceReferenceCategory / resourceReferenceMatchesCategoryFilter 以 manifest 资产 category 为唯一权威筛选口径 - RESOURCE_REFERENCE_FILTERS 改为 6 类 + 全部(全部 / UI 交互 / 角色与对象 / 场景与环境 / 音频 / 文档 / 待归类),并新增 resourceReferenceCategoryLabel 让中文名只定义一处 - ResourceReference 新增 category / tags,由 resourceReferenceFromAsset 经 gameCreationAppAssetCategory / gameCreationAppAssetTags 从 manifest 资产投影;资源画布 ProjectResource 同步新增 assetCategory / assetTags 投影与 projectResourceAssetCategory 待归类兜底 - 新增 Tauri 命令 update_local_project_resource_classification 与 UpdateLocalProjectResourceClassificationInput/Result,实现落在 project/manifest.rs 的 update_manifest_asset_classification_at,复用既有 mutate_manifest_at manifest 写锁与原子写入 - 命令持项目写锁后按 expectedProjectId / expectedProjectRevision 做 CAS,冲突分别返回 project-identity-conflict 与 project-revision-conflict;category 非 6 个合法值即报错且不回退到 kind 派生;tags 走 normalize_game_creation_app_asset_tags;只改目标条目的 category / tags 并在成功后推进一次项目 revision - 新增 Rust 定向测试 project/manifest/classification_tests.rs:更新成功、非法分类被拒、tags 归一化、未引用资产更新不影响其它字段、revision/CAS 与既有写入一致、输入拒绝未知字段 - 前端新增 ResourceClassificationPanel(ThemedModal + PlatformSegmentedTabs + PlatformTextField),资源详情面板以「分类与标签」按钮打开独立面板,保存后重读 manifest 并经 onManifestChange 反映到筛选与投影 - @ 面板与资源画布共用 packages/shared 的 PlatformSegmentedTabs 渲染同一组功能分类标签;画布筛选状态与画布视口一样按「按依赖 / 按类型」分别保存,复用既有 sortMode 状态形状 - 更新 resourceReferenceInput.test.tsx 与 projectResourceProjectionModel.test.ts 覆盖新口径,新增 resourceClassificationPanel.test.tsx 覆盖写入命令的输入归一化与失败不回退 - 同步技术方案与 decision-log:记录按 mediaType 分类到按 category 分类的语义变化(图片 / 视频桶消失,image / video / code / publication-material 归待归类)与新写入命令契约
152 lines
4.5 KiB
TypeScript
152 lines
4.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
|
|
import type { GameCreationAppAssetManifestEntry } from '../../../packages/shared/src/contracts/gameCreationApp';
|
|
import { ResourceClassificationPanel } from '../src/view/project-development/ResourceClassificationPanel';
|
|
|
|
const asset: GameCreationAppAssetManifestEntry = {
|
|
id: 'asset-hero',
|
|
kind: 'character',
|
|
mediaType: 'image/png',
|
|
localPath: 'assets/hero.png',
|
|
source: { kind: 'uploaded' },
|
|
category: 'character',
|
|
tags: ['主角'],
|
|
};
|
|
|
|
function installInvoke(
|
|
implementation: (command: string, args?: unknown) => Promise<unknown>,
|
|
) {
|
|
const invoke = vi.fn(implementation);
|
|
(
|
|
window as unknown as {
|
|
__TAURI__?: { core?: { invoke?: typeof invoke } };
|
|
}
|
|
).__TAURI__ = { core: { invoke } };
|
|
return invoke;
|
|
}
|
|
|
|
function removeInvoke() {
|
|
delete (
|
|
window as unknown as {
|
|
__TAURI__?: { core?: { invoke?: unknown } };
|
|
}
|
|
).__TAURI__;
|
|
}
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
removeInvoke();
|
|
});
|
|
|
|
describe('ResourceClassificationPanel', () => {
|
|
test('writes the category and normalized tags through the controlled native command', async () => {
|
|
const user = userEvent.setup();
|
|
const onSaved = vi.fn();
|
|
const invoke = installInvoke(async (command) => {
|
|
if (command === 'get_local_game_project_revision') {
|
|
return { revision: 7 };
|
|
}
|
|
if (command === 'update_local_project_resource_classification') {
|
|
return {
|
|
asset: { ...asset, category: 'scene', tags: ['主舞台', '日夜'] },
|
|
committedProjectRevision: 8,
|
|
};
|
|
}
|
|
throw new Error(`unexpected command: ${command}`);
|
|
});
|
|
|
|
render(
|
|
<ResourceClassificationPanel
|
|
projectPath="C:/project"
|
|
projectId="project-1"
|
|
asset={asset}
|
|
onClose={vi.fn()}
|
|
onSaved={onSaved}
|
|
/>,
|
|
);
|
|
|
|
await user.click(screen.getByRole('button', { name: '场景与环境' }));
|
|
const tagsField = screen.getByLabelText('资源标签');
|
|
await user.clear(tagsField);
|
|
await user.type(tagsField, ' 主舞台 ,日夜,主舞台、');
|
|
await user.click(screen.getByRole('button', { name: '保存' }));
|
|
|
|
await waitFor(() => {
|
|
expect(onSaved).toHaveBeenCalledTimes(1);
|
|
});
|
|
expect(invoke).toHaveBeenCalledWith(
|
|
'update_local_project_resource_classification',
|
|
expect.objectContaining({
|
|
input: expect.objectContaining({
|
|
projectPath: 'C:/project',
|
|
expectedProjectId: 'project-1',
|
|
expectedProjectRevision: 7,
|
|
assetId: 'asset-hero',
|
|
category: 'scene',
|
|
}),
|
|
}),
|
|
);
|
|
const [, args] = invoke.mock.calls.find(
|
|
([command]) => command === 'update_local_project_resource_classification',
|
|
)!;
|
|
expect((args as { input: { tags: string[] } }).input.tags).toEqual([
|
|
'主舞台',
|
|
'日夜',
|
|
]);
|
|
expect(onSaved.mock.calls[0]?.[0]).toEqual({
|
|
asset: { ...asset, category: 'scene', tags: ['主舞台', '日夜'] },
|
|
committedProjectRevision: 8,
|
|
});
|
|
});
|
|
|
|
test('surfaces the native rejection without reporting a save', async () => {
|
|
const user = userEvent.setup();
|
|
const onSaved = vi.fn();
|
|
installInvoke(async (command) => {
|
|
if (command === 'get_local_game_project_revision') {
|
|
return { revision: 7 };
|
|
}
|
|
throw '非法资源分类:future-category';
|
|
});
|
|
|
|
render(
|
|
<ResourceClassificationPanel
|
|
projectPath="C:/project"
|
|
projectId="project-1"
|
|
asset={asset}
|
|
onClose={vi.fn()}
|
|
onSaved={onSaved}
|
|
/>,
|
|
);
|
|
|
|
await user.click(screen.getByRole('button', { name: '保存' }));
|
|
|
|
await screen.findByRole('alert');
|
|
expect(screen.getByRole('alert').textContent).toContain('非法资源分类');
|
|
expect(onSaved).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('does not attempt a write outside the native client', async () => {
|
|
const user = userEvent.setup();
|
|
const onSaved = vi.fn();
|
|
render(
|
|
<ResourceClassificationPanel
|
|
projectPath="C:/project"
|
|
projectId="project-1"
|
|
asset={asset}
|
|
onClose={vi.fn()}
|
|
onSaved={onSaved}
|
|
/>,
|
|
);
|
|
|
|
await user.click(screen.getByRole('button', { name: '保存' }));
|
|
|
|
await screen.findByRole('alert');
|
|
expect(screen.getByRole('alert').textContent).toContain('客户端');
|
|
expect(onSaved).not.toHaveBeenCalled();
|
|
});
|
|
});
|