@@ -97,7 +97,7 @@ describe('react-draggable', function () {
97
97
98
98
// Not easy to actually test equality here. The functions are bound as static props so we can't test those easily.
99
99
const toOmit = [ 'onStart' , 'onStop' , 'onDrag' , 'onMouseDown' , 'children' ] ;
100
- assert . deepEqual (
100
+ assert . deepStrictEqual (
101
101
_ . omit ( output . props , toOmit ) ,
102
102
_ . omit ( expected . props , toOmit )
103
103
) ;
@@ -148,7 +148,7 @@ describe('react-draggable', function () {
148
148
</ Draggable >
149
149
) ;
150
150
151
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
151
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
152
152
} ) ;
153
153
154
154
it ( 'should throw when setting className' , function ( ) {
@@ -249,7 +249,7 @@ describe('react-draggable', function () {
249
249
) ;
250
250
251
251
const node = ReactDOM . findDOMNode ( drag ) ;
252
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
252
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
253
253
254
254
const style = node . getAttribute ( 'style' ) ;
255
255
assert ( dragged === true ) ;
@@ -265,7 +265,7 @@ describe('react-draggable', function () {
265
265
) ;
266
266
267
267
const node = ReactDOM . findDOMNode ( drag ) ;
268
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
268
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
269
269
270
270
const style = node . getAttribute ( 'style' ) ;
271
271
assert ( dragged === true ) ;
@@ -281,7 +281,7 @@ describe('react-draggable', function () {
281
281
) ;
282
282
283
283
const node = ReactDOM . findDOMNode ( drag ) ;
284
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
284
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
285
285
286
286
const style = node . getAttribute ( 'style' ) ;
287
287
assert ( dragged === true ) ;
@@ -297,7 +297,7 @@ describe('react-draggable', function () {
297
297
) ;
298
298
299
299
const node = ReactDOM . findDOMNode ( drag ) ;
300
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
300
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
301
301
302
302
const style = node . getAttribute ( 'style' ) ;
303
303
assert ( dragged === true ) ;
@@ -313,7 +313,7 @@ describe('react-draggable', function () {
313
313
) ;
314
314
315
315
const node = ReactDOM . findDOMNode ( drag ) ;
316
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
316
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
317
317
318
318
const style = node . getAttribute ( 'style' ) ;
319
319
assert ( dragged === true ) ;
@@ -348,7 +348,7 @@ describe('react-draggable', function () {
348
348
) ;
349
349
350
350
const node = ReactDOM . findDOMNode ( drag ) ;
351
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
351
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
352
352
353
353
const transform = node . getAttribute ( 'transform' ) ;
354
354
assert ( transform . indexOf ( 'translate(100,100)' ) >= 0 ) ;
@@ -461,7 +461,7 @@ describe('react-draggable', function () {
461
461
const body = iframeDoc . body ;
462
462
const node = body . querySelector ( '.react-draggable' ) ;
463
463
if ( ! node ) return setTimeout ( checkIframe , 50 ) ;
464
- simulateMovementFromTo ( node , 0 , 0 , 100 , 100 ) ;
464
+ simulateMouseFromTo ( node , 0 , 0 , 100 , 100 ) ;
465
465
466
466
const style = node . getAttribute ( 'style' ) ;
467
467
assert ( dragged === true ) ;
@@ -711,6 +711,48 @@ describe('react-draggable', function () {
711
711
done ( ) ;
712
712
} , 50 ) ;
713
713
} ) ;
714
+
715
+ // it('should allow touch scrolling parent', function (done) {
716
+ // let dragCalled = false;
717
+ // function onDrag(event, data) {
718
+ // dragCalled = true;
719
+ // // assert(data.x === 100);
720
+ // // assert(data.y === 100);
721
+ // // assert(data.deltaX === 100);
722
+ // // assert(data.deltaY === 100);
723
+ // }
724
+
725
+ // const scrollParent = fragmentFromString(`
726
+ // <div style="overflow: auto; width: 500px; height: 500px; outline: 1px solid black">
727
+ // <div style="width: 10000px; height: 10000px;">
728
+ // </div>
729
+ // </div>
730
+ // `);
731
+
732
+ // drag = TestUtils.renderIntoDocument(
733
+ // <Draggable onDrag={onDrag} preventDefault={false} defaultPosition={{x: 200, y: 200}} offsetParent={scrollParent}>
734
+ // <div style={{position: 'relative', width: '100px', height: '100px', outline: '1px solid red'}} />
735
+ // </Draggable>
736
+ // );
737
+ // const node = ReactDOM.findDOMNode(drag);
738
+
739
+ // transplantNodeInto(node, scrollParent, (f) => f.children[0]);
740
+
741
+ // const scrollParentNode = ReactDOM.findDOMNode(scrollParent);
742
+
743
+ // simulateTouchFromTo(node, 200, 200, 100, 100);
744
+
745
+ // setTimeout(() => {
746
+ // console.log(node);
747
+ // assert(dragCalled, 'onDrag was not called');
748
+ // assert(scrollParentNode.scrollTop !== 0 && scrollParentNode.scrollLeft !== 0, 'parent didn\'t scroll on touch');
749
+ // assert(scrollParentNode.scrollTop === 100, 'parent vertical scroll is off');
750
+ // assert(scrollParentNode.scrollLeft === 100, 'parent horizontal scroll is off');
751
+ // // cleanup
752
+ // document.body.removeChild(scrollParent);
753
+ // done();
754
+ // }, 50);
755
+ // });
714
756
} ) ;
715
757
716
758
describe ( 'draggable callbacks' , function ( ) {
@@ -729,7 +771,7 @@ describe('react-draggable', function () {
729
771
) ;
730
772
731
773
// (element, fromX, fromY, toX, toY)
732
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
774
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
733
775
} ) ;
734
776
735
777
it ( 'should call back with correct dom node with nodeRef' , function ( ) {
@@ -748,7 +790,7 @@ describe('react-draggable', function () {
748
790
) ;
749
791
750
792
// (element, fromX, fromY, toX, toY)
751
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
793
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
752
794
} ) ;
753
795
754
796
it ( 'should call back on drag, with values within the defined bounds' , function ( ) {
@@ -765,7 +807,7 @@ describe('react-draggable', function () {
765
807
) ;
766
808
767
809
// (element, fromX, fromY, toX, toY)
768
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
810
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
769
811
770
812
} ) ;
771
813
@@ -782,7 +824,7 @@ describe('react-draggable', function () {
782
824
</ Draggable >
783
825
) ;
784
826
785
- simulateMovementFromTo ( drag , 200 , 200 , 300 , 300 ) ;
827
+ simulateMouseFromTo ( drag , 200 , 200 , 300 , 300 ) ;
786
828
} ) ;
787
829
788
830
it ( 'should call back with correct position when parent element is 2x scaled' , function ( ) {
@@ -801,7 +843,7 @@ describe('react-draggable', function () {
801
843
) ;
802
844
803
845
// (element, fromX, fromY, toX, toY)
804
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
846
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
805
847
} ) ;
806
848
807
849
it ( 'should call back with correct position when parent element is 0.5x scaled' , function ( ) {
@@ -820,7 +862,7 @@ describe('react-draggable', function () {
820
862
) ;
821
863
822
864
// (element, fromX, fromY, toX, toY)
823
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
865
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
824
866
} ) ;
825
867
826
868
it ( 'should not throw an error if unmounted during a callback' , function ( ) {
@@ -847,7 +889,7 @@ describe('react-draggable', function () {
847
889
) ;
848
890
849
891
// (element, fromX, fromY, toX, toY)
850
- simulateMovementFromTo ( dragRef . current , 0 , 0 , 100 , 100 ) ;
892
+ simulateMouseFromTo ( dragRef . current , 0 , 0 , 100 , 100 ) ;
851
893
852
894
// ok, was a setstate warning thrown?
853
895
// Assert unmounted
@@ -872,7 +914,7 @@ describe('react-draggable', function () {
872
914
) ;
873
915
874
916
// (element, fromX, fromY, toX, toY)
875
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
917
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
876
918
} ) ;
877
919
878
920
it ( 'should call back with correct position when parent element is 2x scaled' , function ( ) {
@@ -891,7 +933,7 @@ describe('react-draggable', function () {
891
933
) ;
892
934
893
935
// (element, fromX, fromY, toX, toY)
894
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
936
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
895
937
} ) ;
896
938
897
939
it ( 'should call back with correct position when parent element is 0.5x scaled' , function ( ) {
@@ -910,11 +952,10 @@ describe('react-draggable', function () {
910
952
) ;
911
953
912
954
// (element, fromX, fromY, toX, toY)
913
- simulateMovementFromTo ( drag , 0 , 0 , 100 , 100 ) ;
955
+ simulateMouseFromTo ( drag , 0 , 0 , 100 , 100 ) ;
914
956
} ) ;
915
957
} ) ;
916
958
917
-
918
959
describe ( 'validation' , function ( ) {
919
960
it ( 'should result with invariant when there isn\'t a child' , function ( ) {
920
961
const renderer = new ShallowRenderer ( ) ;
@@ -951,15 +992,52 @@ function mouseMove(x, y, node) {
951
992
return evt ;
952
993
}
953
994
995
+ function createClientXY ( x , y ) {
996
+ return { clientX : x , clientY : y } ;
997
+ }
998
+
999
+ function touchMove ( x , y , node ) {
1000
+ const touchObj = new Touch ( {
1001
+ identifier : Date . now ( ) ,
1002
+ target : node ,
1003
+ clientX : x ,
1004
+ clientY : y ,
1005
+ radiusX : 2.5 ,
1006
+ radiusY : 2.5 ,
1007
+ rotationAngle : 10 ,
1008
+ force : 0.5 ,
1009
+ } ) ;
1010
+
1011
+ const touchEvent = new TouchEvent ( 'touchmove' , {
1012
+ cancelable : true ,
1013
+ bubbles : true ,
1014
+ touches : [ touchObj ] ,
1015
+ targetTouches : [ ] ,
1016
+ changedTouches : [ touchObj ] ,
1017
+ shiftKey : true ,
1018
+ } ) ;
1019
+
1020
+ node . dispatchEvent ( touchEvent ) ;
1021
+ }
1022
+
954
1023
955
- function simulateMovementFromTo ( drag , fromX , fromY , toX , toY ) {
1024
+ function simulateMouseFromTo ( drag , fromX , fromY , toX , toY ) {
956
1025
const node = ReactDOM . findDOMNode ( drag ) ;
957
1026
958
- TestUtils . Simulate . mouseDown ( node , { clientX : fromX , clientY : fromY } ) ;
1027
+ TestUtils . Simulate . mouseDown ( node , createClientXY ( fromX , fromY ) ) ;
959
1028
mouseMove ( toX , toY , node ) ;
960
1029
TestUtils . Simulate . mouseUp ( node ) ;
961
1030
}
962
1031
1032
+ // // Does not work, cannot figure out how to correctly simulate touches
1033
+ // function simulateTouchFromTo(drag, fromX, fromY, toX, toY) {
1034
+ // const node = ReactDOM.findDOMNode(drag);
1035
+
1036
+ // TestUtils.Simulate.touchStart(node, { touches: [createClientXY(fromX, fromY)] });
1037
+ // touchMove(toX, toY, node);
1038
+ // TestUtils.Simulate.touchEnd(node, { touches: [createClientXY(toX, toY)], changedTouches: [createClientXY(toX, toY)]});
1039
+ // }
1040
+
963
1041
function fragmentFromString ( strHTML ) {
964
1042
var temp = document . createElement ( 'div' ) ;
965
1043
temp . innerHTML = strHTML ;
0 commit comments