@@ -322,6 +322,20 @@ describe('react-draggable', function () {
322
322
} ) ;
323
323
324
324
describe ( 'interaction' , function ( ) {
325
+
326
+ function mouseDownOn ( drag , selector , shouldDrag ) {
327
+ resetDragging ( drag ) ;
328
+ const node = ReactDOM . findDOMNode ( drag ) . querySelector ( selector ) ;
329
+ if ( ! node ) throw new Error ( `Selector not found: ${ selector } ` ) ;
330
+ TestUtils . Simulate . mouseDown ( node ) ;
331
+ expect ( drag . state . dragging ) . toEqual ( shouldDrag ) ;
332
+ }
333
+
334
+ function resetDragging ( drag ) {
335
+ TestUtils . Simulate . mouseUp ( ReactDOM . findDOMNode ( drag ) ) ;
336
+ expect ( drag . state . dragging ) . toEqual ( false ) ;
337
+ }
338
+
325
339
it ( 'should initialize dragging onmousedown' , function ( ) {
326
340
drag = TestUtils . renderIntoDocument ( < Draggable > < div /> </ Draggable > ) ;
327
341
@@ -339,11 +353,27 @@ describe('react-draggable', function () {
339
353
</ Draggable >
340
354
) ;
341
355
342
- TestUtils . Simulate . mouseDown ( ReactDOM . findDOMNode ( drag ) . querySelector ( '.content' ) ) ;
343
- expect ( drag . state . dragging ) . toEqual ( false ) ;
356
+ mouseDownOn ( drag , '.content' , false ) ;
357
+ mouseDownOn ( drag , '.handle' , true ) ;
358
+ } ) ;
344
359
345
- TestUtils . Simulate . mouseDown ( ReactDOM . findDOMNode ( drag ) . querySelector ( '.handle' ) ) ;
346
- expect ( drag . state . dragging ) . toEqual ( true ) ;
360
+ it ( 'should only initialize dragging onmousedown of handle, even if children fire event' , function ( ) {
361
+ drag = TestUtils . renderIntoDocument (
362
+ < Draggable handle = ".handle" >
363
+ < div >
364
+ < div className = "handle" >
365
+ < div > < span > < div className = "deep" > Handle</ div > </ span > </ div >
366
+ </ div >
367
+ < div className = "content" > Lorem ipsum...</ div >
368
+ </ div >
369
+ </ Draggable >
370
+ ) ;
371
+
372
+ mouseDownOn ( drag , '.content' , false ) ;
373
+ mouseDownOn ( drag , '.deep' , true ) ;
374
+ mouseDownOn ( drag , '.handle > div' , true ) ;
375
+ mouseDownOn ( drag , '.handle span' , true ) ;
376
+ mouseDownOn ( drag , '.handle' , true ) ;
347
377
} ) ;
348
378
349
379
it ( 'should not initialize dragging onmousedown of cancel' , function ( ) {
@@ -356,11 +386,27 @@ describe('react-draggable', function () {
356
386
</ Draggable >
357
387
) ;
358
388
359
- TestUtils . Simulate . mouseDown ( ReactDOM . findDOMNode ( drag ) . querySelector ( '.cancel' ) ) ;
360
- expect ( drag . state . dragging ) . toEqual ( false ) ;
389
+ mouseDownOn ( drag , '.cancel' , false ) ;
390
+ mouseDownOn ( drag , '.content' , true ) ;
391
+ } ) ;
361
392
362
- TestUtils . Simulate . mouseDown ( ReactDOM . findDOMNode ( drag ) . querySelector ( '.content' ) ) ;
363
- expect ( drag . state . dragging ) . toEqual ( true ) ;
393
+ it ( 'should not initialize dragging onmousedown of handle, even if children fire event' , function ( ) {
394
+ drag = TestUtils . renderIntoDocument (
395
+ < Draggable cancel = ".cancel" >
396
+ < div >
397
+ < div className = "cancel" >
398
+ < div > < span > < div className = "deep" > Cancel</ div > </ span > </ div >
399
+ </ div >
400
+ < div className = "content" > Lorem ipsum...</ div >
401
+ </ div >
402
+ </ Draggable >
403
+ ) ;
404
+
405
+ mouseDownOn ( drag , '.content' , true ) ;
406
+ mouseDownOn ( drag , '.deep' , false ) ;
407
+ mouseDownOn ( drag , '.cancel > div' , false ) ;
408
+ mouseDownOn ( drag , '.cancel span' , false ) ;
409
+ mouseDownOn ( drag , '.cancel' , false ) ;
364
410
} ) ;
365
411
366
412
it ( 'should discontinue dragging onmouseup' , function ( ) {
@@ -369,8 +415,7 @@ describe('react-draggable', function () {
369
415
TestUtils . Simulate . mouseDown ( ReactDOM . findDOMNode ( drag ) ) ;
370
416
expect ( drag . state . dragging ) . toEqual ( true ) ;
371
417
372
- TestUtils . Simulate . mouseUp ( ReactDOM . findDOMNode ( drag ) ) ;
373
- expect ( drag . state . dragging ) . toEqual ( false ) ;
418
+ resetDragging ( drag ) ;
374
419
} ) ;
375
420
376
421
it ( 'should modulate position on scroll' , function ( done ) {
0 commit comments