@@ -422,8 +422,9 @@ describe('draggable', () => {
422
422
expect ( Math . floor ( draggedBounds . left ) ) . to . be . eql ( Math . floor ( bounds . left + dx ) ) ;
423
423
} ) ;
424
424
425
- it ( 'should only change "position", "top", and "left" values on drag' , ( ) => {
425
+ it ( 'should only change "position", "top", and "left" values on drag' , async ( ) => {
426
426
drag ( content ) ;
427
+ await nextRender ( ) ;
427
428
const overlay = dialog . $ . overlay . $ . overlay ;
428
429
const style = overlay . style ;
429
430
expect ( style . length ) . to . be . eql ( 3 ) ;
@@ -432,6 +433,18 @@ describe('draggable', () => {
432
433
expect ( style . left ) . to . be . ok ;
433
434
} ) ;
434
435
436
+ it ( 'should assign "top", and "left" properties on drag start' , async ( ) => {
437
+ const overlayBounds = dialog . $ . overlay . getBounds ( ) ;
438
+ expect ( dialog . left ) . to . be . undefined ;
439
+ expect ( dialog . top ) . to . be . undefined ;
440
+
441
+ dispatchMouseEvent ( content , 'mousedown' ) ;
442
+ await nextRender ( ) ;
443
+
444
+ expect ( dialog . left ) . to . be . equal ( overlayBounds . left ) ;
445
+ expect ( dialog . top ) . to . be . equal ( overlayBounds . top ) ;
446
+ } ) ;
447
+
435
448
it ( 'should drag and move dialog if mousedown on element with [class="draggable"] in another shadow root' , async ( ) => {
436
449
drag ( dialog . querySelector ( 'internally-draggable' ) . shadowRoot . querySelector ( '.draggable' ) ) ;
437
450
await nextRender ( ) ;
@@ -514,7 +527,7 @@ describe('draggable', () => {
514
527
expect ( Math . floor ( draggedBounds . left ) ) . to . be . eql ( Math . floor ( bounds . left ) ) ;
515
528
} ) ;
516
529
517
- it ( 'should not drag dialog if mousedown on .resizer-container scrollbar' , ( ) => {
530
+ it ( 'should not drag dialog if mousedown on .resizer-container scrollbar' , async ( ) => {
518
531
const boundsSpy = sinon . spy ( dialog . $ . overlay , 'setBounds' ) ;
519
532
content . style . width = `${ content . clientWidth * 4 } px` ;
520
533
const scrollbarHeight = container . offsetHeight - container . clientHeight ;
@@ -523,6 +536,7 @@ describe('draggable', () => {
523
536
x : containerBounds . left + containerBounds . width / 2 ,
524
537
y : containerBounds . top + containerBounds . height - scrollbarHeight / 2 ,
525
538
} ) ;
539
+ await nextRender ( ) ;
526
540
expect ( boundsSpy . called ) . to . equal ( ! scrollbarHeight ) ;
527
541
} ) ;
528
542
@@ -595,6 +609,22 @@ describe('draggable', () => {
595
609
expect ( detail . left ) . to . be . equal ( dialog . left ) ;
596
610
} ) ;
597
611
612
+ it ( 'should use correct coordinates in "dragged" event without moving the dialog during drag' , async ( ) => {
613
+ const overlayBounds = dialog . $ . overlay . getBounds ( ) ;
614
+ const onDragged = sinon . spy ( ) ;
615
+ dialog . addEventListener ( 'dragged' , onDragged ) ;
616
+
617
+ dispatchMouseEvent ( content , 'mousedown' ) ;
618
+ await nextRender ( ) ;
619
+ dispatchMouseEvent ( content , 'mouseup' ) ;
620
+ await nextRender ( ) ;
621
+
622
+ expect ( onDragged . calledOnce ) . to . be . true ;
623
+ const { detail } = onDragged . args [ 0 ] [ 0 ] ;
624
+ expect ( detail . top ) . to . be . equal ( overlayBounds . top ) ;
625
+ expect ( detail . left ) . to . be . equal ( overlayBounds . left ) ;
626
+ } ) ;
627
+
598
628
it ( 'should not set overlay max-width to none on drag' , async ( ) => {
599
629
drag ( container ) ;
600
630
await nextRender ( ) ;
0 commit comments