@@ -2,19 +2,26 @@ import { describe, expect, it } from "@effect/vitest";
22
33import {
44 COMPOSER_MENTION_DRAG_TYPE ,
5+ COMPOSER_PULL_REQUEST_DRAG_TYPE ,
6+ encodePullRequestDragPayload ,
57 type ComposerMentionDropHost ,
68 composerMentionFromTreePath ,
79 dataTransferHasComposerMention ,
810 makeComposerMentionDragHandlers ,
911} from "./composerMentionDrag.ts" ;
1012
11- const makeDragEvent = ( options ?: { mention ?: string ; types ?: ReadonlyArray < string > } ) => {
13+ const makeDragEvent = ( options ?: {
14+ mention ?: string ;
15+ types ?: ReadonlyArray < string > ;
16+ format ?: string ;
17+ } ) => {
1218 const mention = options ?. mention ?? "[index.md](docs/index.md)" ;
19+ const format = options ?. format ?? COMPOSER_MENTION_DRAG_TYPE ;
1320 const calls : Array < string > = [ ] ;
1421 const event = {
1522 dataTransfer : {
16- types : options ?. types ?? [ COMPOSER_MENTION_DRAG_TYPE , "text/plain" ] ,
17- getData : ( format : string ) => ( format === COMPOSER_MENTION_DRAG_TYPE ? mention : "" ) ,
23+ types : options ?. types ?? [ format , "text/plain" ] ,
24+ getData : ( requested : string ) => ( requested === format ? mention : "" ) ,
1825 dropEffect : "none" ,
1926 } ,
2027 nativeEvent : {
@@ -33,6 +40,10 @@ const makeHost = (insertResult = true) => {
3340 log . push ( `insert:${ text } ` ) ;
3441 return insertResult ;
3542 } ,
43+ insertPullRequestAtEnd : ( pullRequest ) => {
44+ log . push ( `pr:${ pullRequest . number } ` ) ;
45+ return insertResult ;
46+ } ,
3647 setDragActive : ( active ) => void log . push ( `active:${ active } ` ) ,
3748 onInsertRejected : ( ) => void log . push ( "rejected" ) ,
3849 } ;
@@ -120,4 +131,34 @@ describe("makeComposerMentionDragHandlers", () => {
120131 handlers . onDrop ( makeDragEvent ( { mention : "" } ) . event ) ;
121132 expect ( log ) . toEqual ( [ "active:false" ] ) ;
122133 } ) ;
134+
135+ it ( "drops a pull request row as a pull request, not as text" , ( ) => {
136+ const { host, log } = makeHost ( ) ;
137+ const handlers = makeComposerMentionDragHandlers ( host ) ;
138+ const pullRequest = {
139+ number : 18094 ,
140+ title : "fix(server): queued runs land on the timeline where they started" ,
141+ url : "https://github.com/pingdotgg/t3code/pull/18094" ,
142+ headBranch : "fix/run-timeline-position" ,
143+ baseBranch : "main" ,
144+ state : "open" ,
145+ isDraft : false ,
146+ } as const ;
147+ handlers . onDrop (
148+ makeDragEvent ( {
149+ format : COMPOSER_PULL_REQUEST_DRAG_TYPE ,
150+ mention : encodePullRequestDragPayload ( pullRequest ) ,
151+ } ) . event ,
152+ ) ;
153+ expect ( log ) . toEqual ( [ "active:false" , "pr:18094" ] ) ;
154+ } ) ;
155+
156+ it ( "ignores a pull request payload that does not decode" , ( ) => {
157+ const { host, log } = makeHost ( ) ;
158+ const handlers = makeComposerMentionDragHandlers ( host ) ;
159+ handlers . onDrop (
160+ makeDragEvent ( { format : COMPOSER_PULL_REQUEST_DRAG_TYPE , mention : '{"number":0}' } ) . event ,
161+ ) ;
162+ expect ( log ) . toEqual ( [ "active:false" ] ) ;
163+ } ) ;
123164} ) ;
0 commit comments