@@ -6,6 +6,7 @@ var customMatchers = require('../assets/custom_matchers');
6
6
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
7
7
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
8
8
9
+ var d3 = require ( 'd3' ) ;
9
10
var click = require ( '../assets/click' ) ;
10
11
var getClientPosition = require ( '../assets/get_client_position' ) ;
11
12
var mouseEvent = require ( '../assets/mouse_event' ) ;
@@ -175,9 +176,7 @@ describe('pie hovering', function() {
175
176
} ) ;
176
177
177
178
describe ( 'labels' , function ( ) {
178
-
179
- var gd ,
180
- mockCopy ;
179
+ var gd , mockCopy ;
181
180
182
181
beforeEach ( function ( ) {
183
182
gd = createGraphDiv ( ) ;
@@ -186,44 +185,60 @@ describe('pie hovering', function() {
186
185
187
186
afterEach ( destroyGraphDiv ) ;
188
187
189
- it ( 'should show the default selected values' , function ( done ) {
190
-
191
- var expected = [ '4' , '5' , '33.3%' ] ;
192
-
193
- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
188
+ function _hover ( ) {
189
+ mouseEvent ( 'mouseover' , 223 , 143 ) ;
190
+ }
194
191
195
- mouseEvent ( 'mouseover' , 223 , 143 ) ;
192
+ function assertLabel ( expected ) {
193
+ var labels = d3 . selectAll ( '.hovertext .nums .line' ) ;
196
194
197
- var labels = Plotly . d3 . selectAll ( '.hovertext .nums .line' ) ;
195
+ expect ( labels [ 0 ] . length ) . toBe ( expected . length ) ;
198
196
199
- expect ( labels [ 0 ] . length ) . toBe ( 3 ) ;
197
+ labels . each ( function ( _ , i ) {
198
+ expect ( d3 . select ( this ) . text ( ) ) . toBe ( expected [ i ] ) ;
199
+ } ) ;
200
+ }
200
201
201
- labels . each ( function ( _ , i ) {
202
- expect ( Plotly . d3 . select ( this ) . text ( ) ) . toBe ( expected [ i ] ) ;
203
- } ) ;
204
- } ) . then ( done ) ;
202
+ it ( 'should show the default selected values' , function ( done ) {
203
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
204
+ . then ( _hover )
205
+ . then ( function ( ) {
206
+ assertLabel ( [ '4' , '5' , '33.3%' ] ) ;
207
+
208
+ return Plotly . restyle ( gd , 'text' , [ [ 'A' , 'B' , 'C' , 'D' , 'E' ] ] ) ;
209
+ } )
210
+ . then ( _hover )
211
+ . then ( function ( ) {
212
+ assertLabel ( [ '4' , 'E' , '5' , '33.3%' ] ) ;
213
+
214
+ return Plotly . restyle ( gd , 'hovertext' , [ [
215
+ 'Apple' , 'Banana' , 'Clementine' , 'Dragon Fruit' , 'Eggplant'
216
+ ] ] ) ;
217
+ } )
218
+ . then ( _hover )
219
+ . then ( function ( ) {
220
+ assertLabel ( [ '4' , 'Eggplant' , '5' , '33.3%' ] ) ;
221
+
222
+ return Plotly . restyle ( gd , 'hovertext' , 'SUP' ) ;
223
+ } )
224
+ . then ( _hover )
225
+ . then ( function ( ) {
226
+ assertLabel ( [ '4' , 'SUP' , '5' , '33.3%' ] ) ;
227
+ } )
228
+ . then ( done ) ;
205
229
} ) ;
206
230
207
231
it ( 'should show the correct separators for values' , function ( done ) {
208
-
209
- var expected = [ '0' , '12|345|678@91' , '99@9%' ] ;
210
-
211
232
mockCopy . layout . separators = '@|' ;
212
233
mockCopy . data [ 0 ] . values [ 0 ] = 12345678.912 ;
213
234
mockCopy . data [ 0 ] . values [ 1 ] = 10000 ;
214
235
215
- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
216
-
217
- mouseEvent ( 'mouseover' , 223 , 143 ) ;
218
-
219
- var labels = Plotly . d3 . selectAll ( '.hovertext .nums .line' ) ;
220
-
221
- expect ( labels [ 0 ] . length ) . toBe ( 3 ) ;
222
-
223
- labels . each ( function ( _ , i ) {
224
- expect ( Plotly . d3 . select ( this ) . text ( ) ) . toBe ( expected [ i ] ) ;
225
- } ) ;
226
- } ) . then ( done ) ;
236
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
237
+ . then ( _hover )
238
+ . then ( function ( ) {
239
+ assertLabel ( [ '0' , '12|345|678@91' , '99@9%' ] ) ;
240
+ } )
241
+ . then ( done ) ;
227
242
} ) ;
228
243
} ) ;
229
244
} ) ;
0 commit comments