@@ -458,4 +458,65 @@ describe('applyTargetedLayout', () => {
458458 result . loop . position . x + loopMetrics . width
459459 )
460460 } )
461+
462+ it ( 'relocates a newly added note off a block it was created on top of' , ( ) => {
463+ // A copilot note is born at the (0,0) placeholder, and a fresh workflow's
464+ // start block lives at (0,0) too. The pre-edit snapshot does not contain
465+ // the note, so the overlap counts as introduced by this edit and the note
466+ // must be moved to the stack below the flow, not preserved as intentional.
467+ const blocks = {
468+ start : createBlock ( 'start' , { position : { x : 0 , y : 0 } } ) ,
469+ note : createBlock ( 'note' , {
470+ type : 'note' ,
471+ position : { x : 0 , y : 0 } ,
472+ subBlocks : {
473+ content : { id : 'content' , type : 'long-input' , value : 'Explains the workflow' } ,
474+ } ,
475+ } ) ,
476+ }
477+
478+ const result = applyTargetedLayout ( blocks , [ ] , {
479+ changedBlockIds : [ 'note' ] ,
480+ previousBlocks : { start : blocks . start } ,
481+ } )
482+
483+ const startMetrics = getBlockMetrics ( result . start )
484+ expect ( result . start . position ) . toEqual ( { x : 0 , y : 0 } )
485+ expect ( result . note . position . y ) . toBeGreaterThanOrEqual (
486+ result . start . position . y + startMetrics . height + DEFAULT_VERTICAL_SPACING
487+ )
488+ } )
489+
490+ it ( 'preserves a pre-existing note arrangement when an unrelated block is laid out' , ( ) => {
491+ const blocks = {
492+ start : createBlock ( 'start' , { position : { x : 0 , y : 0 } } ) ,
493+ note : createBlock ( 'note' , {
494+ type : 'note' ,
495+ position : { x : 60 , y : 10 } ,
496+ subBlocks : {
497+ content : { id : 'content' , type : 'long-input' , value : 'Deliberately parked here' } ,
498+ } ,
499+ } ) ,
500+ added : createBlock ( 'added' , { position : { x : 0 , y : 0 } } ) ,
501+ }
502+
503+ const edges : Edge [ ] = [ { id : 'e1' , source : 'start' , target : 'added' } ]
504+
505+ const result = applyTargetedLayout ( blocks , edges , {
506+ changedBlockIds : [ 'added' ] ,
507+ previousBlocks : {
508+ start : createBlock ( 'start' , { position : { x : 0 , y : 0 } } ) ,
509+ note : createBlock ( 'note' , {
510+ type : 'note' ,
511+ position : { x : 60 , y : 10 } ,
512+ subBlocks : {
513+ content : { id : 'content' , type : 'long-input' , value : 'Deliberately parked here' } ,
514+ } ,
515+ } ) ,
516+ } ,
517+ } )
518+
519+ expect ( result . note . position ) . toEqual ( { x : 60 , y : 10 } )
520+ expect ( result . added . position . x ) . toBeGreaterThan ( result . start . position . x )
521+ } )
461522} )
0 commit comments