@@ -2,7 +2,7 @@ import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
22import { describe , expect , it , vi } from "vite-plus/test" ;
33import { page , userEvent } from "vite-plus/test/browser" ;
44
5- import { render } from "../../test/render" ;
5+ import { act , render } from "../../test/render" ;
66import { openCommandPalette } from "../commandPaletteBus" ;
77import { useCommandPaletteStore } from "../commandPaletteStore" ;
88import { makeThreadFixture } from "../test-fixtures" ;
@@ -26,6 +26,56 @@ function setup(state: { projects?: ReadonlyArray<Project>; threads?: ReadonlyArr
2626}
2727
2828describe ( "CommandPalette open intents" , ( ) => {
29+ it ( "drags a searched thread into the current composer without navigating" , async ( ) => {
30+ const environmentId = EnvironmentId . make ( "remote" ) ;
31+ const threadId = ThreadId . make ( "dragged-thread" ) ;
32+ setup ( {
33+ threads : [ makeThreadFixture ( { environmentId, id : threadId , title : "Drag this thread" } ) ] ,
34+ } ) ;
35+ const onDrop = vi . fn ( ) ;
36+ await using screen = await render (
37+ < CommandPalette >
38+ < div
39+ data-thread-context-drop = "true"
40+ ref = { ( node ) => {
41+ node ?. addEventListener ( "t3-thread-context-drop" , onDrop ) ;
42+ } }
43+ style = { { position : "fixed" , bottom : 0 , width : 300 , height : 100 } }
44+ >
45+ Composer
46+ </ div >
47+ </ CommandPalette > ,
48+ ) ;
49+ const pathname = screen . router ?. state . location . pathname ;
50+ openCommandPalette ( { query : "Drag this thread" } ) ;
51+ const row = page . getByRole ( "option" , { name : / D r a g t h i s t h r e a d / } ) ;
52+ await expect . element ( row ) . toBeVisible ( ) ;
53+ const bounds = row . element ( ) . getBoundingClientRect ( ) ;
54+ const pointer = ( type : string , x : number , y : number ) =>
55+ new PointerEvent ( type , {
56+ bubbles : true ,
57+ cancelable : true ,
58+ pointerId : 1 ,
59+ isPrimary : true ,
60+ button : 0 ,
61+ buttons : type === "pointerup" ? 0 : 1 ,
62+ clientX : x ,
63+ clientY : y ,
64+ } ) ;
65+ await act ( ( ) => {
66+ row . element ( ) . dispatchEvent ( pointer ( "pointerdown" , bounds . x + 20 , bounds . y + 10 ) ) ;
67+ document . dispatchEvent ( pointer ( "pointermove" , bounds . x + 30 , bounds . y + 20 ) ) ;
68+ } ) ;
69+ expect ( useCommandPaletteStore . getState ( ) . open ) . toBe ( false ) ;
70+ await act ( ( ) => {
71+ document . dispatchEvent ( pointer ( "pointermove" , 50 , window . innerHeight - 30 ) ) ;
72+ document . dispatchEvent ( pointer ( "pointerup" , 50 , window . innerHeight - 30 ) ) ;
73+ } ) ;
74+ expect ( onDrop ) . toHaveBeenCalledOnce ( ) ;
75+ expect ( ( onDrop . mock . calls [ 0 ] ! [ 0 ] as CustomEvent ) . detail ) . toEqual ( [ { environmentId, threadId } ] ) ;
76+ expect ( screen . router ?. state . location . pathname ) . toBe ( pathname ) ;
77+ } ) ;
78+
2979 it ( "opens New thread in... with focus in the search input, not the Back button" , async ( ) => {
3080 setup ( ) ;
3181 await using _screen = await render ( < CommandPalette > { null } </ CommandPalette > ) ;
0 commit comments