@@ -490,72 +490,159 @@ describe('useMinimap', () => {
490490 } )
491491 } )
492492
493- describe ( 'mouse interactions' , ( ) => {
494- it ( 'should handle mouse down and start dragging' , async ( ) => {
493+ describe ( 'pointer interactions' , ( ) => {
494+ it ( 'should handle pointer down and start dragging (mouse) ' , async ( ) => {
495495 const minimap = await createAndInitializeMinimap ( )
496496
497- const mouseEvent = new MouseEvent ( 'mousedown ', {
497+ const pointerEvent = new PointerEvent ( 'pointerdown ', {
498498 clientX : 150 ,
499- clientY : 150
499+ clientY : 150 ,
500+ pointerType : 'mouse'
500501 } )
501502
502- minimap . handleMouseDown ( mouseEvent )
503+ minimap . handlePointerDown ( pointerEvent )
503504
504505 expect ( mockContainerElement . getBoundingClientRect ) . toHaveBeenCalled ( )
505506 expect ( mockCanvas . setDirty ) . toHaveBeenCalledWith ( true , true )
506507 } )
507508
508- it ( 'should handle mouse move while dragging' , async ( ) => {
509+ it ( 'should handle pointer move while dragging (mouse) ' , async ( ) => {
509510 const minimap = await createAndInitializeMinimap ( )
510511
511- const mouseDownEvent = new MouseEvent ( 'mousedown ', {
512+ const pointerDownEvent = new PointerEvent ( 'pointerdown ', {
512513 clientX : 150 ,
513- clientY : 150
514+ clientY : 150 ,
515+ pointerType : 'mouse'
514516 } )
515- minimap . handleMouseDown ( mouseDownEvent )
517+ minimap . handlePointerDown ( pointerDownEvent )
516518
517- const mouseMoveEvent = new MouseEvent ( 'mousemove ', {
519+ const pointerMoveEvent = new PointerEvent ( 'pointermove ', {
518520 clientX : 200 ,
519- clientY : 200
521+ clientY : 200 ,
522+ pointerType : 'mouse'
520523 } )
521- minimap . handleMouseMove ( mouseMoveEvent )
524+ minimap . handlePointerMove ( pointerMoveEvent )
522525
523526 expect ( mockCanvas . setDirty ) . toHaveBeenCalledWith ( true , true )
524527 expect ( mockCanvas . ds . offset ) . toBeDefined ( )
525528 } )
526529
527- it ( 'should not move when not dragging' , async ( ) => {
530+ it ( 'should handle pointer up to stop dragging (mouse) ' , async ( ) => {
528531 const minimap = await createAndInitializeMinimap ( )
529532
533+ const pointerDownEvent = new PointerEvent ( 'pointerdown' , {
534+ clientX : 150 ,
535+ clientY : 150 ,
536+ pointerType : 'mouse'
537+ } )
538+ minimap . handlePointerDown ( pointerDownEvent )
539+
540+ minimap . handlePointerUp ( )
541+
530542 mockCanvas . setDirty . mockClear ( )
531543
532- const mouseMoveEvent = new MouseEvent ( 'mousemove ', {
544+ const pointerMoveEvent = new PointerEvent ( 'pointermove ', {
533545 clientX : 200 ,
534- clientY : 200
546+ clientY : 200 ,
547+ pointerType : 'mouse'
535548 } )
536- minimap . handleMouseMove ( mouseMoveEvent )
549+ minimap . handlePointerMove ( pointerMoveEvent )
537550
538551 expect ( mockCanvas . setDirty ) . not . toHaveBeenCalled ( )
539552 } )
540553
541- it ( 'should handle mouse up to stop dragging' , async ( ) => {
554+ it ( 'should handle pointer down and start dragging (touch) ' , async ( ) => {
542555 const minimap = await createAndInitializeMinimap ( )
543556
544- const mouseDownEvent = new MouseEvent ( 'mousedown ', {
557+ const pointerEvent = new PointerEvent ( 'pointerdown ', {
545558 clientX : 150 ,
546- clientY : 150
559+ clientY : 150 ,
560+ pointerType : 'touch'
561+ } )
562+
563+ minimap . handlePointerDown ( pointerEvent )
564+
565+ expect ( mockContainerElement . getBoundingClientRect ) . toHaveBeenCalled ( )
566+ expect ( mockCanvas . setDirty ) . toHaveBeenCalledWith ( true , true )
567+ } )
568+
569+ it ( 'should handle pointer move while dragging (touch)' , async ( ) => {
570+ const minimap = await createAndInitializeMinimap ( )
571+
572+ const pointerDownEvent = new PointerEvent ( 'pointerdown' , {
573+ clientX : 150 ,
574+ clientY : 150 ,
575+ pointerType : 'touch'
576+ } )
577+ minimap . handlePointerDown ( pointerDownEvent )
578+
579+ const pointerMoveEvent = new PointerEvent ( 'pointermove' , {
580+ clientX : 200 ,
581+ clientY : 200 ,
582+ pointerType : 'touch'
583+ } )
584+ minimap . handlePointerMove ( pointerMoveEvent )
585+
586+ expect ( mockCanvas . setDirty ) . toHaveBeenCalledWith ( true , true )
587+ expect ( mockCanvas . ds . offset ) . toBeDefined ( )
588+ } )
589+
590+ it ( 'should handle pointer move while dragging (pen)' , async ( ) => {
591+ const minimap = await createAndInitializeMinimap ( )
592+
593+ const pointerDownEvent = new PointerEvent ( 'pointerdown' , {
594+ clientX : 150 ,
595+ clientY : 150 ,
596+ pointerType : 'pen'
597+ } )
598+ minimap . handlePointerDown ( pointerDownEvent )
599+
600+ const pointerMoveEvent = new PointerEvent ( 'pointermove' , {
601+ clientX : 200 ,
602+ clientY : 200 ,
603+ pointerType : 'pen'
604+ } )
605+ minimap . handlePointerMove ( pointerMoveEvent )
606+
607+ expect ( mockCanvas . setDirty ) . toHaveBeenCalledWith ( true , true )
608+ expect ( mockCanvas . ds . offset ) . toBeDefined ( )
609+ } )
610+
611+ it ( 'should not move when not dragging with pointer' , async ( ) => {
612+ const minimap = await createAndInitializeMinimap ( )
613+
614+ mockCanvas . setDirty . mockClear ( )
615+
616+ const pointerMoveEvent = new PointerEvent ( 'pointermove' , {
617+ clientX : 200 ,
618+ clientY : 200 ,
619+ pointerType : 'touch'
620+ } )
621+ minimap . handlePointerMove ( pointerMoveEvent )
622+
623+ expect ( mockCanvas . setDirty ) . not . toHaveBeenCalled ( )
624+ } )
625+
626+ it ( 'should handle pointer up to stop dragging (touch)' , async ( ) => {
627+ const minimap = await createAndInitializeMinimap ( )
628+
629+ const pointerDownEvent = new PointerEvent ( 'pointerdown' , {
630+ clientX : 150 ,
631+ clientY : 150 ,
632+ pointerType : 'touch'
547633 } )
548- minimap . handleMouseDown ( mouseDownEvent )
634+ minimap . handlePointerDown ( pointerDownEvent )
549635
550- minimap . handleMouseUp ( )
636+ minimap . handlePointerUp ( )
551637
552638 mockCanvas . setDirty . mockClear ( )
553639
554- const mouseMoveEvent = new MouseEvent ( 'mousemove ', {
640+ const pointerMoveEvent = new PointerEvent ( 'pointermove ', {
555641 clientX : 200 ,
556- clientY : 200
642+ clientY : 200 ,
643+ pointerType : 'touch'
557644 } )
558- minimap . handleMouseMove ( mouseMoveEvent )
645+ minimap . handlePointerMove ( pointerMoveEvent )
559646
560647 expect ( mockCanvas . setDirty ) . not . toHaveBeenCalled ( )
561648 } )
0 commit comments