0797410eef
* 支持从项目, 本地电脑, 主站导入/引用素材. * 页面复杂, 需要足够空间, 作为资源打开时会占满右侧 * 编辑结果作为一种新的美术资源. * 新增素材按钮现在是空的实现, 临时在旁边加了一个新增UI设计的按钮 临时入口:  简化: * 组件实现了最基本的图片和文本 * 容器式布局未接入llm编辑 * 不同阶段统一维护一个状态State, 任何阶段都可以人工调整, 不设单独的步骤 * 多图的UI合并功能暂时不要求, 隐藏入口 * 因为生成工具尚未从主站迁移, 主站地图子画布未实现, 以tab栏的形式容纳素材的子画布需求搁置 * 未实现llm绑定字体功能 * 识别会替换现有UI树, 暂时不是增量的 Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/170 Co-authored-by: 王德宇 <kvtodev@outlook.com> Co-committed-by: 王德宇 <kvtodev@outlook.com>
74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn() }));
|
|
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
|
|
import {
|
|
createTauriUiDesignStateStore,
|
|
uiDesignStateStore,
|
|
} from '../src/features/ui-editor/uiDesignStateStore';
|
|
|
|
describe('UI 设计 State mock store', () => {
|
|
it('按资源保留快照并拒绝过期 revision', async () => {
|
|
const first = await uiDesignStateStore.load('ui-1');
|
|
first.state.ui_trees.push({} as never);
|
|
await expect(
|
|
uiDesignStateStore.save('ui-1', first.revision, first.state),
|
|
).resolves.toMatchObject({
|
|
status: 'saved',
|
|
revision: 1,
|
|
});
|
|
|
|
await expect(uiDesignStateStore.load('ui-1')).resolves.toMatchObject({
|
|
revision: 1,
|
|
state: { ui_trees: [{}] },
|
|
});
|
|
await expect(
|
|
uiDesignStateStore.save('ui-1', first.revision, first.state),
|
|
).resolves.toMatchObject({ status: 'conflict', current: { revision: 1 } });
|
|
});
|
|
|
|
it('通过专用 Tauri 命令提交项目身份和资源 CAS revision', async () => {
|
|
const store = createTauriUiDesignStateStore('/tmp/project', 'project-1');
|
|
const state = {
|
|
ui_trees: [],
|
|
ui_design_images: {},
|
|
sprite_assets: {},
|
|
font_assets: {},
|
|
};
|
|
vi.mocked(invoke).mockResolvedValueOnce({ revision: 3, state });
|
|
await expect(store.load('asset-1')).resolves.toEqual({
|
|
revision: 3,
|
|
state,
|
|
});
|
|
expect(invoke).toHaveBeenLastCalledWith('load_ui_design_state', {
|
|
input: {
|
|
projectPath: '/tmp/project',
|
|
expectedProjectId: 'project-1',
|
|
assetId: 'asset-1',
|
|
},
|
|
});
|
|
|
|
vi.mocked(invoke).mockResolvedValueOnce({
|
|
status: 'saved',
|
|
state,
|
|
revision: 4,
|
|
committedProjectRevision: 18,
|
|
});
|
|
await expect(store.save('asset-1', 3, state)).resolves.toMatchObject({
|
|
status: 'saved',
|
|
revision: 4,
|
|
});
|
|
expect(invoke).toHaveBeenLastCalledWith('save_ui_design_state', {
|
|
input: {
|
|
projectPath: '/tmp/project',
|
|
expectedProjectId: 'project-1',
|
|
assetId: 'asset-1',
|
|
expectedRevision: 3,
|
|
state,
|
|
},
|
|
});
|
|
});
|
|
});
|