@@ -7,29 +7,29 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
7
7
var mouseEvent = require ( '../assets/mouse_event' ) ;
8
8
9
9
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 ;
12
14
13
- afterEach ( destroyGraphDiv ) ;
15
+ var pointPos = [ 351 , 223 ] ,
16
+ blankPos = [ 70 , 363 ] ;
14
17
15
- var mockCopy = Lib . extendDeep ( { } , mock ) ,
16
- clientX = 351 ,
17
- clientY = 223 ,
18
- gd ;
18
+ afterEach ( destroyGraphDiv ) ;
19
19
20
20
// cartesian click events events use the hover data
21
21
// from the mousemove events and then simulate
22
22
// 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 ) ;
27
27
}
28
28
29
- function doubleClick ( cb ) {
30
- click ( ) ;
29
+ function doubleClick ( x , y , cb ) {
30
+ click ( x , y ) ;
31
31
setTimeout ( function ( ) {
32
- click ( ) ;
32
+ click ( x , y ) ;
33
33
cb ( ) ;
34
34
} , DBLCLICKDELAY / 2 ) ;
35
35
}
@@ -41,38 +41,50 @@ describe('click event', function() {
41
41
. then ( done ) ;
42
42
} ) ;
43
43
44
- it ( 'should contain the correct fields ', function ( ) {
44
+ describe ( 'click events ', function ( ) {
45
45
var futureData ;
46
46
47
- gd . on ( 'plotly_click' , function ( data ) {
48
- futureData = data ;
47
+ beforeEach ( function ( ) {
48
+ gd . on ( 'plotly_click' , function ( data ) {
49
+ futureData = data ;
50
+ } ) ;
49
51
} ) ;
50
52
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
+ } ) ;
54
57
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
+ } ) ;
64
72
} ) ;
65
73
66
- it ( 'should trigger double click if two clicks are \'close\' together' , function ( done ) {
74
+ describe ( ' double click events' , function ( ) {
67
75
var futureData ;
68
76
69
- gd . on ( 'plotly_doubleclick' , function ( data ) {
70
- futureData = data ;
77
+ beforeEach ( function ( ) {
78
+ gd . on ( 'plotly_doubleclick' , function ( data ) {
79
+ futureData = data ;
80
+ } ) ;
71
81
} ) ;
72
82
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
+ } ) ;
76
88
} ) ;
77
89
} ) ;
78
90
} ) ;
0 commit comments