@@ -7,29 +7,29 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
77var mouseEvent = require ( '../assets/mouse_event' ) ;
88
99
10- describe ( 'click event' , function ( ) {
11- var mock = require ( '@mocks/14.json' ) ;
10+ describe ( 'click interactions' , function ( ) {
11+ var mock = require ( '@mocks/14.json' ) ,
12+ mockCopy = Lib . extendDeep ( { } , mock ) ,
13+ gd ;
1214
13- afterEach ( destroyGraphDiv ) ;
15+ var pointPos = [ 351 , 223 ] ,
16+ blankPos = [ 70 , 363 ] ;
1417
15- var mockCopy = Lib . extendDeep ( { } , mock ) ,
16- clientX = 351 ,
17- clientY = 223 ,
18- gd ;
18+ afterEach ( destroyGraphDiv ) ;
1919
2020 // cartesian click events events use the hover data
2121 // from the mousemove events and then simulate
2222 // a click event on mouseup
23- function click ( ) {
24- mouseEvent ( 'mousemove' , clientX , clientY ) ;
25- mouseEvent ( 'mousedown' , clientX , clientY ) ;
26- mouseEvent ( 'mouseup' , clientX , clientY ) ;
23+ function click ( x , y ) {
24+ mouseEvent ( 'mousemove' , x , y ) ;
25+ mouseEvent ( 'mousedown' , x , y ) ;
26+ mouseEvent ( 'mouseup' , x , y ) ;
2727 }
2828
29- function doubleClick ( cb ) {
30- click ( ) ;
29+ function doubleClick ( x , y , cb ) {
30+ click ( x , y ) ;
3131 setTimeout ( function ( ) {
32- click ( ) ;
32+ click ( x , y ) ;
3333 cb ( ) ;
3434 } , DBLCLICKDELAY / 2 ) ;
3535 }
@@ -41,38 +41,50 @@ describe('click event', function() {
4141 . then ( done ) ;
4242 } ) ;
4343
44- it ( 'should contain the correct fields ', function ( ) {
44+ describe ( 'click events ', function ( ) {
4545 var futureData ;
4646
47- gd . on ( 'plotly_click' , function ( data ) {
48- futureData = data ;
47+ beforeEach ( function ( ) {
48+ gd . on ( 'plotly_click' , function ( data ) {
49+ futureData = data ;
50+ } ) ;
4951 } ) ;
5052
51- click ( ) ;
52-
53- expect ( futureData . points . length ) . toEqual ( 1 ) ;
53+ it ( 'should not be trigged when not on data points' , function ( ) {
54+ click ( blankPos [ 0 ] , blankPos [ 1 ] ) ;
55+ expect ( futureData ) . toBe ( undefined ) ;
56+ } ) ;
5457
55- var pt = futureData . points [ 0 ] ;
56- expect ( Object . keys ( pt ) ) . toEqual ( [
57- 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
58- 'x' , 'y' , 'xaxis' , 'yaxis'
59- ] ) ;
60- expect ( pt . curveNumber ) . toEqual ( 0 ) ;
61- expect ( pt . pointNumber ) . toEqual ( 11 ) ;
62- expect ( pt . x ) . toEqual ( 0.125 ) ;
63- expect ( pt . y ) . toEqual ( 2.125 ) ;
58+ it ( 'should contain the correct fields' , function ( ) {
59+ click ( pointPos [ 0 ] , pointPos [ 1 ] ) ;
60+ expect ( futureData . points . length ) . toEqual ( 1 ) ;
61+
62+ var pt = futureData . points [ 0 ] ;
63+ expect ( Object . keys ( pt ) ) . toEqual ( [
64+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
65+ 'x' , 'y' , 'xaxis' , 'yaxis'
66+ ] ) ;
67+ expect ( pt . curveNumber ) . toEqual ( 0 ) ;
68+ expect ( pt . pointNumber ) . toEqual ( 11 ) ;
69+ expect ( pt . x ) . toEqual ( 0.125 ) ;
70+ expect ( pt . y ) . toEqual ( 2.125 ) ;
71+ } ) ;
6472 } ) ;
6573
66- it ( 'should trigger double click if two clicks are \'close\' together' , function ( done ) {
74+ describe ( ' double click events' , function ( ) {
6775 var futureData ;
6876
69- gd . on ( 'plotly_doubleclick' , function ( data ) {
70- futureData = data ;
77+ beforeEach ( function ( ) {
78+ gd . on ( 'plotly_doubleclick' , function ( data ) {
79+ futureData = data ;
80+ } ) ;
7181 } ) ;
7282
73- doubleClick ( function ( ) {
74- expect ( futureData ) . toBe ( null ) ;
75- done ( ) ;
83+ it ( 'should return null' , function ( done ) {
84+ doubleClick ( pointPos [ 0 ] , pointPos [ 1 ] , function ( ) {
85+ expect ( futureData ) . toBe ( null ) ;
86+ done ( ) ;
87+ } ) ;
7688 } ) ;
7789 } ) ;
7890} ) ;
0 commit comments