@@ -14,14 +14,24 @@ describe('Test geo interactions', function() {
1414
1515 describe ( 'mock geo_first.json' , function ( ) {
1616 var mock = require ( '@mocks/geo_first.json' ) ;
17+ var gd ;
18+
19+ function mouseEventScatterGeo ( type ) {
20+ mouseEvent ( type , 300 , 235 ) ;
21+ }
22+
23+ function mouseEventChoropleth ( type ) {
24+ mouseEvent ( type , 400 , 160 ) ;
25+ }
1726
1827 beforeEach ( function ( done ) {
19- Plotly . plot ( createGraphDiv ( ) , mock . data , mock . layout ) . then ( done ) ;
28+ gd = createGraphDiv ( ) ;
29+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( done ) ;
2030 } ) ;
2131
22- describe ( 'scattegeo hover labels' , function ( ) {
32+ describe ( 'scattergeo hover labels' , function ( ) {
2333 beforeEach ( function ( ) {
24- mouseEvent ( 'mouseover' , 300 , 235 ) ;
34+ mouseEventScatterGeo ( 'mouseover' ) ;
2535 } ) ;
2636
2737 it ( 'should show one hover text group' , function ( ) {
@@ -41,9 +51,63 @@ describe('Test geo interactions', function() {
4151 } ) ;
4252 } ) ;
4353
54+ describe ( 'scattergeo hover events' , function ( ) {
55+ var ptData ;
56+
57+ beforeEach ( function ( ) {
58+ gd . on ( 'plotly_hover' , function ( eventData ) {
59+ ptData = eventData . points [ 0 ] ;
60+ } ) ;
61+
62+ mouseEventScatterGeo ( 'mouseover' ) ;
63+ } ) ;
64+
65+ it ( 'should contain the correct fields' , function ( ) {
66+ expect ( Object . keys ( ptData ) ) . toEqual ( [
67+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
68+ 'lon' , 'lat' , 'location'
69+ ] ) ;
70+ } ) ;
71+
72+ it ( 'should show the correct point data' , function ( ) {
73+ expect ( ptData . lon ) . toEqual ( 0 ) ;
74+ expect ( ptData . lat ) . toEqual ( 0 ) ;
75+ expect ( ptData . location ) . toBe ( null ) ;
76+ expect ( ptData . curveNumber ) . toEqual ( 0 ) ;
77+ expect ( ptData . pointNumber ) . toEqual ( 0 ) ;
78+ } ) ;
79+ } ) ;
80+
81+ describe ( 'scattergeo click events' , function ( ) {
82+ var ptData ;
83+
84+ beforeEach ( function ( ) {
85+ gd . on ( 'plotly_click' , function ( eventData ) {
86+ ptData = eventData . points [ 0 ] ;
87+ } ) ;
88+
89+ mouseEventScatterGeo ( 'click' ) ;
90+ } ) ;
91+
92+ it ( 'should contain the correct fields' , function ( ) {
93+ expect ( Object . keys ( ptData ) ) . toEqual ( [
94+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
95+ 'lon' , 'lat' , 'location'
96+ ] ) ;
97+ } ) ;
98+
99+ it ( 'should show the correct point data' , function ( ) {
100+ expect ( ptData . lon ) . toEqual ( 0 ) ;
101+ expect ( ptData . lat ) . toEqual ( 0 ) ;
102+ expect ( ptData . location ) . toBe ( null ) ;
103+ expect ( ptData . curveNumber ) . toEqual ( 0 ) ;
104+ expect ( ptData . pointNumber ) . toEqual ( 0 ) ;
105+ } ) ;
106+ } ) ;
107+
44108 describe ( 'choropleth hover labels' , function ( ) {
45109 beforeEach ( function ( ) {
46- mouseEvent ( 'mouseover' , 400 , 160 ) ;
110+ mouseEventChoropleth ( 'mouseover' ) ;
47111 } ) ;
48112
49113 it ( 'should show one hover text group' , function ( ) {
@@ -64,5 +128,57 @@ describe('Test geo interactions', function() {
64128 } ) ;
65129 } ) ;
66130
131+ describe ( 'choropleth hover events' , function ( ) {
132+ var ptData ;
133+
134+ beforeEach ( function ( ) {
135+ gd . on ( 'plotly_hover' , function ( eventData ) {
136+ ptData = eventData . points [ 0 ] ;
137+ } ) ;
138+
139+ mouseEventChoropleth ( 'mouseover' ) ;
140+ } ) ;
141+
142+ it ( 'should contain the correct fields' , function ( ) {
143+ expect ( Object . keys ( ptData ) ) . toEqual ( [
144+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
145+ 'location' , 'z'
146+ ] ) ;
147+ } ) ;
148+
149+ it ( 'should show the correct point data' , function ( ) {
150+ expect ( ptData . location ) . toBe ( 'RUS' ) ;
151+ expect ( ptData . z ) . toEqual ( 10 ) ;
152+ expect ( ptData . curveNumber ) . toEqual ( 1 ) ;
153+ expect ( ptData . pointNumber ) . toEqual ( 2 ) ;
154+ } ) ;
155+ } ) ;
156+
157+ describe ( 'choropleth click events' , function ( ) {
158+ var ptData ;
159+
160+ beforeEach ( function ( ) {
161+ gd . on ( 'plotly_click' , function ( eventData ) {
162+ ptData = eventData . points [ 0 ] ;
163+ } ) ;
164+
165+ mouseEventChoropleth ( 'click' ) ;
166+ } ) ;
167+
168+ it ( 'should contain the correct fields' , function ( ) {
169+ expect ( Object . keys ( ptData ) ) . toEqual ( [
170+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
171+ 'location' , 'z'
172+ ] ) ;
173+ } ) ;
174+
175+ it ( 'should show the correct point data' , function ( ) {
176+ expect ( ptData . location ) . toBe ( 'RUS' ) ;
177+ expect ( ptData . z ) . toEqual ( 10 ) ;
178+ expect ( ptData . curveNumber ) . toEqual ( 1 ) ;
179+ expect ( ptData . pointNumber ) . toEqual ( 2 ) ;
180+ } ) ;
181+ } ) ;
182+
67183 } ) ;
68184} ) ;
0 commit comments