@@ -456,32 +456,74 @@ describe('react-draggable', function () {
456456 } ) ;
457457
458458 it ( 'should modulate position on scroll' , function ( done ) {
459- // This test fails in karma under Chrome & Firefox, positioning quirks
460- // FIXME: Why? Chrome reports 2x scrollTo, Phantom reports 0x, Firefox reports 1x as it should
461- var is_ff = navigator . userAgent . toLowerCase ( ) . indexOf ( 'Firefox' ) > - 1 ;
462- if ( ! is_ff ) return done ( ) ;
463-
464- var dragCalled = false ;
459+ let dragCalled = false ;
465460
466461 function onDrag ( e , coreEvent ) {
467462 assert ( coreEvent . deltaY === 500 ) ;
468463 dragCalled = true ;
469464 }
470465 drag = TestUtils . renderIntoDocument ( < Draggable onDrag = { onDrag } > < div /> </ Draggable > ) ;
471- var node = ReactDOM . findDOMNode ( drag ) ;
466+ const node = ReactDOM . findDOMNode ( drag ) ;
467+
468+ // Create a container we can scroll. I'm doing it this way so we can still access <Draggable>.
469+ // Enzyme (airbnb project) would make this a lot easier.
470+ const fragment = fragmentFromString ( `
471+ <div style="overflow: auto; height: 100px;">
472+ <div style="height: 10000px; position: relative;">
473+ </div>
474+ </div>
475+ ` ) ;
476+ transplantNodeInto ( node , fragment , ( f ) => f . children [ 0 ] ) ;
472477
473478 TestUtils . Simulate . mouseDown ( node , { clientX : 0 , clientY : 0 } ) ;
474479 assert ( drag . state . dragging === true ) ;
475480
476- document . body . style . height = '10000px' ;
477- window . scrollTo ( 0 , 500 ) ;
478- TestUtils . Simulate . mouseUp ( node , { clientX : 0 , clientY : 0 } ) ;
481+ // Scroll the inner container & trigger a scroll
482+ fragment . scrollTop = 500 ;
483+ mouseMove ( 0 , 0 ) ;
484+ TestUtils . Simulate . mouseUp ( node ) ;
479485 setTimeout ( function ( ) {
486+ assert ( drag . state . dragging === false ) ;
480487 assert ( dragCalled === true ) ;
481- assert ( drag . state . clientY === 500 ) ;
488+ assert ( drag . state . y === 500 ) ;
489+ // Cleanup
490+ document . body . removeChild ( fragment ) ;
482491 done ( ) ;
483492 } , 50 ) ;
493+
484494 } ) ;
495+
496+ it ( 'should respect offsetParent on nested div scroll' , function ( done ) {
497+ let dragCalled = false ;
498+ function onDrag ( e , coreEvent ) {
499+ dragCalled = true ;
500+ // Because the offsetParent is the body, we technically haven't moved at all relative to it
501+ assert ( coreEvent . deltaY === 0 ) ;
502+ }
503+ drag = TestUtils . renderIntoDocument ( < Draggable onDrag = { onDrag } offsetParent = { document . body } > < div /> </ Draggable > ) ;
504+ const node = ReactDOM . findDOMNode ( drag ) ;
505+
506+ // Create a container we can scroll. I'm doing it this way so we can still access <Draggable>.
507+ // Enzyme (airbnb project) would make this a lot easier.
508+ const fragment = fragmentFromString ( `
509+ <div style="overflow: auto; height: 100px;">
510+ <div style="height: 10000px; position: relative;">
511+ </div>
512+ </div>
513+ ` ) ;
514+ transplantNodeInto ( node , fragment , ( f ) => f . children [ 0 ] ) ;
515+
516+ TestUtils . Simulate . mouseDown ( node , { clientX : 0 , clientY : 0 } ) ;
517+ fragment . scrollTop = 500 ;
518+
519+ mouseMove ( 0 , 0 ) ;
520+ TestUtils . Simulate . mouseUp ( node ) ;
521+ setTimeout ( function ( ) {
522+ assert ( dragCalled ) ;
523+ // Cleanup
524+ document . body . removeChild ( fragment ) ;
525+ done ( ) ;
526+ } , 50 ) ;
485527 } ) ;
486528
487529 describe ( 'draggable callbacks' , function ( ) {
@@ -597,3 +639,15 @@ function simulateMovementFromTo(drag, fromX, fromY, toX, toY) {
597639 mouseMove ( toX , toY ) ;
598640 TestUtils . Simulate . mouseUp ( node ) ;
599641}
642+
643+ function fragmentFromString ( strHTML ) {
644+ var temp = document . createElement ( 'div' ) ;
645+ temp . innerHTML = strHTML ;
646+ return temp . children [ 0 ] ;
647+ }
648+
649+ function transplantNodeInto ( node , into , selector ) {
650+ node . parentNode . removeChild ( node ) ;
651+ selector ( into ) . appendChild ( node ) ;
652+ document . body . appendChild ( into ) ;
653+ }
0 commit comments