返回 DeepSeek-Reasonix
rich-composer-restored-identity.test.tsx
根目录 / desktop / frontend / src / __tests__ / rich-composer-restored-identity.test.tsx
1 import assert from "node:assert/strict";
2 import React, { act } from "react";
3 import { createRoot } from "react-dom/client";
4 import { installDom } from "./composerInboxHarness";
5 import { RichComposerInput, type RichComposerInputHandle } from "../components/RichComposerInput";
6 import { LocaleProvider } from "../lib/i18n";
7 import type { ComposerInvocation } from "../lib/invocationDisplay";
8
9 const dom=installDom();
10 const root=createRoot(document.getElementById("root")!);
11 const handle=React.createRef<RichComposerInputHandle>();
12 const command={name:"restored-skill",kind:"skill" as const,description:"skill"};
13 let result:ComposerInvocation[]=[];
14 const noop=()=>{};
15 try {
16 await act(async()=>root.render(<LocaleProvider><RichComposerInput ref={handle} text=" /" invocations={[{id:"invocation-1",offset:0,command}]} placeholder="" disabled={false}
17 onSelectionChange={noop} onKeyDown={noop} onContextMenu={noop} onPaste={noop} onCompositionStart={noop} onCompositionEnd={noop}
18 onChange={(_text,items)=>{result=items;}} /></LocaleProvider>));
19 await act(async()=>handle.current!.insertInvocation({...command,name:"new-skill"},{from:1,to:2,query:""}));
20 assert.equal(result.length,2);
21 assert.equal(new Set(result.map(item=>item.id)).size,2,"restored IDs cannot collide with this renderer's counter");
22 assert.equal(result[0].id,"invocation-1","preserve original identity");
23 console.log("PASS restored rich composer invocation identity");
24 } finally {await act(async()=>root.unmount());dom.window.close();}
25
25 lines Plain Text