Files
Genarrative/apps/ai-game-creator-shell/tests/resourceGenerationPromptTestUtils.ts
T
suzmii 13b28ebbc7 生成占位与卡下独立浮层,修复引用选择被焦点陷阱阻断
工具点击先在当前栏目创建临时占位卡,生成浮层挂在占位下沿;图片、音效、背景音乐入口一致
占位按项目与草稿 ID 归属宿主临时状态:可拖动、提交绑定任务 ID、成功结果落到占位最新位置
删除占位只隐藏展示,关闭浮层不冒充取消后台任务;失败保留占位与输入引用供重试
生成面板改为非模态浮层:ThemedModal 焦点陷阱曾阻断 portal 到 body 的引用选择器,点选不生效
引用选择器定位加顶边钳制,搜索收窄与键盘选择可用;不再越出视口
参考候选与陈旧引用校验排除 SVG(原生解码不支持),其余 image 类型不额外收窄
任务创建处对参考资产 ID 去重;补浮层真实组件整合、占位模型与拖动、参考模型回归测试
2026-09-17 18:22:39 +08:00

41 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { act, within } from '@testing-library/react';
import {
$createParagraphNode,
$createTextNode,
$getRoot,
type LexicalEditor,
} from 'lexical';
/**
* 往生成面板的提示词输入区写一段文本。
*
* 提示词输入区与聊天、资源快速编辑共用同一个 `@` 引用输入区(Lexical contenteditable)。
* jsdom 没有可用的 DOM SelectionLexical 因此会忽略浏览器输入事件——`userEvent.type` 与
* `beforeinput` 都不会落字,`fireEvent.change` 更不适用。所以这条链路只能在编辑器实例上做
* 等价更新:仍然走 Lexical 的 `update()` → `OnChangePlugin` → 面板状态,断言的是面板真正收到
* 的提示词与引用。浏览器里的真实输入路径由引用输入区自己的测试与实机验收覆盖。
*/
export async function typeGenerationPrompt(scope: HTMLElement, text: string) {
const element = within(scope).getByLabelText('生成提示词') as HTMLElement & {
__lexicalEditor?: LexicalEditor;
};
const editor = element.__lexicalEditor;
if (!editor) {
throw new Error('生成提示词输入区不是 Lexical 编辑器');
}
await act(async () => {
editor.update(() => {
const root = $getRoot();
root.clear();
const paragraph = $createParagraphNode();
paragraph.append($createTextNode(text));
root.append(paragraph);
});
});
}
/** 读回提示词输入区当前呈现的文本(contenteditable 没有 `value`)。 */
export function generationPromptText(scope: HTMLElement) {
return within(scope).getByLabelText('生成提示词').textContent ?? '';
}