@@ -2,19 +2,25 @@ import { describe, expect, it } from "@effect/vitest";
22
33import {
44 COMPOSER_MENTION_DRAG_TYPE ,
5+ COMPOSER_PULL_REQUEST_DRAG_TYPE ,
56 type ComposerMentionDropHost ,
67 composerMentionFromTreePath ,
78 dataTransferHasComposerMention ,
89 makeComposerMentionDragHandlers ,
910} from "./composerMentionDrag.ts" ;
1011
11- const makeDragEvent = ( options ?: { mention ?: string ; types ?: ReadonlyArray < string > } ) => {
12+ const makeDragEvent = ( options ?: {
13+ mention ?: string ;
14+ types ?: ReadonlyArray < string > ;
15+ format ?: string ;
16+ } ) => {
1217 const mention = options ?. mention ?? "[index.md](docs/index.md)" ;
18+ const format = options ?. format ?? COMPOSER_MENTION_DRAG_TYPE ;
1319 const calls : Array < string > = [ ] ;
1420 const event = {
1521 dataTransfer : {
16- types : options ?. types ?? [ COMPOSER_MENTION_DRAG_TYPE , "text/plain" ] ,
17- getData : ( format : string ) => ( format === COMPOSER_MENTION_DRAG_TYPE ? mention : "" ) ,
22+ types : options ?. types ?? [ format , "text/plain" ] ,
23+ getData : ( requested : string ) => ( requested === format ? mention : "" ) ,
1824 dropEffect : "none" ,
1925 } ,
2026 nativeEvent : {
@@ -33,6 +39,10 @@ const makeHost = (insertResult = true) => {
3339 log . push ( `insert:${ text } ` ) ;
3440 return insertResult ;
3541 } ,
42+ insertPullRequestAtEnd : ( pullRequest ) => {
43+ log . push ( `pr:${ pullRequest . number } ` ) ;
44+ return insertResult ;
45+ } ,
3646 setDragActive : ( active ) => void log . push ( `active:${ active } ` ) ,
3747 onInsertRejected : ( ) => void log . push ( "rejected" ) ,
3848 } ;
@@ -120,4 +130,34 @@ describe("makeComposerMentionDragHandlers", () => {
120130 handlers . onDrop ( makeDragEvent ( { mention : "" } ) . event ) ;
121131 expect ( log ) . toEqual ( [ "active:false" ] ) ;
122132 } ) ;
133+
134+ it ( "drops a pull request row as a pull request, not as text" , ( ) => {
135+ const { host, log } = makeHost ( ) ;
136+ const handlers = makeComposerMentionDragHandlers ( host ) ;
137+ const pullRequest = {
138+ number : 18094 ,
139+ title : "fix(server): queued runs land on the timeline where they started" ,
140+ url : "https://github.com/pingdotgg/t3code/pull/18094" ,
141+ headBranch : "fix/run-timeline-position" ,
142+ baseBranch : "main" ,
143+ state : "open" ,
144+ isDraft : false ,
145+ } ;
146+ handlers . onDrop (
147+ makeDragEvent ( {
148+ format : COMPOSER_PULL_REQUEST_DRAG_TYPE ,
149+ mention : JSON . stringify ( pullRequest ) ,
150+ } ) . event ,
151+ ) ;
152+ expect ( log ) . toEqual ( [ "active:false" , "pr:18094" ] ) ;
153+ } ) ;
154+
155+ it ( "ignores a pull request payload that does not decode" , ( ) => {
156+ const { host, log } = makeHost ( ) ;
157+ const handlers = makeComposerMentionDragHandlers ( host ) ;
158+ handlers . onDrop (
159+ makeDragEvent ( { format : COMPOSER_PULL_REQUEST_DRAG_TYPE , mention : '{"number":0}' } ) . event ,
160+ ) ;
161+ expect ( log ) . toEqual ( [ "active:false" ] ) ;
162+ } ) ;
123163} ) ;
0 commit comments