@@ -6,6 +6,7 @@ var Lib = require('@src/lib');
6
6
7
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9
+ var mouseEvent = require ( '../assets/mouse_event' ) ;
9
10
10
11
describe ( 'hover info' , function ( ) {
11
12
'use strict' ;
@@ -242,4 +243,42 @@ describe('hover info', function() {
242
243
expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text' ) . selectAll ( 'tspan' ) . size ( ) ) . toEqual ( 2 ) ;
243
244
} ) ;
244
245
} ) ;
246
+
247
+ describe ( 'hoverformat' , function ( ) {
248
+
249
+ var data = [ {
250
+ x : [ 1 , 2 , 3 ] ,
251
+ y : [ 0.12345 , 0.23456 , 0.34567 ]
252
+ } ] ,
253
+ layout = {
254
+ yaxis : { showticklabels : true , hoverformat : ',.2r' } ,
255
+ width : 600 ,
256
+ height : 400
257
+ } ;
258
+
259
+ beforeEach ( function ( ) {
260
+ this . gd = createGraphDiv ( ) ;
261
+ } ) ;
262
+
263
+ it ( 'should display the correct format when ticklabels true' , function ( ) {
264
+ Plotly . plot ( this . gd , data , layout ) ;
265
+ mouseEvent ( 'mousemove' , 310 , 220 ) ;
266
+
267
+ var hovers = d3 . selectAll ( 'g.hovertext' ) ;
268
+
269
+ expect ( hovers . size ( ) ) . toEqual ( 1 ) ;
270
+ expect ( hovers . select ( 'text' ) [ 0 ] [ 0 ] . textContent ) . toEqual ( '0.23' ) ;
271
+ } ) ;
272
+
273
+ it ( 'should display the correct format when ticklabels false' , function ( ) {
274
+ layout . yaxis . showticklabels = false ;
275
+ Plotly . plot ( this . gd , data , layout ) ;
276
+ mouseEvent ( 'mousemove' , 310 , 220 ) ;
277
+
278
+ var hovers = d3 . selectAll ( 'g.hovertext' ) ;
279
+
280
+ expect ( hovers . size ( ) ) . toEqual ( 1 ) ;
281
+ expect ( hovers . select ( 'text' ) [ 0 ] [ 0 ] . textContent ) . toEqual ( '0.23' ) ;
282
+ } ) ;
283
+ } ) ;
245
284
} ) ;
0 commit comments